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

fix(auth): clean up auth exception handling #1104

Merged
merged 6 commits into from
Oct 6, 2022

Conversation

andrewazores
Copy link
Member

Fixes #1102

@andrewazores andrewazores marked this pull request as ready for review October 6, 2022 21:30
@andrewazores
Copy link
Member Author

Wait a minute, looks like I broke something just before pushing. Whoops. Checking.

@andrewazores
Copy link
Member Author

Or not... ? bash repeated-integration-tests.bash 1 JmxAuthIT works. Something else must have caused the CI failure.

@andrewazores
Copy link
Member Author

https://github.com/cryostatio/cryostat/actions/runs/3200604186/jobs/5227713966

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running itest.RulesPostJsonIT
HTTP 415: Unsupported Media Type
HTTP 409: Conflict
HTTP 400: Bad Request
HTTP 415: Unsupported Media Type
HTTP 400: Bad Request
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.588 s - in itest.RulesPostJsonIT
[INFO] Running itest.TargetReportIT
HTTP 404: Not Found
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.518 s - in itest.TargetReportIT
[INFO] Running itest.TargetRecordingsClientErrorIT
HTTP 400: Bad Request
HTTP 400: Bad Request
HTTP 404: Not Found
HTTP 400: Bad Request
HTTP 400: Bad Request
HTTP 404: Not Found
HTTP 400: Bad Request
HTTP 400: Bad Request
HTTP 400: Bad Request
HTTP 404: Not Found
HTTP 400: Bad Request
HTTP 400: Bad Request
HTTP 400: Bad Request
HTTP 404: Not Found
HTTP 400: Bad Request
[INFO] Tests run: 15, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.275 s - in itest.TargetRecordingsClientErrorIT
[INFO] Running itest.JmxAuthIT
[podman, run, --quiet, --pod=cryostat-itests, --detach, --rm, --env, USE_AUTH=true, --env, JMX_PORT=9093, quay.io/andrewazores/vertx-fib-demo:0.8.0]
089c8fef15e4dc820a96486a094501b145d68359e27255435a20f64e8adae0ad
[podman, kill, 089c8fef15e4dc820a96486a094501b145d68359e27255435a20f64e8adae0ad]
089c8fef15e4dc820a96486a094501b145d68359e27255435a20f64e8adae0ad
expected target count (1) observed, counting success 1/3
expected target count (1) observed, counting success 2/3
expected target count (1) observed, counting success 3/3
discovery complete
discovery completed in 15024ms
Error:  Tests run: 8, Failures: 8, Errors: 0, Skipped: 0, Time elapsed: 20.038 s <<< FAILURE! - in itest.JmxAuthIT
Error:  checkStatusForTemplatesQueryWithCredentials  Time elapsed: 0.081 s  <<< FAILURE!
java.lang.AssertionError: 

Expected: (a value equal to or greater than <200> and a value less than <300>)
     but: a value less than <300> <500> was greater than <300>
	at itest.JmxAuthIT.checkStatusForTemplatesQueryWithCredentials(JmxAuthIT.java:118)

Error:  checkStatusForTemplatesQueryWithoutCredentials  Time elapsed: 0.033 s  <<< FAILURE!
java.lang.AssertionError: 

Expected: <427>
     but: was <500>
	at itest.JmxAuthIT.checkStatusForTemplatesQueryWithoutCredentials(JmxAuthIT.java:127)

Error:  checkStatusForV1EventsQueryWithoutCredentials  Time elapsed: 0.039 s  <<< FAILURE!
java.lang.AssertionError: 

Expected: <427>
     but: was <500>
	at itest.JmxAuthIT.checkStatusForV1EventsQueryWithoutCredentials(JmxAuthIT.java:146)

Error:  checkStatusForV2EventsQueryWithoutCredentials  Time elapsed: 0.024 s  <<< FAILURE!
java.lang.AssertionError: 

Expected: <427>
     but: was <500>
	at itest.JmxAuthIT.checkStatusForV2EventsQueryWithoutCredentials(JmxAuthIT.java:165)

Error:  checkStatusForV1EventsQueryWithCredentials  Time elapsed: 0.022 s  <<< FAILURE!
java.lang.AssertionError: 

Expected: (a value equal to or greater than <200> and a value less than <300>)
     but: a value less than <300> <500> was greater than <300>
	at itest.JmxAuthIT.checkStatusForV1EventsQueryWithCredentials(JmxAuthIT.java:137)

Error:  checkStatusForRecordingsQueryWithCredentials  Time elapsed: 0.032 s  <<< FAILURE!
java.lang.AssertionError: 

