Skip to content

Fixes to hostname#10820

Merged
stianst merged 1 commit intokeycloak:mainfrom
pedroigor:issue-hostname
Mar 22, 2022
Merged

Fixes to hostname#10820
stianst merged 1 commit intokeycloak:mainfrom
pedroigor:issue-hostname

Conversation

@pedroigor
Copy link
Copy Markdown
Contributor

@pedroigor pedroigor commented Mar 18, 2022

  • Removes the none value for the proxyoption. Users should not really set this value but don't set proxy. It also causes issues when resolving kc.proxy because if none is set, the resolved value is none and not false.
  • Added a hostname-port option to allow setting the port the proxy is using to expose the frontend URL.
  • Removed the hostname-admin option because it is causing a lot of unnecessary confusion. We instead default to using the request info (scheme, port, etc) to build the admin Url and rely on the proxy to expose or not this URL.
  • Added specific tests for hostname within the distribution test suite. We no longer need to run the tests from the base test suite.
  • Fixes the test suite to properly remove the distribution before running tests.

Closes #10627
Closes #10331

Copy link
Copy Markdown
Contributor

@DGuhr DGuhr left a comment

Choose a reason for hiding this comment

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

Nice, thanks! PR itself LGTM (assuming the tests are green) - but could you also change the https://www.keycloak.org/server/hostname guide pls to reflect these changes?

edit: seems there are also regressions to the operator testsuite.

@pedroigor
Copy link
Copy Markdown
Contributor Author

@DGuhr Updated the guide.

@DGuhr
Copy link
Copy Markdown
Contributor

DGuhr commented Mar 18, 2022

@pedroigor sorry, forgot to mention the proxy guide. when none is not available anymore, we should remove it from the available modes here: https://www.keycloak.org/server/reverseproxy

@DGuhr
Copy link
Copy Markdown
Contributor

DGuhr commented Mar 18, 2022

@pedroigor think i spotted a bug, iirc the behaviour was different before:

scenario: run start-dev with https. want to access admin login after creating initial admin user.

  1. create host entry for id.keycloak.test in local HOSTS
  2. run ./kc.sh start-dev --hostname=id.keycloak.test --https-certificate-file=../conf/id.keycloak.test.pem --https-certificate-key-file=../conf/id.keycloak.test-key.pem --https-port=8555
  3. access welcomepage using https://localhost:8555, create initial admin user
  4. click on "Administration console" link

outcome: invalid redirect_uri, see screenshot. also it now opens with id.keycloak.test instead of localhost.
Screenshot 2022-03-18 at 16 46 09

expected behaviour: login page for master realm opens with uri localhost:8555, as hostname-strict and hostname-strict-https are false in devmode and login is called from internal link.

Would be nice if we could check these also using automated tests (like assertAdminPage in the old testsuite), e.g. https://www.testcontainers.org/modules/webdriver_containers/ or using RestAssured.

@pedroigor
Copy link
Copy Markdown
Contributor Author

@DGuhr Not really a bug because the client is not configured to allow that redirect URI. Try accessing using the hostname and it should work.

@DGuhr
Copy link
Copy Markdown
Contributor

DGuhr commented Mar 20, 2022

@pedroigor uh yes, absolutely right, my apologies. So then LGTM here :)

Not 100% sure we would not need a hostname-http-port and hostname-https-port, but if so could be done in another iteration i guess.

DGuhr
DGuhr previously approved these changes Mar 20, 2022
DGuhr
DGuhr previously approved these changes Mar 21, 2022
Copy link
Copy Markdown
Contributor

@DGuhr DGuhr left a comment

Choose a reason for hiding this comment

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

@stianst stianst merged commit ffa6df5 into keycloak:main Mar 22, 2022
stianst pushed a commit to stianst/keycloak that referenced this pull request Mar 22, 2022
@stianst stianst mentioned this pull request Mar 22, 2022
stianst pushed a commit to stianst/keycloak that referenced this pull request Mar 22, 2022
stianst pushed a commit to stianst/keycloak that referenced this pull request Mar 22, 2022
@netcompany-runeviumsondergaard
Copy link
Copy Markdown

Please also update "Relevant options":
image

None is still an option

@joao-rebelo
Copy link
Copy Markdown

I'm having troubles having the admin GUI behind a proxy since 17.0.1. I'm not sure if it would be caused by this issue and if it is an issue or a feature.
The details for my scenario / investigations so far are described at discourse:
https://keycloak.discourse.group/t/keycloak-17-0-1-admin-console-on-edge-mode/14584

Should I be configuring something differently now?

@AllexVeldman
Copy link
Copy Markdown

AllexVeldman commented Apr 26, 2022

@pedroigor I was using the hostname-admin to expose the admin console to our development team using cloudflared tunnel on a separate subdomain with the frontend endpoints behind a proxy with hostname-strict=true.

What is the recommended migration for this scenario?

edit: changing hostname-strict=false still gives a invalid_redirect_uri error
only header added by our admin tunnel is the Host header

@pedroigor
Copy link
Copy Markdown
Contributor Author

@AllexVeldman Now the admin URLs are solely based on the request info. That also means obtaining the info from the HTTP headers forwarded by your proxy.

@AllexVeldman
Copy link
Copy Markdown

AllexVeldman commented Apr 26, 2022

@pedroigor The redirect_url is correctly built, it's the request for the login form that does not accept the redirect_uri:

2022-04-26 11:32:58,360 WARN  [org.keycloak.events] (executor-thread-0) type=LOGIN_ERROR, realmId=master, clientId=security-admin-console, userId=null, ipAddress=<ip>, error=invalid_redirect_uri, redirect_uri=https://subA.domain.com/auth/admin/master/console/

with keycloak.conf

hostname=subB.domain.com
hostname-admin=subA.domain.com
hostname-strict=false
hostname-strict-backchannel=false
http-relative-path=/auth

So my flow is

  • https://subA.domain.com/auth/admin (admin endpoint)
  • redirects to https://subA.domain.com/auth/admin/master/console/
  • requests (frontend endpoint) https://subB.domain.com/auth/realms/master/protocol/openid-connect/auth?...redirect_uri=https%3A%2F%subA.domain.com%2Fauth%2Fadmin%2Fmaster%2Fconsole%2F

@AllexVeldman
Copy link
Copy Markdown

I got it to work by setting the frontendUrl of the master domain as suggested in https://keycloak.discourse.group/t/frontendurl-and-adminurl-how-to-restrict-admin-console-to-internal-ip-only/2655

@pedroigor
Copy link
Copy Markdown
Contributor Author

+1. It should also be possible to register the https://subA.domain.com/auth/admin/master/console/ as a valid redirect URI for the security-admin-console client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keycloak admin UI drops https port if --hostname is used

6 participants