custom-realm.asciidoc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. [role="xpack"]
  2. [[custom-realms]]
  3. === Integrating with other authentication systems
  4. If you are using an authentication system that is not supported out-of-the-box
  5. by the {es} {security-features}, you can create a custom realm to interact with
  6. it to authenticate users. You implement a custom realm as an SPI loaded security
  7. extension as part of an ordinary elasticsearch plugin.
  8. [[implementing-custom-realm]]
  9. ==== Implementing a custom realm
  10. Sample code that illustrates the structure and implementation of a custom realm
  11. is provided in https://github.com/elastic/elasticsearch/tree/{branch}/x-pack/qa/security-example-spi-extension. You can use this code as a starting point for creating your
  12. own realm.
  13. To create a custom realm, you need to:
  14. . Extend `org.elasticsearch.xpack.security.authc.Realm` to communicate with your
  15. authentication system to authenticate users.
  16. . Implement the `org.elasticsearch.xpack.security.authc.Realm.Factory` interface in
  17. a class that will be used to create the custom realm.
  18. . Extend `org.elasticsearch.xpack.security.authc.DefaultAuthenticationFailureHandler` to
  19. handle authentication failures when using your custom realm.
  20. To package your custom realm as a plugin:
  21. . Implement an extension class for your realm that extends
  22. `org.elasticsearch.xpack.core.security.SecurityExtension`. There you need to
  23. override one or more of the following methods:
  24. +
  25. [source,java]
  26. ----------------------------------------------------
  27. @Override
  28. public Map<String, Factory> getRealms() {
  29. ...
  30. }
  31. ----------------------------------------------------
  32. +
  33. The `getRealms` method is used to provide a map of type names to the `Factory` that
  34. will be used to create the realm.
  35. +
  36. [source,java]
  37. ----------------------------------------------------
  38. @Override
  39. public AuthenticationFailureHandler getAuthenticationFailureHandler() {
  40. ...
  41. }
  42. ----------------------------------------------------
  43. +
  44. The `getAuthenticationFailureHandler` method is used to optionally provide a
  45. custom `AuthenticationFailureHandler`, which will control how the
  46. {es} {security-features} respond in certain authentication failure events.
  47. +
  48. [source,java]
  49. ----------------------------------------------------
  50. @Override
  51. public List<String> getSettingsFilter() {
  52. ...
  53. }
  54. ----------------------------------------------------
  55. +
  56. The `Plugin#getSettingsFilter` method returns a list of setting names that should be
  57. filtered from the settings APIs as they may contain sensitive credentials. Note this method is not
  58. part of the `SecurityExtension` interface, it's available as part of the elasticsearch plugin main class.
  59. . Create a build configuration file for the plugin; Gradle is our recommendation.
  60. . Create a `META-INF/services/org.elasticsearch.xpack.core.security.SecurityExtension` descriptor file for the
  61. extension that contains the fully qualified class name of your `org.elasticsearch.xpack.core.security.SecurityExtension` implementation
  62. . Bundle all in a single zip file.
  63. [[using-custom-realm]]
  64. ==== Using a custom realm to authenticate users
  65. To use a custom realm:
  66. . Install the realm extension on each node in the cluster. You run
  67. `bin/elasticsearch-plugin` with the `install` sub-command and specify the URL
  68. pointing to the zip file that contains the extension. For example:
  69. +
  70. [source,shell]
  71. ----------------------------------------
  72. bin/elasticsearch-plugin install file:///<path>/my-realm-1.0.zip
  73. ----------------------------------------
  74. . Add a realm configuration of the appropriate realm type to `elasticsearch.yml`
  75. under the `xpack.security.authc.realms` namespace.
  76. You must define your realm within the namespace that matches the type defined
  77. by the extension.
  78. The options you can set depend on the settings exposed by the custom realm.
  79. At a minimum, you must explicitly set the `order` attribute to control the
  80. order in which the realms are consulted during authentication. You must also
  81. make sure each configured realm has a distinct `order` setting. In the event
  82. that two or more realms have the same `order`, the node will fail to start.
  83. +
  84. IMPORTANT: When you configure realms in `elasticsearch.yml`, only the
  85. realms you specify are used for authentication. If you also want to use the
  86. `native` or `file` realms, you must include them in the realm chain.
  87. . Restart Elasticsearch.