Expected: (a value equal to or greater than <200> and a value less than <300>)
     but: a value less than <300> <500> was greater than <300>
	at itest.JmxAuthIT.checkStatusForRecordingsQueryWithCredentials(JmxAuthIT.java:99)

Error:  checkStatusForV2EventsQueryWithCredentials  Time elapsed: 0.015 s  <<< FAILURE!
java.lang.AssertionError: 

Expected: (a value equal to or greater than <200> and a value less than <300>)
     but: a value less than <300> <500> was greater than <300>
	at itest.JmxAuthIT.checkStatusForV2EventsQueryWithCredentials(JmxAuthIT.java:156)

Error:  checkStatusForRecordingsQueryWithoutCredentials  Time elapsed: 0.03 s  <<< FAILURE!
java.lang.AssertionError: 

Expected: <427>
     but: was <500>
	at itest.JmxAuthIT.checkStatusForRecordingsQueryWithoutCredentials(JmxAuthIT.java:108)

and the server-side logs:

INFO: Creating connection for service:jmx:rmi:///jndi/rmi://cryostat-itests:9093/jmxrmi
Oct 06, 2022 9:38:55 PM io.cryostat.core.log.Logger info
INFO: connection attempt failed.

Oct 06, 2022 9:38:55 PM io.cryostat.core.log.Logger info
INFO: Connection for service:jmx:rmi:///jndi/rmi://cryostat-itests:9093/jmxrmi closed
Oct 06, 2022 9:38:55 PM io.cryostat.core.log.Logger error
SEVERE: HTTP 500: Could not get template models
io.vertx.ext.web.handler.HttpException: Internal Server Error
Caused by: io.cryostat.core.FlightRecorderException: Could not get template models
	at io.cryostat.core.templates.RemoteTemplateService.getTemplateModels(RemoteTemplateService.java:163)
	at io.cryostat.core.templates.AbstractTemplateService.getTemplates(AbstractTemplateService.java:53)
	at io.cryostat.core.templates.RemoteTemplateService.getTemplates(RemoteTemplateService.java:64)
	at io.cryostat.core.templates.MergedTemplateService.getTemplates(MergedTemplateService.java:69)
	at io.cryostat.net.web.http.api.v1.TargetTemplatesGetHandler.lambda$handleAuthenticated$0(TargetTemplatesGetHandler.java:126)
	at io.cryostat.net.TargetConnectionManager.executeConnectedTask(TargetConnectionManager.java:163)
	at io.cryostat.net.web.http.api.v1.TargetTemplatesGetHandler.handleAuthenticated(TargetTemplatesGetHandler.java:122)
	at io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler.handle(AbstractAuthenticatedRequestHandler.java:100)
	at io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler.handle(AbstractAuthenticatedRequestHandler.java:70)
	at io.vertx.ext.web.impl.BlockingHandlerDecorator.lambda$handle$0(BlockingHandlerDecorator.java:48)
	at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:159)
	at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
	at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:157)
	at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.openjdk.jmc.rjmx.ConnectionException caused by java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: cryostat-itests; nested exception is: 
	java.net.ConnectException: Connection refused]
            plugininfo0_.callback as callback2_0_,
            plugininfo0_.realm as realm3_0_,
            plugininfo0_.subtree as subtree4_0_ 
        from
            PluginInfo plugininfo0_
Oct 06, 2022 9:38:55 PM io.cryostat.core.log.Logger info
INFO: Creating connection for service:jmx:rmi:///jndi/rmi://cryostat-itests:9093/jmxrmi
Oct 06, 2022 9:38:55 PM io.cryostat.core.log.Logger info
INFO: connection attempt failed.

Oct 06, 2022 9:38:55 PM io.cryostat.core.log.Logger info
INFO: Connection for service:jmx:rmi:///jndi/rmi://cryostat-itests:9093/jmxrmi closed
Oct 06, 2022 9:38:55 PM io.cryostat.core.log.Logger error
SEVERE: HTTP 500: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: cryostat-itests; nested exception is: 
	java.net.ConnectException: Connection refused]
