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

JWT realm support for HTTPS URL in PKC JWKSet setting #84630

Conversation

justincr-elastic
Copy link
Contributor

Add HTTPS server to JWT issuer.

JwtRealmTestCase.createJwtIssuer() decides if public PKC JWKSet should be made available via local file or HTTPS server. If HTTPS, it passes settings to JwtIssuer to initialize a HTTPS server, and JwtIssuer.close() can be used to clean up the HTTPS server thread pool.

JwtRealmTestCase.createJwtRealm() checks if JwtIssuer has a HTTPS server. If yes, it uses the URL computed by the JwtIssuer server. If no, it puts the JWKSet in a temp file and points its config to it.

@justincr-elastic justincr-elastic added :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) >feature Team:Security Meta label for security team labels Mar 3, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@justincr-elastic justincr-elastic requested a review from ywangd March 3, 2022 16:28
@elasticsearchmachine
Copy link
Collaborator

Hi @justincr-elastic, I've created a changelog YAML for you.

@justincr-elastic justincr-elastic marked this pull request as draft March 3, 2022 16:29
@justincr-elastic justincr-elastic marked this pull request as ready for review March 3, 2022 22:43
@justincr-elastic justincr-elastic changed the title Test JWT realm with HTTPS URL for PKC JWKSet JWT realm support for HTTPS URL in PKC JWKSet setting Mar 3, 2022
@justincr-elastic justincr-elastic marked this pull request as draft March 3, 2022 22:56
@justincr-elastic
Copy link
Contributor Author

#68967 talks about how we use HttpsServer for tests.

@justincr-elastic
Copy link
Contributor Author

@elasticmachine update branch

@elasticmachine
Copy link
Collaborator

merge conflict between base and head

@justincr-elastic justincr-elastic requested a review from tvernum March 7, 2022 22:24
@justincr-elastic justincr-elastic marked this pull request as ready for review March 7, 2022 23:05
Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

I left a few comments, also:

  • I don't think the PR should be labelled as feature because it really is about tests
  • There are some complexities in how JwtIssuer, JwtIssuerHttpsServer is created and managed. They work as is, but I'd personally prefer having them managed more transparently by the base JwtTestCase. That said, these are all just test code and I don't have too strong opinions.

Comment on lines +134 to +137
} catch (Throwable t) {
this.close();
throw t;
}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this belong to test code? e.g. invoke jwtRealm.close() in a @After method in test class?

Copy link
Member

Choose a reason for hiding this comment

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

Answer my own question here. I think this is added to production code because the instantiation may fail in tests and there will no instance of jwtRealm to call close upon. Generally I don't like change production code for tests. But this seems to be minor enough and the behaviour is retrow anyway.

Comment on lines +239 to +241
final Registry<SchemeIOSessionStrategy> registry = RegistryBuilder.<SchemeIOSessionStrategy>create()
.register("https", new SSLIOSessionStrategy(clientContext, verifier))
.build();
Copy link
Member

Choose a reason for hiding this comment

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

Just for my own knowledge: we have decided to not support plain http in fetching JWKs?

@justincr-elastic justincr-elastic added >test Issues or PRs that are addressing/adding tests and removed >feature labels Mar 8, 2022
@justincr-elastic
Copy link
Contributor Author

@elasticmachine update branch

@justincr-elastic
Copy link
Contributor Author

@elasticmachine update branch

@justincr-elastic justincr-elastic requested a review from ywangd March 9, 2022 15:09
@justincr-elastic
Copy link
Contributor Author

I am proposing to leave MockHttpServer in this PR.

  • MockHttpServer is sufficient for HTTPS URL loading of PKC JWKSet at startup.
  • MockWebServer is only required for HTTPS URL reloading of PKC JWKSet at runtime.

I will add a task to track switching to MockWebServer later, which will be tried to PKC JWKSet reloading at runtime.

Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM

@justincr-elastic justincr-elastic merged commit 0c39078 into elastic:master Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) Team:Security Meta label for security team >test Issues or PRs that are addressing/adding tests v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants