Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 2 failing integration tests in jwt_auth.test.ts in 2.x #1555

Closed
cwperks opened this issue Aug 15, 2023 · 4 comments
Closed

[BUG] 2 failing integration tests in jwt_auth.test.ts in 2.x #1555

cwperks opened this issue Aug 15, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@cwperks
Copy link
Member

cwperks commented Aug 15, 2023

The following tests are failing in 2.x:

FAIL test/jest_integration/jwt_auth.test.ts (42.523 s)
  start OpenSearch Dashboards server
    ✕ Login to app/opensearch_dashboards_overview#/ when JWT is enabled (12187 ms)
    ✕ Login to app/dev_tools#/console when JWT is enabled (11849 ms)

Specifically the tests are failing in these 2 locations:

In each instance it appears that OpenSearch-Dashboards w/ the security-dashboards-plugin is installed, but not ready or that it is taking a long time for the dashboard to be brought up. I have not been able to reproduce the error locally or using act to run the workflow locally.

The tests started failing between these 2 commits in 2.x:

These can be run locally using: yarn test:jest_server -- jwt_auth.test.ts

These failures are blocking PRs like #1550 from being merged to 2.x

@cwperks cwperks added bug Something isn't working untriaged labels Aug 15, 2023
@cwperks
Copy link
Member Author

cwperks commented Aug 15, 2023

@scrawfor99 @RyanL1997 @peternied I filed an issue to capture the errors we are seeing in the integration tests for 2.x

@cwperks cwperks changed the title [BUG] 2 fail integration tests in jwt_auth.test.ts in 2.x [BUG] 2 failing integration tests in jwt_auth.test.ts in 2.x Aug 15, 2023
stephen-crawford pushed a commit to opensearch-project/security that referenced this issue Aug 16, 2023
…#3189)

### Description

After the upgrade of JJWT from
#3092, the JWT
Integration Tests in security-dashboards-plugin started failing. See
details on:
opensearch-project/security-dashboards-plugin#1555

The output from the tests in Github actions was not very revealing, but
@RyanL1997 pointed out that when running the test locally after creating
a local distro of core + security plugin with 2.x it would output a
permissions error:

```
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:485) ~[?:?]
	at java.security.AccessController.checkPermission(AccessController.java:1068) ~[?:?]
	at java.lang.SecurityManager.checkPermission(SecurityManager.java:416) ~[?:?]
	at java.lang.ClassLoader.checkClassLoaderPermission(ClassLoader.java:2060) ~[?:?]
	at java.lang.Thread.getContextClassLoader(Thread.java:1493) ~[?:?]
	at io.jsonwebtoken.impl.lang.Services$1.getClassLoader(Services.java:37) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.impl.lang.Services.loadFirst(Services.java:100) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.impl.DefaultJwtParserBuilder.build(DefaultJwtParserBuilder.java:191) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at com.amazon.dlic.auth.http.jwt.HTTPJwtAuthenticator.<init>(HTTPJwtAuthenticator.java:135) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
        ...
```

This PR surrounds the call to build the parser with
`AccessController.doPrivileged(...)` to ensure the call has the
privileges needed to create the parser.

This change should also be applied to main. For some reason, the tests
are not failing when running on the main branch but are on 2.x.

* Category (Enhancement, New feature, Bug fix, Test fix, Refactoring,
Maintenance, Documentation)

Bug fix

### Issues Resolved


opensearch-project/security-dashboards-plugin#1555