io.vertx.ext.web.handler.HttpException: Internal Server Error
Caused by: org.openjdk.jmc.rjmx.ConnectionException caused by java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: cryostat-itests; nested exception is: 
	java.net.ConnectException: Connection refused]
	at org.openjdk.jmc.rjmx.internal.RJMXConnection.connect(RJMXConnection.java:441)
	at io.cryostat.core.net.JFRConnection.attemptConnect(JFRConnection.java:300)
	at io.cryostat.core.net.JFRConnection.connect(JFRConnection.java:257)
	at io.cryostat.core.net.JFRConnection.getService(JFRConnection.java:120)
	at io.cryostat.net.web.http.api.v1.TargetRecordingsGetHandler.lambda$handleAuthenticated$0(TargetRecordingsGetHandler.java:128)
	at io.cryostat.net.TargetConnectionManager.executeConnectedTask(TargetConnectionManager.java:163)
	at io.cryostat.net.web.http.api.v1.TargetRecordingsGetHandler.handleAuthenticated(TargetRecordingsGetHandler.java:124)
	at io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler.handle(AbstractAuthenticatedRequestHandler.java:100)
	at io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler.handle(AbstractAuthenticatedRequestHandler.java:70)
	at io.vertx.ext.web.impl.BlockingHandlerDecorator.lambda$handle$0(BlockingHandlerDecorator.java:48)
	at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:159)
	at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
	at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:157)
	at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: cryostat-itests; nested exception is: 
	java.net.ConnectException: Connection refused]
	at java.management.rmi/javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:370)
	at org.openjdk.jmc.rjmx.internal.RJMXConnection.connectJmxConnector(RJMXConnection.java:487)
	at org.openjdk.jmc.rjmx.internal.RJMXConnection.establishConnection(RJMXConnection.java:464)
	at org.openjdk.jmc.rjmx.internal.RJMXConnection.connect(RJMXConnection.java:434)
	... 17 more
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: cryostat-itests; nested exception is: 
	java.net.ConnectException: Connection refused]
	at jdk.naming.rmi/com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:138)
	at java.naming/com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:220)
	at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409)
	at java.management.rmi/javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1839)
	at java.management.rmi/javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1813)
	at java.management.rmi/javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:302)
	... 20 more
Caused by: java.rmi.ConnectException: Connection refused to host: cryostat-itests; nested exception is: 
	java.net.ConnectException: Connection refused
	at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:626)
	at java.rmi/sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:217)
	at java.rmi/sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:204)
	at java.rmi/sun.rmi.server.UnicastRef.newCall(UnicastRef.java:344)
	at java.rmi/sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:116)
	at jdk.naming.rmi/com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:134)
	... 25 more
Caused by: java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.connect0(Native Method)
	at java.base/sun.nio.ch.Net.connect(Net.java:579)
	at java.base/sun.nio.ch.Net.connect(Net.java:568)
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
	at java.base/java.net.Socket.connect(Socket.java:633)
	at java.base/java.net.Socket.connect(Socket.java:583)
	at java.base/java.net.Socket.<init>(Socket.java:507)
	at java.base/java.net.Socket.<init>(Socket.java:287)
	at java.rmi/sun.rmi.transport.tcp.TCPDirectSocketFactory.createSocket(TCPDirectSocketFactory.java:40)
	at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:620)
	... 30 more
Oct 06, 2022 9:38:55 PM io.cryostat.core.log.Logger info
INFO: (10.0.2.100:59582): GET /api/v1/targets/service:jmx:rmi:%2F%2F%2Fjndi%2Frmi:%2F%2Fcryostat-itests:9093%2Fjmxrmi/recordings 500 13ms
Oct 06, 2022 9:38:55 PM io.cryostat.core.log.Logger info
INFO: Removing cached connection for service:jmx:rmi:///jndi/rmi://cryostat-itests:9093/jmxrmi: EXPLICIT

So it looks like the test container came up in JDP, but Cryostat wasn't able to connect to it afterward. Not sure why that happened.

And this class of failure should probably be a 404 or something, not 500.

Copy link
Member

@tthvo tthvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Solved the front-end issue when testing. I think maybe a test expected status code needs changing following this updates ?

Error:  Failures: 
Error:    WrongServiceListeningOnPortIT.testConnectionFailsAsExpected:112 
Expected: <500>
     but: was <502>

maxcao13
maxcao13 previously approved these changes Oct 6, 2022
Copy link
Member

@maxcao13 maxcao13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as well, I will use the AbstractAuthenticatedRequestHandler connection exception handling in my issue :-)

@andrewazores
Copy link
Member Author

Okay, I think this is actually settled this time.

Copy link
Member

@tthvo tthvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! Thanks for fixing this :D

@andrewazores andrewazores merged commit d33bc0a into cryostatio:main Oct 6, 2022
@andrewazores andrewazores deleted the auth-exception-handling branch October 6, 2022 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Task] Requests for target-specific templates return 500 instead of expected 427 on JMX credentials failure
3 participants