saml-guide.asciidoc 39 KB

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