### Check List
- [ ] New functionality includes testing
- [ ] New functionality has been documented
- [ ] Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and
signing off your commits, please check
[here](https://github.com/opensearch-project/OpenSearch/blob/main/CONTRIBUTING.md#developer-certificate-of-origin).

Signed-off-by: Craig Perkins <[email protected]>
@cwperks
Copy link
Member Author

cwperks commented Aug 16, 2023

Full error:

io.jsonwebtoken.lang.InstantiationException: Unable to instantiate class [io.jsonwebtoken.impl.DefaultJwtParser]
	at io.jsonwebtoken.lang.Classes.newInstance(Classes.java:159) ~[jjwt-api-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.lang.Classes.newInstance(Classes.java:137) ~[jjwt-api-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.Jwts.parser(Jwts.java:124) ~[jjwt-api-0.11.5.jar:0.11.5]
	at com.amazon.dlic.auth.http.jwt.HTTPJwtAuthenticator.<init>(HTTPJwtAuthenticator.java:96) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:484) ~[?:?]
	at org.opensearch.security.support.ReflectionHelper.instantiateAAA(ReflectionHelper.java:62) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.securityconf.DynamicConfigModelV7.newInstance(DynamicConfigModelV7.java:406) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.securityconf.DynamicConfigModelV7.buildAAA(DynamicConfigModelV7.java:310) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.securityconf.DynamicConfigModelV7.<init>(DynamicConfigModelV7.java:87) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.securityconf.DynamicConfigFactory.onChange(DynamicConfigFactory.java:283) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.configuration.ConfigurationRepository.notifyAboutChanges(ConfigurationRepository.java:406) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.configuration.ConfigurationRepository.reloadConfiguration0(ConfigurationRepository.java:395) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.configuration.ConfigurationRepository.reloadConfiguration(ConfigurationRepository.java:379) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.configuration.ConfigurationRepository.lambda$new$0(ConfigurationRepository.java:221) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at java.lang.Thread.run(Thread.java:1589) [?:?]
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:485) ~[?:?]
	at java.security.AccessController.checkPermission(AccessController.java:1068) ~[?:?]
	at java.lang.SecurityManager.checkPermission(SecurityManager.java:411) ~[?:?]
	at java.lang.ClassLoader.checkClassLoaderPermission(ClassLoader.java:2070) ~[?:?]
	at java.lang.Thread.getContextClassLoader(Thread.java:2420) ~[?:?]
	at io.jsonwebtoken.impl.lang.Services$1.getClassLoader(Services.java:37) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.impl.lang.Services.loadAll(Services.java:68) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.impl.compression.DefaultCompressionCodecResolver.<init>(DefaultCompressionCodecResolver.java:57) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.impl.DefaultJwtParser.<init>(DefaultJwtParser.java:51) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
	at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) ~[?:?]
	at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:306) ~[?:?]
	at java.lang.Class.newInstance(Class.java:684) ~[?:?]
	at io.jsonwebtoken.lang.Classes.newInstance(Classes.java:157) ~[jjwt-api-0.11.5.jar:0.11.5]
	... 16 more
[2023-08-16T12:07:23,908][WARN ][o.o.s.s.ReflectionHelper ] [smoketestnode] Unable to enable 'com.amazon.dlic.auth.http.jwt.HTTPJwtAuthenticator' due to java.lang.reflect.InvocationTargetException
[2023-08-16T12:07:23,912][ERROR][o.o.s.s.DynamicConfigModelV7] [smoketestnode] Unable to initialize auth domain jwt_auth_domain=AuthcDomain [http_enabled=true, transport_enabled=false, order=5, http_authenticator=HttpAuthenticator [challenge=true, type=jwt, config={signing_key=VGhpcyBpcyBhIHZlcnkgc2VjdXJlIHNlY3JldC4gTm8gb25lIHdpbGwgZXZlciBiZSBhYmxlIHRvIGd1ZXNzIGl0IQ==, jwt_header=Authorization, jwt_url_parameter=token, roles_key=roles, subject_key=sub}], authentication_backend=AuthcBackend [type=noop, config={}], description=Authenticate via Json Web Token] due to OpenSearchException[java.lang.reflect.InvocationTargetException]; nested: InvocationTargetException; nested: RuntimeException[io.jsonwebtoken.lang.InstantiationException: Unable to instantiate class [io.jsonwebtoken.impl.DefaultJwtParser]]; nested: InstantiationException[Unable to instantiate class [io.jsonwebtoken.impl.DefaultJwtParser]]; nested: AccessControlException[access denied ("java.lang.RuntimePermission" "getClassLoader")];
org.opensearch.OpenSearchException: java.lang.reflect.InvocationTargetException
	at org.opensearch.security.support.ReflectionHelper.instantiateAAA(ReflectionHelper.java:73) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.securityconf.DynamicConfigModelV7.newInstance(DynamicConfigModelV7.java:406) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.securityconf.DynamicConfigModelV7.buildAAA(DynamicConfigModelV7.java:310) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.securityconf.DynamicConfigModelV7.<init>(DynamicConfigModelV7.java:87) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.securityconf.DynamicConfigFactory.onChange(DynamicConfigFactory.java:283) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.configuration.ConfigurationRepository.notifyAboutChanges(ConfigurationRepository.java:406) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.configuration.ConfigurationRepository.reloadConfiguration0(ConfigurationRepository.java:395) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.configuration.ConfigurationRepository.reloadConfiguration(ConfigurationRepository.java:379) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at org.opensearch.security.configuration.ConfigurationRepository.lambda$new$0(ConfigurationRepository.java:221) [opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at java.lang.Thread.run(Thread.java:1589) [?:?]
Caused by: java.lang.reflect.InvocationTargetException
	at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:79) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:484) ~[?:?]
	at org.opensearch.security.support.ReflectionHelper.instantiateAAA(ReflectionHelper.java:62) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	... 9 more
