WARNING: Version 5.5 of the Elastic Stack has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
PKI User Authentication
editPKI User Authentication
editYou can configure X-Pack security to use Public Key Infrastructure (PKI) certificates to authenticate users in Elasticsearch. This requires clients to present X.509 certificates.
You cannot use PKI certificates to authenticate users in Kibana.
To use PKI in Elasticsearch, you configure a PKI realm, enable client authentication on the desired network layers (transport or http), and map the Distinguished Names (DNs) from the user certificates to X-Pack security roles in the role mapping file.
You can also use a combination of PKI and username/password authentication. For
example, you can enable SSL/TLS on the transport layer and define a PKI realm to
require transport clients to authenticate with X.509 certificates, while still
authenticating HTTP traffic using username and password credentials. You can also set
xpack.security.transport.ssl.client_authentication
to optional
to allow clients without
certificates to authenticate with other credentials.
You must enable SSL/TLS and enabled client authentication to use PKI. For more information, see Setting Up SSL/TLS on a Cluster.
PKI Realm Configuration
editLike other realms, you configure options for a pki
realm under the
xpack.security.authc.realms
namespace in elasticsearch.yml
.
To configure a pki
realm:
-
Add a realm configuration of type
pki
toelasticsearch.yml
under thexpack.security.authc.realms
namespace. At a minimum, you must set the realmtype
topki
. If you are configuring multiple realms, you should also explicitly set theorder
attribute. See PKI Realm Settings for all of the options you can set for apki
realm.For example, the following snippet shows the most basic
pki
realm configuration:xpack: security: authc: realms: pki1: type: pki
With this configuration, any certificate trusted by the SSL/TLS layer is accepted for authentication. The username is the common name (CN) extracted from the DN of the certificate.
When you configure realms in
elasticsearch.yml
, only the realms you specify are used for authentication. If you also want to use thenative
orfile
realms, you must include them in the realm chain.If you want to use something other than the CN of the DN as the username, you can specify a regex to extract the desired username. For example, the regex in the following configuration extracts the email address from the DN:
xpack: security: authc: realms: pki1: type: pki username_pattern: "EMAILADDRESS=(.*?)(?:,|$)"
- Restart Elasticsearch.
PKI and SSL Settings
editThe PKI realm relies on the SSL settings of the node’s network interface (transport or http). The realm can be configured to be more restrictive than the underlying network connection - that is, it is possible to configure the node such that some connections are accepted by the network interface but then fail to be authenticated by the PKI realm. However the reverse is not possible - the PKI realm cannot authenticate a connection that has been refused by the network interface.
In particular this means:
-
The transport or http interface must request client certificates by setting
client_authentication
tooptional
orrequired
. -
The interface must trust the certificate that is presented by the client
by configuring either the
truststore
orcertificate_authorities
paths, or by settingverification_mode
tonone
. - The protocols supported by the interface must be compatible with those used by the client.
The relevant network interface (transport or http) must be configured to trust any certificate that is to be used within the PKI realm. However it possible to configure the PKI realm to trust only a subset of the certificates accepted by the network interface. This is useful when the SSL/TLS layer trusts clients with certificates that are signed by a different CA than the one that signs your users' certificates.
To configure the PKI realm with its own truststore, specify the
truststore.path
option as below:
xpack: security: authc: realms: pki1: type: pki truststore: path: "/path/to/pki_truststore.jks" password: "changeme"
The certificate_authorities
option may be used as an alternative to the
truststore.path
setting.
PKI Realm Settings
editSee Security Settings for All Realms and PKI Realm Settings.
Mapping Roles for PKI Users
editYou map roles for PKI users through the role-mapping API, or by using a file stored on each node. When a user authenticates against a PKI realm, the privileges for that user are the union of all privileges defined by the roles to which the user is mapped.
You identify a user by the distinguished name in their certificate.
For example, the following mapping configuration maps John Doe
to the
user
role:
Using the role-mapping API:
PUT _xpack/security/role_mapping/users { "roles" : [ "user" ], "rules" : { "field" : { "dn" : "cn=John Doe,ou=example,o=com" } }, "enabled": true }
Or, alternatively, configured in a role-mapping file:
The disinguished name for a PKI user follows X.500 naming conventions which
place the most specific fields (like cn
or uid
) at the beginning of the
name, and the most general fields (like o
or dc
) at the end of the name.
Some tools, such as openssl, may print out the subject name in a different
format.
One way that you can determine the correct DN for a certificate is to use the
authenticate API (use the relevant PKI
certificate as the means of authentication) and inspect the metadata field in
the result. The user’s distinguished name will be populated under the pki_dn
key. You can also use the authenticate API to validate your role mapping.
For more information, see Mapping Users and Groups to Roles.