Repository navigation
fix: adds more validation of proxy-headers - #38092
Conversation
16c2619 to
7a3000c
Compare
7a3000c to
73e037f
Compare
73e037f to
b35cd9d
Compare
There was a problem hiding this comment.
@shawkins Thanks for the update.
Just to summarize offline discussion we had. The validation should fail if (pseudo code):
!tlsConfigured && proxyHeaders == null && (!hostname.startsWith("https://") || hostname.isLocalContext())
The validation should be just a warning not to be breaking change (for some folks even the misconfigured scenario might sort of work).
We should also document that Admin Console loads only in secure context, incl. what secure context mean (TLS from the browser's perspective, or localhost).
|
I'll circle back to this after #38536 is merged because it touches the same logic. |
6b59793 to
3c9a744
Compare
71b8296 to
b996b7f
Compare
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.adapter.servlet.SAMLClockSkewAdapterTest#testTokenTimeIsValid |
There was a problem hiding this comment.
In general looks good.
Could you please also update the docs to incorporate some notes around these new validations?
There was a problem hiding this comment.
Why // else warn on prod? The warning si already there, no?
There was a problem hiding this comment.
The else case here is something like hostname=http://localhost - doesn't seem like that would be used in production, but I wasn't sure if it warrented a warning.
Yes, once we have a handle on all the cases / verbiage, I'll update the docs. |
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.cluster.ClientInvalidationClusterTest#crudWithFailover |
There was a problem hiding this comment.
IMHO it is good enough for now, it's a good start and we'll see if that helps the users.
Added some minor comments, mostly typos.
I think we can update the docs and we're ready for merge. It'd be good to get it to 26.2.
ce98e1b to
b9af8b2
Compare
|
Finally circling back to this. It now incorporates the config warnings into the hostname-debug output along with a more precise test of misconfiguration of the frontend URL. There are two ways that could be done - either do it under the main hostname-debug endpoint logic, or the endpoint test logic. I opted for the latter. The only thing I'd like to additionally check for is if tls passthrough is being used and proxy headers have been set - but this will take a bit more logic to determine. Does it seem worth it? cc @vmuzikar |
|
@vmuzikar reviewed again for consistency across the docs, startup warnings, and hostname-debug page. The only thing that needed adjusted was recommending that someone use a full url hostname when behind a proxy as a remedy for failing CORs checks. As far as I can tell, this does not work. In LoginStatusIframeEndpoint logic So the only time you can get away with setting the full hostname url, but not the proxy-headers, is when you are not behind a proxy. |
There was a problem hiding this comment.
Should already be up-to-date.
Right, I missed it, thanks.
There was a problem hiding this comment.
Should we check for other X-Forwarded-* headers too, or at least change it to X-Forwarded-Host as it's most relevant for this case?
There was a problem hiding this comment.
I was just effectively reusing the check that we're doing in the WelcomeResource - do you want to consolidate those and switch to X-Forwarded-Host instead?
There was a problem hiding this comment.
do you want to consolidate those and switch to X-Forwarded-Host instead?
That'd probably make sense.
There was a problem hiding this comment.
But it's not a blocker, approving regardless, feel free to merge.
There was a problem hiding this comment.
Refined to use the headers we have defined in the constants.
It could be the issue here is some inconsistency or missing guidance over the HOST header. The full hostname URL could work without proxy-headers when using re-encrypt - as long as the proxy sets or keeps the HOST header to be what was used to access the proxy. This does not appear to be the default behavior for nginx, as it will set the host to what is used to access the backend. I don't think this won't work in edge mode because the scheme is not part of the HOST header. |
|
Actually, there seems to be something wrong with the commits. Can you please check it? |
Should be better now. Added one more validation about setting proxy-headers in edge mode. |
There was a problem hiding this comment.
I did some testing and this actually does not get us the "raw" request but one enriched by the Hostname provider, see:
@shawkins Could you please check it?
There was a problem hiding this comment.
I have. You only get the enrichment if you call getBaseUri. If you call getRequestUri, you get the underlying request:
There was a problem hiding this comment.
Then I might be doing something wrong. :)
I start KC with hostname=example.com and access http://localhost:8080/realms/master/hostname-debug. I would expect to get that warning but it's not emitted, and while debugging I can actually see that requestURI = http://example.com:8080/realms/master/hostname-debug/test?frontEnd=true.
There was a problem hiding this comment.
If you have hostname=example.com the urls tested by hostname-debug will be to example.com, not localhost. If you have a proxy setup for example.com, you should get the warning if it then accesses keycloak over localhost.
There was a problem hiding this comment.
If you have hostname=example.com the urls tested by hostname-debug will be to example.com, not localhost.
Right, sorry, I was stupid and also forgot I have example.com in my /etc/hosts. :D
LGTM, thanks. Let's get this merged finally.
There was a problem hiding this comment.
Just to double check - do you think we need to review our usage of getRequestUri and the other methods on KeycloakUriInfo that expose the underlying delegate? I see several code paths using that, which makes using the full hostname url without proxy-headers problematic - or are we good with just requiring the proxy-headers to be be set?
There was a problem hiding this comment.
or are we good with just requiring the proxy-headers to be be set
IMHO we're good for now - we say in docs proxy headers are required anyway for edge and reencrypt. If we did a refactor of getRequestUri, I would do that in a separate PR. But I wouldn't do that for now not to risk regressions.
also improves the handling and message around insecure contexts closes: keycloak#38091 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
…figuration/mappers/HostnameV2PropertyMappers.java Co-authored-by: Václav Muzikář <vaclav@muzikari.cz> Signed-off-by: Steven Hawkins <shawkins@redhat.com>
added updates from reviews Signed-off-by: Steve Hawkins <shawkins@redhat.com>
also adding detection of origin mismatch Signed-off-by: Steve Hawkins <shawkins@redhat.com>
…vices/resources/DebugHostnameSettingsResource.java Co-authored-by: Václav Muzikář <vaclav@muzikari.cz> Signed-off-by: Steven Hawkins <shawkins@redhat.com>
…vices/resources/DebugHostnameSettingsResource.java Co-authored-by: Václav Muzikář <vaclav@muzikari.cz> Signed-off-by: Steven Hawkins <shawkins@redhat.com>
and adding a specific check for a non-secure context Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
e3a8548 to
a4687ad
Compare
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.webauthn.account.WebAuthnSigningInTest#categoriesTestKeycloak CI - WebAuthn IT (firefox) |
cc @vmuzikar @mabartos this is a rough in of code changes to add more validation around proxy-headers. Without re-introducing something like the proxy setting, we cannot directly infer the user's intention in several cases.
In particular we still don't have a good handle on what some users were doing using Keycloak over http but not through a proxy, so the message just says something vague about reviewing the usage: "Please review whether this direct http usage of keycloak is expected." @vmuzikar I believe you mentioned something about this case being problematic with Docker usage - keycloak ends up not actually being accessed over localhost, so it's not a secure context.
It would also make more sense to put this validation (and that of the legacy property usage) in the v2 provider, but that would require broader access to the whole configuration. If we want to pursue that we could either consider adding something like Config.Scope.getDescoped(String key) - which breaks the config encapsulation a little bit, or we'll have to map everything of interest to an spi property.
The other place where users are commonly getting tripped up is here
keycloak/services/src/main/java/org/keycloak/protocol/oidc/endpoints/LoginStatusIframeEndpoint.java
Line 88 in edd67c6
I haven't done it yet, but some additional doc changes will be added as well.
WDYT?
closes: #38091