I’m preparing an internal proof-of-concept for a custom authentication backend for Search Guard to integrate with our own credentials source. This would be one of our prerequisites for justifying purchase of an Enterprise licence.
I’ve read Custom implementations | Security for Elasticsearch | Search Guard and the linked Javadoc, and the source, and I have a project which is working as far as its own unit tests, but fails to initialize when configured in sg_config.yml. My authentication module is built as a Maven artifact with dependencies extracted to the output “fat jar” and dropped into the search-guard-6 directory next to the plugin jars. I had a bit of a fight with “Jar Hell” but it’s getting past that now.
At initialization it’s throwing what a SecurityManager AccessControlException while trying to load JPA/Hibernate (4.3.11). I’ve seen that Elasticsearch builds its own Policy but this failure seems odd as the getClassLoader permission is already included in the Search Guard plugin security policy.
I’ve tried wrapping the createEntityManagerFactory call with the AccessController.doPrivileged pattern but that actually fails earlier in the call chain - probably the wrong approach.
I’ve tried running with -Djava.security.debug=access,failure but it provides no further insights.
Is there something else which needs adding to the plugin policy to allow this class loading process? Is there any way that a drop-in backend module can augment the policy or are we stuck with a manual edit? (if so, would it be better to package it as a separate Elasticsearch plugin?)
-
Elasticsearch 6.2.2; Search Guard 22.1 (Kibana plugin v13)
-
Using built-in enterprise modules only
-
JVM 1.8.0_161 on Windows 7 Pro SP1
-
Search Guard configuration files (some names changed to obscure IP details):
searchguard:
dynamic:
…
authc:
my-auth:
enabled: true
http_enabled: true
transport_enabled: false
order: 5
http_authenticator:
type: “basic”
challenge: false
authentication_backend:
type: “com.example.es.sg.auth.MyAuthenticationBackend”
config: …
``
- Elasticsearch log messages
[2018-06-13T13:38:37,259][DEBUG][c.f.s.c.IndexBaseConfigurationRepository] Notify com.floragunn.searchguard.auth.BackendRegistry@525b8922 listener about change configuration with type config
[2018-06-13T13:38:37,269][DEBUG][c.f.s.s.ReflectionHelper ] Loaded module Module [type=INTERNAL_USERS_AUTHENTICATION_BACKEND, implementing class=com.floragunn.searchguard.auth.internal.InternalAuthenticationBackend]
[2018-06-13T13:38:37,273][DEBUG][c.f.s.s.ReflectionHelper ] Loaded module Module [type=HTTP_BASIC_AUTHENTICATOR, implementing class=com.floragunn.searchguard.http.HTTPBasicAuthenticator]
[2018-06-13T13:38:37,274][ERROR][c.f.s.a.BackendRegistry ] Not yet initialized (you may need to run sgadmin)
[2018-06-13T13:38:37,285][INFO ][c.e.e.s.a.MyAuthenticationBackend] Starting up authentication backend: { /* settings from elasticsearch.yml and sg_config.yml section */}, C:\dev\elastic\6.2.2\elasticsearch-6.2.2\config
[2018-06-13T13:38:37,304][WARN ][c.f.s.s.ReflectionHelper ] Unable to enable ‘com.example.es.sg.auth.MyAuthenticationBackend’ due to java.lang.reflect.InvocationTargetException
[2018-06-13T13:38:37,306][ERROR][c.f.s.a.BackendRegistry ] Unable to initialize auth domain my-auth due to ElasticsearchException[java.lang.reflect.InvocationTargetException]; nested: InvocationTargetException; nested: AccessControlException[access denied (“java.lang.RuntimePermission” “getClassLoader”)];
org.elasticsearch.ElasticsearchException: java.lang.reflect.InvocationTargetException
at com.floragunn.searchguard.support.ReflectionHelper.instantiateAAA(ReflectionHelper.java:184) ~[search-guard-6-6.2.2-22.1.jar:6.2.2-22.1]
at com.floragunn.searchguard.auth.BackendRegistry.newInstance(BackendRegistry.java:668) ~[search-guard-6-6.2.2-22.1.jar:6.2.2-22.1]
at com.floragunn.searchguard.auth.BackendRegistry.onChange(BackendRegistry.java:230) [search-guard-6-6.2.2-22.1.jar:6.2.2-22.1]
at com.floragunn.searchguard.configuration.IndexBaseConfigurationRepository.notifyAboutChanges(IndexBaseConfigurationRepository.java:361) [search-guard-6-6.2.2-22.1.jar:6.2.2-22.1]
at com.floragunn.searchguard.configuration.IndexBaseConfigurationRepository.reloadConfiguration(IndexBaseConfigurationRepository.java:311) [search-guard-6-6.2.2-22.1.jar:6.2.2-22.1]
at com.floragunn.searchguard.configuration.IndexBaseConfigurationRepository$1$1.run(IndexBaseConfigurationRepository.java:171) [search-guard-6-6.2.2-22.1.jar:6.2.2-22.1]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_161]
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_161]
at com.floragunn.searchguard.support.ReflectionHelper.instantiateAAA(ReflectionHelper.java:176) ~[?:?]
… 6 more
Caused by: java.security.AccessControlException: access denied (“java.lang.RuntimePermission” “getClassLoader”)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) ~[?:1.8.0_161]
at java.security.AccessController.checkPermission(AccessController.java:884) ~[?:1.8.0_161]
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) ~[?:1.8.0_161]
at java.lang.ClassLoader.checkClassLoaderPermission(ClassLoader.java:1528) ~[?:1.8.0_161]
at java.lang.Thread.getContextClassLoader(Thread.java:1443) ~[?:1.8.0_161]
at javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader.getContextualClassLoader(PersistenceProviderResolverHolder.java:101) ~[?:?]
at javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader.getPersistenceProviders(PersistenceProviderResolverHolder.java:76) ~[?:?]
at javax.persistence.Persistence.getProviders(Persistence.java:69) ~[?:?]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:53) ~[?:?]
at com.example.es.sg.auth.db.Database.(Database.java:21) ~[?:?]
at com.example.es.sg.auth.MyAuthenticationBackend.(MyAuthenticationBackend.java:66) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_161]
at com.floragunn.searchguard.support.ReflectionHelper.instantiateAAA(ReflectionHelper.java:176) ~[?:?]
… 6 more
[2018-06-13T13:38:37,356][INFO ][c.f.s.c.IndexBaseConfigurationRepository] Search Guard License Info: …
``
Thanks,
James