Return SPNEGO mutual authentication token - #51560
Open
aw1cks wants to merge 2 commits into
Open
Conversation
Propagate the final GSS response token through Kerberos credential validation and return it on the successful authentication response. Closes keycloak#51559 Signed-off-by: Alex Wicks <alex@awicks.io>
Contributor
There was a problem hiding this comment.
Pull request overview
Propagates final SPNEGO mutual-authentication tokens to successful HTTP responses.
Changes:
- Adds response tokens to authenticated Kerberos validation state.
- Returns tokens through
WWW-Authenticatewithout session persistence. - Adds coverage for standalone and LDAP Kerberos providers.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
AbstractKerberosSingleRealmTest.java |
Tests successful mutual-authentication headers. |
SpnegoAuthenticator.java |
Writes response tokens to HTTP headers. |
LDAPStorageProvider.java |
Propagates LDAP Kerberos response tokens. |
KerberosFederationProvider.java |
Propagates standalone Kerberos response tokens. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Handle optional GSS output tokens and verify that mutual authentication completes without persisting the response token in user sessions. Closes keycloak#51559 Signed-off-by: Alex Wicks <alex@awicks.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #51559
Propagate the final SPNEGO response token when the GSS security context is established and return it in the
WWW-Authenticateheader of the authentication response.Both the standalone Kerberos provider and the LDAP provider now include a generated response token in authenticated credential-validation state.
The browser SPNEGO authenticator extracts that transient protocol state, adds it to the HTTP response, and persists only the remaining credential state as user-session notes.
The GSS output token is optional.
SPNEGOAuthenticatornow handlesnulland empty output tokens without failing authentication or generating a malformed emptyNegotiatechallenge.It continues to use basic Base64 encoding because MIME Base64 can insert CRLF characters and is unsuitable for HTTP header values.
This allows clients that request SPNEGO mutual authentication to validate the Keycloak server and complete the exchange.
This follows RFC 4178 section 3.2, which requires a response mechanism token returned by the acceptor to be included in the SPNEGO response.
RFC 4559 section 4.1 and section 5 carry that final token as
gssapi-datain theWWW-Authenticateheader of the final HTTP response.RFC 4559 illustrates a
200final response rather than Keycloak's authorization-endpoint redirect.Keycloak concludes successful browser authentication with a
302, and RFC 9110 section 11.6.1 permitsWWW-Authenticateon response statuses other than401.The header is attached to the current HTTP response before the authentication flow continues because an authenticator does not own the flow's final JAX-RS response.
Testing
Extended
spnegoMutualAuthenticationTestin the shared Kerberos integration test class.The test runs through both
KerberosStandaloneTestandKerberosLdapTestand verifies that:WWW-Authenticate: Negotiate <token>header.SpnegoResponseTokenis not persisted as a user-session note or exposed through a configured session-note protocol mapper.The header assertion failed against the original implementation because the final token was absent.
Verified with:
Documentation
No documentation changes are required because this corrects the existing SPNEGO protocol behavior and does not introduce configuration or user-facing options.
The observable addition of the final response header is described above for reviewers and release-note generation.
AI disclosure
AI agents were used to help investigate the authentication flow, draft the implementation, and prepare the regression tests.
I reviewed and understand the complete change and am responsible for the submitted code.