Caused by: java.lang.RuntimeException: io.jsonwebtoken.lang.InstantiationException: Unable to instantiate class [io.jsonwebtoken.impl.DefaultJwtParser]
	at com.amazon.dlic.auth.http.jwt.HTTPJwtAuthenticator.<init>(HTTPJwtAuthenticator.java:102) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:484) ~[?:?]
	at org.opensearch.security.support.ReflectionHelper.instantiateAAA(ReflectionHelper.java:62) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	... 9 more
Caused by: io.jsonwebtoken.lang.InstantiationException: Unable to instantiate class [io.jsonwebtoken.impl.DefaultJwtParser]
	at io.jsonwebtoken.lang.Classes.newInstance(Classes.java:159) ~[jjwt-api-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.lang.Classes.newInstance(Classes.java:137) ~[jjwt-api-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.Jwts.parser(Jwts.java:124) ~[jjwt-api-0.11.5.jar:0.11.5]
	at com.amazon.dlic.auth.http.jwt.HTTPJwtAuthenticator.<init>(HTTPJwtAuthenticator.java:96) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:484) ~[?:?]
	at org.opensearch.security.support.ReflectionHelper.instantiateAAA(ReflectionHelper.java:62) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	... 9 more
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:485) ~[?:?]
	at java.security.AccessController.checkPermission(AccessController.java:1068) ~[?:?]
	at java.lang.SecurityManager.checkPermission(SecurityManager.java:411) ~[?:?]
	at java.lang.ClassLoader.checkClassLoaderPermission(ClassLoader.java:2070) ~[?:?]
	at java.lang.Thread.getContextClassLoader(Thread.java:2420) ~[?:?]
	at io.jsonwebtoken.impl.lang.Services$1.getClassLoader(Services.java:37) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.impl.lang.Services.loadAll(Services.java:68) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.impl.compression.DefaultCompressionCodecResolver.<init>(DefaultCompressionCodecResolver.java:57) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.impl.DefaultJwtParser.<init>(DefaultJwtParser.java:51) ~[jjwt-impl-0.11.5.jar:0.11.5]
	at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
	at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) ~[?:?]
	at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:306) ~[?:?]
	at java.lang.Class.newInstance(Class.java:684) ~[?:?]
	at io.jsonwebtoken.lang.Classes.newInstance(Classes.java:157) ~[jjwt-api-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.lang.Classes.newInstance(Classes.java:137) ~[jjwt-api-0.11.5.jar:0.11.5]
	at io.jsonwebtoken.Jwts.parser(Jwts.java:124) ~[jjwt-api-0.11.5.jar:0.11.5]
	at com.amazon.dlic.auth.http.jwt.HTTPJwtAuthenticator.<init>(HTTPJwtAuthenticator.java:96) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:484) ~[?:?]
	at org.opensearch.security.support.ReflectionHelper.instantiateAAA(ReflectionHelper.java:62) ~[opensearch-security-2.10.0.0-SNAPSHOT.jar:2.10.0.0-SNAPSHOT]
	... 9 more

@stephen-crawford
Copy link
Contributor

stephen-crawford commented Aug 21, 2023

[Triage] Thank you for filing this issue @cwperks. Leaving this without the triaged label since this requires further action to determine what the desired outcome should be.

@cwperks
Copy link
Member Author

cwperks commented Aug 23, 2023

Closing this issue as it is now solved. The fix was targeted to 2.x and not necessary in main because all HTTP Authenticators are instantiated in a privileged block in main. See details here: opensearch-project/security#3213 (comment)

@cwperks cwperks closed this as completed Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants