custom-realm.asciidoc 4.3 KB

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