saml-guide.asciidoc 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. [role="xpack"]
  2. [[saml-guide]]
  3. == Configuring SAML single-sign-on on the {stack}
  4. The Elastic Stack supports SAML single-sign-on (SSO) into {kib}, using {es} as
  5. a backend service. In SAML terminology, the Elastic Stack is operating as a
  6. _Service Provider_.
  7. The other component that is needed to enable SAML single-sign-on is the
  8. _Identity Provider_, which is a service that handles your credentials and
  9. performs that actual authentication of users.
  10. If you are interested in configuring SSO into {kib}, then you will need to
  11. provide {es} with information about your _Identity Provider_, and you will need
  12. to register the Elastic Stack as a known _Service Provider_ within that
  13. Identity Provider. There are also a few configuration changes that are
  14. required in {kib} to activate the SAML authentication provider.
  15. NOTE: The SAML support in {kib} is designed on the expectation that it will be
  16. the primary (or sole) authentication method for users of that {kib} instance.
  17. Once you enable SAML authentication in {kib} it will affect all users who try
  18. to login. The <<saml-kibana>> section provides more detail about how this works.
  19. === The identity provider
  20. The Elastic Stack supports the SAML 2.0 _Web Browser SSO_ and the SAML
  21. 2.0 _Single Logout_ profiles and can integrate with any Identity Provider (IdP)
  22. that supports at least the SAML 2.0 _Web Browser SSO Profile_.
  23. It has been tested with a number of popular IdP implementations.
  24. This guide assumes that you have an existing IdP and wish to add {kib} as a
  25. Service Provider.
  26. The Elastic Stack uses a standard SAML _metadata_ document, in XML format that
  27. defines the capabilities and features of your IdP. You should be able to
  28. download or generate such a document within your IdP administration interface.
  29. Download the IdP metadata document and store it within the `config` directory on
  30. each {es} node. For the purposes of this guide, we will assume that you are
  31. storing it as `config/saml/idp-metadata.xml`.
  32. The IdP will have been assigned an identifier (_EntityID_ in SAML terminology)
  33. which is most commonly expressed in _Uniform Resource Identifier_ (URI) form.
  34. Your admin interface may tell you what this is, or you might need to
  35. read the metadata document to find it - look for the `entityID` attribute on the
  36. `EntityDescriptor` element.
  37. Most IdPs will provide an appropriate metadata file with all the features that
  38. the Elastic Stack requires, and should only require the configuration steps
  39. described below. For completeness sake, the minimum requirements that the Elastic
  40. Stack has for the IdP's metadata are:
  41. - An `<EntityDescriptor>` with an `entityID` that matches the {es}
  42. <<saml-create-realm, configuration>>
  43. - An `<IDPSSODescriptor>` that supports the SAML 2.0 protocol
  44. (`urn:oasis:names:tc:SAML:2.0:protocol`).
  45. - At least one `<KeyDescriptor>` that is configured for _signing_ (that is, it
  46. has `use="signing"` or leaves the `use` unspecified)
  47. - A `<SingleSignOnService>` with binding of HTTP-Redirect
  48. (`urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect`)
  49. - If you wish to support <<saml-logout, Single Logout>>, a `<SingleLogoutService>`
  50. with binding of HTTP-Redirect
  51. (`urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect`)
  52. The Elastic Stack requires that all messages from the IdP are signed.
  53. For authentication `<Response>` messages, the signature may be applied to either
  54. the response itself, or to the individual assertions.
  55. For `<LogoutRequest>` messages, the message itself must be signed, and the
  56. signature should be provided as a URL parameter, as required by the HTTP-Redirect
  57. binding.
  58. === Configure {es} for SAML authentication
  59. There are five configuration steps to enable SAML authentication in {es}:
  60. . Enable SSL/TLS for HTTP
  61. . Enable the Token Service
  62. . Create one or more SAML realms
  63. . Configure role mappings
  64. . Generate a SAML Metadata file for use by your Identity Provider _(optional)_
  65. ==== Enable TLS for HTTP
  66. If your {es} cluster is operating in production mode, then you must
  67. configure the HTTP interface to use SSL/TLS before you can enable SAML
  68. authentication.
  69. For more information, see
  70. {ref}/configuring-tls.html#tls-http[Encrypting HTTP Client Communications].
  71. ==== Enable the token service
  72. The {es} SAML implementation makes use of the {es} Token Service. This service
  73. is automatically enabled if you configure TLS on the HTTP interface, and can be
  74. explicitly configured by including the following in your `elasticsearch.yml` file:
  75. [source, yaml]
  76. ------------------------------------------------------------
  77. xpack.security.authc.token.enabled: true
  78. ------------------------------------------------------------
  79. [[saml-create-realm]]
  80. ==== Create a SAML realm
  81. SAML authentication is enabled by configuring a SAML realm within the
  82. authentication chain for {es}.
  83. This realm has a few mandatory settings, and a number of optional settings.
  84. The available settings are described in detail in the
  85. <<saml-settings, SAML realm documentation>>, this guide will walk you through
  86. the most common settings.
  87. Create a realm by adding the following to your `elasticsearch.yml`
  88. configuration file. Each configuration value is explained below.
  89. [source, yaml]
  90. ------------------------------------------------------------
  91. xpack.security.authc.realms.saml1:
  92. type: saml
  93. order: 2
  94. idp.metadata.path: saml/idp-metadata.xml
  95. idp.entity_id: "https://sso.example.com/"
  96. sp.entity_id: "https://kibana.example.com/"
  97. sp.acs: "https://kibana.example.com/api/security/v1/saml"
  98. sp.logout: "https://kibana.example.com/logout"
  99. attributes.principal: "urn:oid:0.9.2342.19200300.100.1.1"
  100. attributes.groups: "urn:oid:1.3.6.1.4.1.5923.1.5.1."
  101. ------------------------------------------------------------
  102. IMPORTANT: SAML is used when authenticating via {kib}, but it is not an
  103. effective means of authenticating directly to the {es} REST API. For this reason
  104. we recommend that you include at least one additional realm such as the
  105. <<native-realm, native realm>> in your authentication chain for use by API
  106. clients.
  107. The configuration values used in the example above are:
  108. xpack.security.authc.realms.saml::
  109. This defines a new authentication realm named "saml1".
  110. See <<realms>> for more explanation of realms.
  111. type:: The `type` must be `saml`
  112. order::
  113. You should define a unique order on each realm in your authentication chain.
  114. It is recommended that the SAML realm be at the bottom of your authentication
  115. chain (that is, that it has the _highest_ order).
  116. idp.metadata.path::
  117. This is the path to the metadata file that you saved for your Identity Provider.
  118. The path that you enter here is relative to your `config/` directory.
  119. {security} will automatically monitor this file for changes and will
  120. reload the configuration whenever it is updated.
  121. idp.entity_id::
  122. This is the identifier (SAML EntityID) that your IdP uses.
  123. It should match the `entityID` attribute within the metadata file.
  124. sp.entity_id::
  125. This is a unique identifier for your {kib} instance, expressed as a URI.
  126. You will use this value when you add {kib} as a service provider within your IdP.
  127. We recommend that you use the base URL for your {kib} instance as the entity ID.
  128. sp.acs::
  129. The _Assertion Consumer Service_ (ACS) endpoint is the URL within {kib} that accepts
  130. authentication messages from the IdP.
  131. This ACS endpoint supports the SAML HTTP-POST binding only.
  132. It must be a URL that is accessible from the web browser of the user who is
  133. attempting to login to {kib}, it does not need to be directly accessible by {es}
  134. or the IdP.
  135. The correct value may vary depending on how you have installed {kib} and
  136. whether there are any proxies involved, but it will typically be
  137. +$\{kibana-url}/api/security/v1/saml+ where _$\{kibana-url}_ is the base URL for
  138. your {kib} instance.
  139. sp.logout::
  140. This is the URL within {kib} that accepts logout messages from the IdP.
  141. Like the `sp.acs` URL, it must be accessible from the web browser, but does
  142. not need to be directly accessible by {es} or the IdP. The correct value may
  143. vary depending on how you have installed {kib} and whether there are any
  144. proxies involved, but it will typically be +$\{kibana-url}/logout+ where
  145. _$\{kibana-url}_ is the base URL for your {kib} instance.
  146. attribute.principal:: See <<saml-attribute-mapping>>.
  147. attribute.groups:: See <<saml-attribute-mapping>>.
  148. [[saml-attribute-mapping]]
  149. ==== Attribute mapping
  150. When a user connects to {kib} through your Identity Provider, the Identity
  151. Provider will supply a SAML Assertion about the user. The assertion will contain
  152. an _Authentication Statement_ indicating that the user has successfully
  153. authenticated to the IdP and one ore more _Attribute Statements_ that will
  154. include _Attributes_ for the user.
  155. These attributes may include such things as:
  156. - the user's username
  157. - the user's email address
  158. - the user's groups or roles
  159. Attributes in SAML are named using a URI such as
  160. `urn:oid:0.9.2342.19200300.100.1.1` or
  161. `http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn`, and have one or
  162. more values associated with them.
  163. These attribute identifiers vary between IdPs, and most IdPs offer ways to
  164. customise the URIs and their associated value.
  165. {es} uses these attributes to infer information about the user who has
  166. logged in, and they can be used for role mapping (below).
  167. In order for these attributes to be useful, {es} and the IdP need to have a
  168. common via for the names of the attributes. This is done manually, by
  169. configuring the IdP and the {security} SAML realm to use the same URI name for
  170. each logical user attribute.
  171. The recommended steps for configuring these SAML attributes are as follows:
  172. . Consult your IdP to see what user attributes it can provide.
  173. This varies greatly between providers, but you should be able to obtain a list
  174. from the documentation, or from your local admin.
  175. . Read through the list of <<saml-user-properties, user properties>> that {es}
  176. supports, and decide which of them are useful to you, and can be provided by
  177. your IdP. At a _minimum_, the `principal` attribute is required.
  178. . Configure your IdP to "release" those attributes to your {kib} SAML service
  179. provider. This process varies by provider - some will provide a user interface
  180. for this, while others may require that you edit configuration files.
  181. Usually the IdP (or your local administrator) will have suggestions about what
  182. URI to use for each attribute. You can simply accept those suggestions, as the
  183. {es} service is entirely configurable and does not require that any specific
  184. URIs are used.
  185. . Configure the SAML realm in {es} to associate the {es} user properties (see
  186. <<saml-user-properties, the listing>> below), to the URIs that you configured
  187. in your IdP. In the example above, we have configured the `principal` and
  188. `groups` attributes.
  189. ===== Special attribute names
  190. In general, {es} expects that the configured value for an attribute will be a
  191. URI such as `urn:oid:0.9.2342.19200300.100.1.1`, however there are some
  192. additional names that can be used:
  193. `nameid`::
  194. This uses the SAML `NamedID` value instead of a SAML attribute. SAML
  195. `NameID` elements are an optional, but frequently provided, field within a
  196. SAML Assertion that the IdP may use to identify the Subject of that
  197. Assertion. In some cases the `NameID` will relate to the user's login
  198. identifier (username) wihin the IdP, but in many cases they will be
  199. internally generated identifiers that have no obvious meaning outside
  200. of the IdP.
  201. `nameid:persistent`::
  202. This uses the SAML `NameID` value, but only if the NameID format is
  203. `urn:oasis:names:tc:SAML:2.0:nameid-format:persistent`.
  204. A SAML `NameID` element has an optional `Format` attribute that indicates
  205. the semantics of the provided name. It is common for IdPs to be configured
  206. with "transient" NameIDs that present a new identifier for each session.
  207. Since it is rarely useful to use a transient NameID as part of an attribute
  208. mapping, the "nameid:persistent" attribute name can be used as a safety
  209. mechanism that will cause an error if you attempt to map from a `NameID`
  210. that does not have a persistent value.
  211. _friendlyName_::
  212. A SAML attribute may have a _friendlyName_ in addition to its URI based name.
  213. For example the attribute with a name of `urn:oid:0.9.2342.19200300.100.1.1`
  214. might also have a friendlyName of `uid`.
  215. You may use these friendly names within an attribute mapping, but it is
  216. recommended that you use the URI based names, as friendlyNames are neither
  217. standardized or mandatory.
  218. The example below configures a realm to use a persistent nameid for the principal,
  219. and the attribute with the friendlyName "roles" for the user's groups.
  220. [source, yaml]
  221. ------------------------------------------------------------
  222. xpack.security.authc.realms.saml1:
  223. type: saml
  224. order: 2
  225. idp.metadata.path: saml/idp-metadata.xml
  226. idp.entity_id: "https://sso.example.com/"
  227. sp.entity_id: "https://kibana.example.com/"
  228. sp.acs: "https://kibana.example.com/api/security/v1/saml"
  229. attributes.principal: "nameid:persistent"
  230. attributes.groups: "roles"
  231. ------------------------------------------------------------
  232. [[saml-user-properties]]
  233. ===== {es} user properties
  234. The {es} SAML realm can be configured to map SAML `attributes` to the
  235. following properties on the authenticated user:
  236. principal:: _(Required)_
  237. This is the _username_ that will be applied to a user that authenticates
  238. against this realm.
  239. The `principal` appears in places such as the {es} audit logs.
  240. groups:: _(Recommended)_
  241. If you wish to use your IdP's concept of groups or roles as the basis for a
  242. user's {es} privileges, you should map them with this attribute.
  243. The `groups` are passed directly to your
  244. <<saml-role-mapping, role mapping rules>>
  245. name:: _(Optional)_ The user's full name.
  246. mail:: _(Optional)_ The user's email address.
  247. dn:: _(Optional)_ The user's X.500 _Distinguished Name_.
  248. ===== Extracting partial values from SAML attributes
  249. There are some occasions where the IdP's attribute may contain more information
  250. than you wish to use within {es}. A common example of this is one where the
  251. IdP works exclusively with email addresses, but you would like the user's
  252. `principal` to use the _local-name_ part of the email address.
  253. For example if their email address was `james.wong@staff.example.com`, then you
  254. would like their principal to simply be `james.wong`.
  255. This can be achieved using the `attribute_patterns` setting in the {es}
  256. realm, as demonstrated in the realm configuration below:
  257. [source, yaml]
  258. ------------------------------------------------------------
  259. xpack.security.authc.realms.saml1:
  260. type: saml
  261. order: 2
  262. idp.metadata.path: saml/idp-metadata.xml
  263. idp.entity_id: "https://sso.example.com/"
  264. sp.entity_id: "https://kibana.example.com/"
  265. sp.acs: "https://kibana.example.com/api/security/v1/saml"
  266. attributes.principal: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
  267. attribute_patterns.principal: "^([^@]+)@staff\\.example\\.com$"
  268. ------------------------------------------------------------
  269. In this case, the user's `principal` is mapped from an email attribute, but a
  270. regular expression is applied to the value before it is assigned to the user.
  271. If the regular expression matches, then the result of the first group is used as
  272. effective value. If the regular expression does not match then the attribute
  273. mapping fails.
  274. In this example, the email address must belong to the `staff.example.com` domain,
  275. and then the local-part (anything before the `@`) is used as the principal.
  276. Any users who try to login using a different email domain will fail because the
  277. regular expression will not match against their email address, and thus their
  278. principal attribute - which is mandatory - will not be populated.
  279. IMPORTANT: Small mistakes in these regular expressions can have significant
  280. security consequences. For example, if we accidentally left off the trailing
  281. `$` from the example above, then we would match any email address where the
  282. domain starts with `staff.example.com`, and this would accept an email
  283. address such as `admin@staff.example.com.attacker.net`. It is important that
  284. you make sure your regular expressions are as precise as possible so that
  285. you do not inadvertently open an avenue for user impersonation attacks.
  286. [[saml-logout]]
  287. ==== SAML logout
  288. The SAML protocol supports the concept of Single Logout (SLO).
  289. The level of support for SLO varies between Identity Providers.
  290. You should consult the documentation for your IdP to determine what Logout
  291. services it offers.
  292. By default the Elastic Stack will support SAML SLO if the following are true:
  293. - Your IdP metadata specifies that the IdP offers a SLO service
  294. - You configure `sp.logout`
  295. - The setting `idp.use_single_logout` is not `false`
  296. ===== IdP SLO service
  297. One of the values that {es} reads from the IdP's SAML metadata is the
  298. `<SingleLogoutService>`. In order for Single Logout to work with the Elastic
  299. stack, {es} requires that this exist and support a binding of
  300. `urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect`.
  301. The Elastic Stack will send both `<LogoutRequest>` and `<LogoutResponse>`
  302. messages to this service as appropriate.
  303. ===== The sp.logout setting
  304. The {es} realm setting `sp.logout` specifies a URL in {kib} to which the IdP can
  305. send both `<LogoutRequest>` and `<LogoutResponse>` messages. This service uses
  306. the SAML HTTP-Redirect binding.
  307. {es} will process `<LogoutRequest>` messages, and perform a global signout that
  308. invalidates any existing {es} security tokens that are associated with the
  309. provided SAML session.
  310. If you do not configure a value for `sp.logout`, {es} will refuse all
  311. `<LogoutRequest>` messages.
  312. NOTE: It is common for IdPs to require that `LogoutRequest` messages be signed,
  313. so you may need to configure <<saml-enc-sign,signing credentials>>.
  314. ===== The idp.use_single_logout setting
  315. If your IdP provides a `<SingleLogoutService>` but you do not wish to use it,
  316. you can configure `idp.use_single_logout: false` in your SAML realm, and {es}
  317. will ignore the SLO service that your IdP provides. In this case, when a user
  318. logs out of {kib} it will invalidate their {es} session (security token), but
  319. will not perform any logout at the IdP.
  320. ===== Using {kib} without single logout
  321. If your IdP does not support Single Logout, or you choose not to use it, then
  322. {kib} will perform a "local logout" only.
  323. This means that {kib} will invalidate the session token it is using to
  324. communicate with {es}, but will not be able to perform any sort of invalidation
  325. of the Identity Provider session. In most cases this will mean that {kib} users
  326. are still considered to be logged in to the IdP. Consequently, if the user
  327. navigates to the {kib} landing page, they will be automatically reauthenticated,
  328. and will commence a new {kib} session without needing to enter any credentials.
  329. The possible solutions to this problem are:
  330. - Ask your IdP administrator or vendor to provide a Single Logout service
  331. - If your Idp does provide a Single Logout Service, make sure it is included in
  332. the IdP metadata file, and do _not_ set `idp.use_single_logout` to `false`.
  333. - Advise your users to close their browser after logging out of {kib}
  334. - Enable the `force_authn` setting on your SAML realm. This setting causes the
  335. Elastic Stack to request fresh authentication from the IdP every time a user
  336. attempts to log into {kib}.
  337. This setting defaults to `false` because it can be a more cumbersome user
  338. experience, but it can also be an effective protection to stop users
  339. piggy-backing on existing IdP sessions.
  340. [[saml-enc-sign]]
  341. ==== Encryption and signing
  342. The Elastic Stack supports generating signed SAML messages (for authentication
  343. and/or logout), verifying signed SAML messages from the IdP (for both
  344. authentication and logout) and can process encrypted content.
  345. You can configure {es} for signing, encryption or both, with the same
  346. or separate keys used for each of those.
  347. The Elastic Stack uses X.509 certificates with RSA private keys for SAML
  348. cryptography. These keys can be generated using any standard SSL tool, including
  349. the `elasticsearch-certutil` tool that ships with X-Pack.
  350. Your IdP may require that the Elastic Stack have a cryptographic key for signing
  351. SAML messages, and that you provide the corresponding signing certificate within
  352. the Service Provider configuration (either within the Elastic Stack SAML
  353. metadata file or manually configured within the IdP administration interface).
  354. While most IdPs do not expected authentication requests to be signed, it is
  355. commonly the case that signatures are required for logout requests. Your IdP
  356. will validate these signatures against the signing certificate that has been
  357. configured for the Elastic Stack Service Provider.
  358. Encryption certificates are rarely needed, but the Elastic Stack supports them
  359. for cases where IdPs or local policies mandate their use.
  360. ===== Generating certificates and keys
  361. {es} supports certificates and keys in either PEM, PKCS#12 or JKS format.
  362. Some Identity Providers are more restrictive in the formats they support, and
  363. will require you to provide the certificates as a file in a particular format.
  364. You should consult the documentation for your IdP to determine what formats they
  365. support. Since PEM format is the most commonly supported format, the examples
  366. below will generate certificates in that format.
  367. Using the {ref}/certutil.html[`elasticsearch-certutil`] tool, you can generate a
  368. signing certificate with the following command:
  369. [source, sh]
  370. --------------------------------------------------
  371. bin/elasticsearch-certutil cert -pem -days 1100 -name saml-sign -out saml-sign.zip
  372. --------------------------------------------------
  373. This will
  374. - generate a certificate and key pair (the `cert` subcommand)
  375. - create the files in PEM format (`-pem` option)
  376. - generate a certificate that is valid for 3 years (`-days 1100`)
  377. - name the certificate `saml-sign` (`-name` option)
  378. - save the certificate and key in the `saml-sign.zip` file (`-out` option)
  379. The generated zip archive will contain 3 files:
  380. - `saml-sign.crt`, the public certificate to be used for signing
  381. - `saml-sign.key`, the private key for the certificate
  382. - `ca.crt`, a CA certificate that is not need, and can be ignored.
  383. Encryption certificates can be generated with the same process.
  384. ===== Configuring {es} for signing
  385. By default, {security} will sign _all_ outgoing SAML messages if a signing
  386. key has been configured.
  387. If you wish to use *PEM formatted* keys and certificates for signing, then
  388. you should configure the following settings on the SAML realm:
  389. `signing.certificate`::
  390. The path to the PEM formatted certificate file. e.g. `saml/saml-sign.crt`
  391. `signing.key`::
  392. The path to the PEM formatted key file. e.g. `saml/saml-sign.key`
  393. `signing.secure_key_passphrase`::
  394. The passphrase for the key, if the file is encypted. This is a
  395. {ref}/secure-settings.html[secure setting] that must be set with the
  396. `elasticsearch-keystore` tool.
  397. If you wish to use *PKCS#12 formatted* files or a *Java Keystore* for
  398. signing, then you should configure the following settings on the SAML realm:
  399. `signing.keystore.path`::
  400. The path to the PKCS#12 or JKS keystore. e.g. `saml/saml-sign.p12`
  401. `signing.keystore.alias`::
  402. The alias of the key within the keystore. e.g. `signing-key`
  403. `signing.keystore.secure_password`::
  404. The passphrase for the keystore, if the file is encypted. This is a
  405. {ref}/secure-settings.html[secure setting] that must be set with the
  406. `elasticsearch-keystore` tool.
  407. If you wish to sign some, but not all outgoing *SAML messages*, then you
  408. should configure the following setting on the SAML realm:
  409. `signing.saml_messages`::
  410. A list of message types to sign. A message type is identified by the
  411. _local name_ of the XML element used for the message. Supported values
  412. are: `AuthnRequest`, `LogoutRequest` and `LogoutResponse`.
  413. ===== Configuring {es} for encrypted messages
  414. {security} supports a single key for message decryption. If a key is
  415. configured, then {security} will attempt to use it to decrypt
  416. `EncryptedAssertion` and `EncryptedAttribute` elements in Authentication
  417. responses, and `EncryptedID` elements in Logout requests.
  418. {security} will reject any SAML message that contains an `EncryptedAssertion`
  419. that cannot be decrypted.
  420. If an `Assertion` contains both encrypted and plain-text attributes, then
  421. failure to decrypt the encrypted attributes will not cause an automatic
  422. rejection. Rather, {security} will process the available plain-text attributes
  423. (and any `EncryptedAttributes` that could be decrypted).
  424. If you wish to use *PEM formatted* keys and certificates for SAML encryption,
  425. then you should configure the following settings on the SAML realm:
  426. `encryption.certificate`::
  427. The path to the PEM formatted certificate file. e.g. `saml/saml-crypt.crt`
  428. `encryption.key`::
  429. The path to the PEM formatted key file. e.g. `saml/saml-crypt.key`
  430. `encryption.secure_key_passphrase`::
  431. The passphrase for the key, if the file is encypted. This is a
  432. {ref}/secure-settings.html[secure setting] that must be set with the
  433. `elasticsearch-keystore` tool.
  434. If you wish to use *PKCS#12 formatted* files or a *Java Keystore* for SAML
  435. encryption, then you should configure the following settings on the SAML realm:
  436. `encryption.keystore.path`::
  437. The path to the PKCS#12 or JKS keystore. e.g. `saml/saml-crypt.p12`
  438. `encryption.keystore.alias`::
  439. The alias of the key within the keystore. e.g. `encryption-key`
  440. `encryption.keystore.secure_password`::
  441. The passphrase for the keystore, if the file is encypted. This is a
  442. {ref}/secure-settings.html[secure setting] that must be set with the
  443. `elasticsearch-keystore` tool.
  444. === Generating SP metadata
  445. Some Identity Providers support importing a metadata file from the Service
  446. Provider. This will automatically configure many of the integration options
  447. between the IdP and the SP.
  448. The Elastic Stack supports generating such a metadata file using the
  449. `bin/elasticsearch-saml-metadata` command in your {es} directory.
  450. The {ref}/saml-metadata.html[documentation for the elasticsearch-saml-metadata utility]
  451. describes how to run it, and the available command line options.
  452. [[saml-role-mapping]]
  453. === Configuring role mappings
  454. When a user authenticates using SAML, they are identified to the Elastic Stack,
  455. but this does not automatically grant them access to perform any actions or
  456. access any data.
  457. Your SAML users cannot do anything until they are mapped to X-Pack Security
  458. roles. This mapping is performed through the
  459. {ref}/security-api-role-mapping.html[role-mapping API]
  460. This is an example of a simple role mapping that grants the `kibana_user` role
  461. to any user who authenticates against the `saml1` realm:
  462. [source,js]
  463. --------------------------------------------------
  464. PUT /_xpack/security/role_mapping/saml-kibana
  465. {
  466. "roles": [ "kibana_user" ],
  467. "enabled": true,
  468. "rules": {
  469. "field": { "realm.name": "saml1" }
  470. }
  471. }
  472. --------------------------------------------------
  473. // CONSOLE
  474. // TEST
  475. The attributes that are mapped via the realm configuration are used to process
  476. role mapping rules, and these rules determine which roles a user is granted.
  477. The user fields that are provided to the role
  478. mapping are derived from the SAML attributes as follows:
  479. - `username`: The `principal` attribute
  480. - `dn`: The `dn` attribute
  481. - `groups`: The `groups` attribute
  482. - `metadata`: See <<saml-user-metadata>>
  483. For more information, see <<mapping-roles>> and
  484. {ref}/security-api-role-mapping.html[Role Mapping APIs].
  485. If your IdP has the ability to provide groups or roles to Service Providers,
  486. then you should map this SAML attribute to the `attributes.groups` setting in
  487. the {es} realm, and then make use of it in a role mapping as per the example
  488. below.
  489. This mapping grants the {es} `finance_data` role, to any users who authenticate
  490. via the `saml1` realm with the `finance-team` group.
  491. [source,js]
  492. --------------------------------------------------
  493. PUT /_xpack/security/role_mapping/saml-finance
  494. {
  495. "roles": [ "finance_data" ],
  496. "enabled": true,
  497. "rules": { "all": [
  498. { "field": { "realm.name": "saml1" } },
  499. { "field": { "groups": "finance-team" } }
  500. ] }
  501. }
  502. --------------------------------------------------
  503. // CONSOLE
  504. // TEST
  505. [[saml-user-metadata]]
  506. === User metadata
  507. By default users who authenticate via SAML will have some additional metadata
  508. fields.
  509. - `saml_nameid` will be set to the value of the `NameID` element in the SAML
  510. authentication response
  511. - `saml_nameid_format` will be set to the full URI of the NameID's `format`
  512. attribute
  513. - Every SAML Attribute that is provided in the authentication response
  514. (regardless of whether it is mapped to an {es} user property), will be added
  515. as the metadata field `saml(name)` where "name" is the full URI name of the
  516. attribute. For example `saml(urn:oid:0.9.2342.19200300.100.1.3)`.
  517. - For every SAML Attribute that has a _friendlyName_, will also be added as the
  518. metadata field `saml_friendlyName` where "name" is the full URI name of the
  519. attribute. For example `saml_mail`.
  520. This behaviour can be disabled by adding `populate_user_metadata: false` to as
  521. a setting in the saml realm.
  522. [[saml-kibana]]
  523. === Configuring {kib}
  524. SAML authentication in {kib} requires a small number of additional settings
  525. in addition to the standard {kib} security configuration. The
  526. {kibana-ref}/using-kibana-with-security.html[{kib} security documentation]
  527. provides details on the available configuration options that you can apply.
  528. In particular, since your {es} nodes have been configured to use TLS on the HTTP
  529. interface, you must configure {kib} to use a `https` URL to connect to {es}, and
  530. you may need to configure `elasticsearch.ssl.certificateAuthorities` to trust
  531. the certificates that {es} has been configured to use.
  532. SAML authentication in {kib} is also subject to the
  533. `xpack.security.sessionTimeout` setting that is described in the {kib} security
  534. documentation, and you may wish to adjst this timeout to meet your local needs.
  535. The two additional settings that are required for SAML support are shown below:
  536. [source, yaml]
  537. ------------------------------------------------------------
  538. xpack.security.authProviders: [saml]
  539. server.xsrf.whitelist: [/api/security/v1/saml]
  540. ------------------------------------------------------------
  541. The configuration values used in the example above are:
  542. `xpack.security.authProviders`::
  543. Set this to `[ saml ]` to instruct {kib} to use SAML SSO as the authentication
  544. method.
  545. `server.xsrf.whitelist`::
  546. {kib} has in-built protection against _Cross Site Request Forgery_ attacks which
  547. are designed to prevent the {kib} server from processing requests that
  548. originated from outside the {kib} application.
  549. In order to support SAML authentication messages that originate from your
  550. Identity Provider, we need to explicitly _whitelist_ the SAML authentication URL
  551. within {kib}, so that the {kib} server will not reject these external messages.
  552. If your {kib} instance is behind a proxy, you may also need to add configuration
  553. to tell {kib} how to form its public URL. This is needed because all SAML
  554. messages are exchanged via the user's web browser, so {kib} needs to know what
  555. URLs are used within the browser. In this case, the following settings should be
  556. added to your `kibana.yml` configuration file:
  557. [source, yaml]
  558. ------------------------------------------------------------
  559. xpack.security.public:
  560. protocol: https
  561. hostname: kibana.proxy.com
  562. port: 443
  563. ------------------------------------------------------------
  564. `xpack.security.public.protocol`::
  565. This is the protocol that the user's web browser uses to connect to the proxy.
  566. Must be one of `http` or `https`. It is strongly recommended that you use the
  567. `https` protocol for all access to {kib}.
  568. `xpack.security.public.hostname`::
  569. The fully qualified hostname that your users use to connect to the proxy server.
  570. `xpack.security.public.port`::
  571. The port number that your users use to connect to the proxy server (e.g. `80`
  572. for `http` or `443` for `https`).
  573. These values must be aligned with the URLs used in the {es} configuration for
  574. `sp.acs` and `sp.logout`.
  575. ==== Supporting SAML and basic authentication in {kib}
  576. The SAML support in {kib} is designed on the expectation that it will be the
  577. primary (or sole) authentication method for users of that {kib} instance.
  578. However, it is possible to support both SAML and Basic authentication within a
  579. single {kib} instance by setting `xpack.security.authProviders` as per the
  580. example below:
  581. [source, yaml]
  582. ------------------------------------------------------------
  583. xpack.security.authProviders: [saml, basic]
  584. ------------------------------------------------------------
  585. The order is important - this will _initiate_ SAML authentication for
  586. unauthenticated users, but will _accept_ basic authentication.
  587. If {kib} is configured in this way, then users who wish to login with a
  588. username and password, can do so by directly accessing the `/login` page in
  589. {kib}. This login will not use SAML credentials, and will rely on one of the
  590. other security realms within {es}. Only users who have a username and password
  591. for a configured {es} authentication realm will be able to login via this page.
  592. Alternatively, when the `basic` authentication provider is enabled, you can
  593. place a reverse proxy in front of {kib}, and configure it to send a basic
  594. authentication header (`Authorization: Basic ....`) for each request.
  595. If this header is present and valid, {kib} will not initiate the SAML
  596. authentication process.
  597. ==== Operating multiple {kib} instances
  598. If you wish to have multiple {kib} instances that authenticate against the same
  599. {es} cluster, then each {kib} instance that is configured for SAML authentication,
  600. requires its own SAML realm.
  601. Each SAML realm must have its own unique Entity ID (`sp.entity_id`), and its own
  602. _Assertion Consumer Service_ (`sp.acs`). Each {kib} instance will be mapped to
  603. the correct realm by looking up the matching `sp.acs` value.
  604. These realms may use the same Identity Provider, but are not required to.
  605. The following is example of having 3 difference {kib} instances, 2 of which
  606. use the same internal IdP, and another which uses a different IdP.
  607. [source, yaml]
  608. ------------------------------------------------------------
  609. xpack.security.authc.realms.saml_finance:
  610. type: saml
  611. order: 2
  612. idp.metadata.path: saml/idp-metadata.xml
  613. idp.entity_id: "https://sso.example.com/"
  614. sp.entity_id: "https://kibana.finance.example.com/"
  615. sp.acs: "https://kibana.finance.example.com/api/security/v1/saml"
  616. sp.logout: "https://kibana.finance.example.com/logout"
  617. attributes.principal: "urn:oid:0.9.2342.19200300.100.1.1"
  618. attributes.groups: "urn:oid:1.3.6.1.4.1.5923.1.5.1."
  619. xpack.security.authc.realms.saml_sales:
  620. type: saml
  621. order: 3
  622. idp.metadata.path: saml/idp-metadata.xml
  623. idp.entity_id: "https://sso.example.com/"
  624. sp.entity_id: "https://kibana.sales.example.com/"
  625. sp.acs: "https://kibana.sales.example.com/api/security/v1/saml"
  626. sp.logout: "https://kibana.sales.example.com/logout"
  627. attributes.principal: "urn:oid:0.9.2342.19200300.100.1.1"
  628. attributes.groups: "urn:oid:1.3.6.1.4.1.5923.1.5.1."
  629. xpack.security.authc.realms.saml_eng:
  630. type: saml
  631. order: 4
  632. idp.metadata.path: saml/idp-external.xml
  633. idp.entity_id: "https://engineering.sso.example.net/"
  634. sp.entity_id: "https://kibana.engineering.example.com/"
  635. sp.acs: "https://kibana.engineering.example.com/api/security/v1/saml"
  636. sp.logout: "https://kibana.engineering.example.com/logout"
  637. attributes.principal: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"
  638. ------------------------------------------------------------
  639. It is possible to have one or more {kib} instances that use SAML, while other
  640. instances use basic authentication against another realm type (e.g.
  641. <<native-realm, Native>> or <<ldap-realm, LDAP>>).