configuring-pki-realm.asciidoc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. [role="xpack"]
  2. [[configuring-pki-realm]]
  3. === Configuring a PKI realm
  4. You can configure {es} to use Public Key Infrastructure (PKI) certificates
  5. to authenticate users. This requires clients to present X.509 certificates.
  6. NOTE: You cannot use PKI certificates to authenticate users in {kib}.
  7. To use PKI in {es}, you configure a PKI realm, enable client authentication on
  8. the desired network layers (transport or http), and map the Distinguished Names
  9. (DNs) from the user certificates to roles in the
  10. <<security-api-role-mapping,role-mapping API>> or role-mapping file.
  11. You can also use a combination of PKI and username/password authentication. For
  12. example, you can enable SSL/TLS on the transport layer and define a PKI realm to
  13. require transport clients to authenticate with X.509 certificates, while still
  14. authenticating HTTP traffic using username and password credentials. You can
  15. also set `xpack.security.transport.ssl.client_authentication` to `optional` to
  16. allow clients without certificates to authenticate with other credentials.
  17. IMPORTANT: You must enable SSL/TLS and enable client authentication to use PKI.
  18. For more information, see {stack-ov}/pki-realm.html[PKI User Authentication].
  19. . Add a realm configuration for a `pki` realm to `elasticsearch.yml` under the
  20. `xpack.security.authc.realms.pki` namespace.
  21. If you are configuring multiple realms, you should
  22. explicitly set the `order` attribute. See <<ref-pki-settings>> for all of the
  23. options you can set for a `pki` realm.
  24. +
  25. --
  26. For example, the following snippet shows the most basic `pki` realm configuration:
  27. [source, yaml]
  28. ------------------------------------------------------------
  29. xpack:
  30. security:
  31. authc:
  32. realms:
  33. pki:
  34. pki1:
  35. order: 1
  36. ------------------------------------------------------------
  37. With this configuration, any certificate trusted by the SSL/TLS layer is accepted
  38. for authentication. The username is the common name (CN) extracted from the DN
  39. of the certificate.
  40. IMPORTANT: When you configure realms in `elasticsearch.yml`, only the
  41. realms you specify are used for authentication. If you also want to use the
  42. `native` or `file` realms, you must include them in the realm chain.
  43. If you want to use something other than the CN of the DN as the username, you
  44. can specify a regex to extract the desired username. For example, the regex in
  45. the following configuration extracts the email address from the DN:
  46. [source, yaml]
  47. ------------------------------------------------------------
  48. xpack:
  49. security:
  50. authc:
  51. realms:
  52. pki:
  53. pki1:
  54. username_pattern: "EMAILADDRESS=(.*?)(?:,|$)"
  55. ------------------------------------------------------------
  56. --
  57. . Restart {es}.
  58. . <<configuring-tls,Enable SSL/TLS>>.
  59. . Enable client authentication on the desired network layers (transport or http).
  60. +
  61. --
  62. The PKI realm relies on the TLS settings of the node's network interface. The
  63. realm can be configured to be more restrictive than the underlying network
  64. connection - that is, it is possible to configure the node such that some
  65. connections are accepted by the network interface but then fail to be
  66. authenticated by the PKI realm. However, the reverse is not possible. The PKI
  67. realm cannot authenticate a connection that has been refused by the network
  68. interface.
  69. In particular this means:
  70. * The transport or http interface must request client certificates by setting
  71. `client_authentication` to `optional` or `required`.
  72. * The interface must _trust_ the certificate that is presented by the client
  73. by configuring either the `truststore` or `certificate_authorities` paths,
  74. or by setting `verification_mode` to `none`. See
  75. <<ssl-tls-settings,`ssl.verification_mode`>> for an explanation of this
  76. setting.
  77. * The _protocols_ supported by the interface must be compatible with those
  78. used by the client.
  79. The relevant network interface (transport or http) must be configured to trust
  80. any certificate that is to be used within the PKI realm. However, it possible to
  81. configure the PKI realm to trust only a _subset_ of the certificates accepted
  82. by the network interface. This is useful when the SSL/TLS layer trusts clients
  83. with certificates that are signed by a different CA than the one that signs your
  84. users' certificates.
  85. To configure the PKI realm with its own truststore, specify the `truststore.path`
  86. option. For example:
  87. [source, yaml]
  88. ------------------------------------------------------------
  89. xpack:
  90. security:
  91. authc:
  92. realms:
  93. pki:
  94. pki1:
  95. truststore:
  96. path: "/path/to/pki_truststore.jks"
  97. password: "x-pack-test-password"
  98. ------------------------------------------------------------
  99. The `certificate_authorities` option can be used as an alternative to the
  100. `truststore.path` setting.
  101. --
  102. . Map roles for PKI users.
  103. +
  104. --
  105. You map roles for PKI users through the
  106. <<security-role-mapping-apis,role mapping APIs>> or by using a file stored on
  107. each node. When a user authenticates against a PKI realm, the privileges for
  108. that user are the union of all privileges defined by the roles to which the
  109. user is mapped.
  110. You identify a user by the distinguished name in their certificate.
  111. For example, the following mapping configuration maps `John Doe` to the
  112. `user` role:
  113. Using the role-mapping API:
  114. [source,js]
  115. --------------------------------------------------
  116. PUT /_security/role_mapping/users
  117. {
  118. "roles" : [ "user" ],
  119. "rules" : { "field" : {
  120. "dn" : "cn=John Doe,ou=example,o=com" <1>
  121. } },
  122. "enabled": true
  123. }
  124. --------------------------------------------------
  125. // CONSOLE
  126. <1> The distinguished name (DN) of a PKI user.
  127. Or, alternatively, configured in a role-mapping file:
  128. [source, yaml]
  129. ------------------------------------------------------------
  130. user: <1>
  131. - "cn=John Doe,ou=example,o=com" <2>
  132. ------------------------------------------------------------
  133. <1> The name of a role.
  134. <2> The distinguished name (DN) of a PKI user.
  135. The distinguished name for a PKI user follows X.500 naming conventions which
  136. place the most specific fields (like `cn` or `uid`) at the beginning of the
  137. name, and the most general fields (like `o` or `dc`) at the end of the name.
  138. Some tools, such as _openssl_, may print out the subject name in a different
  139. format.
  140. One way that you can determine the correct DN for a certificate is to use the
  141. <<security-api-authenticate,authenticate API>> (use the relevant PKI
  142. certificate as the means of authentication) and inspect the metadata field in
  143. the result. The user's distinguished name will be populated under the `pki_dn`
  144. key. You can also use the authenticate API to validate your role mapping.
  145. For more information, see
  146. {stack-ov}/mapping-roles.html[Mapping Users and Groups to Roles].
  147. NOTE: The PKI realm supports
  148. {stack-ov}/realm-chains.html#authorization_realms[authorization realms] as an
  149. alternative to role mapping.
  150. --