Operator: Support for create ingress / route without setting KC_HOSTNAME environment variable in application container #47564
Replies: 3 comments 6 replies
-
|
@shawkins would be great to have your attention on this matter |
Beta Was this translation helpful? Give feedback.
-
|
Can you clarify what dynamic hostname you are looking to use? There is already https://www.keycloak.org/operator/basic-deployment#_hostname for using a dynamic hostname, but it requires setting the ingress classname to openshift-default. |
Beta Was this translation helpful? Give feedback.
-
Can you clarify what you mean by a different hostname? By design, there is just a single default hostname for keycloak. If your loadbalancer wants to make keycloak available as "public.domain.name", then the hostname for keycloak should be set to "public.domain.name". If you enable dynamic backchannel requests -https://www.keycloak.org/server/hostname#_utilizing_an_internal_url_for_communication_among_clients - you must use a full url as the hostname, and then you are able to issue backchannel requests directly to the service hostname.
That is the correct behavior - X-Forwarded-Host will only be used if hostname-strict=false and no hostname is set. Setting the hostname is nearly always recommended for production though. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The problem
Currently the operator uses
spec.hostname.hostnameto define both:This puts a wall to deploy keycloak with dynamic hostname keeping ingress managed by the operator.
I mean, when both
spec.hostname.hostnameandspec.hostname.strictare defined operator creates:spec.hostname.hostname(so a openshift route with domain equals to ingress host)KC_HOSTNAMEequals tospec.hostname.hostnameandKC_HOSTNAME_STRICTequals tospec.hostname.strict.Therefore, if someone tries to configure Keycloak CR as below, wanting to have a dynamic hostname, he will not be able to.
As exposed in log
KC_HOSTNAME_STRICTis ignored ifKC_HOSTNAMEis specified and that is exactly what operator does:When you need to deploy keycloak with distinct domains for internal and external users this behaviour turn into a problem.
Workarounds
To workaround that I found two options both ends with a keycloak container as below:
KC_HOSTNAMEdefinedKC_STRICT_HOSTNAME=falseThat allows distinct domains for internal and external users.
Not specify
spec.hostname.hostnameThe first is to not specify
spec.hostname.hostnameand disable operator-managed ingress.The trade-off is clear. The need to handle ingress creation.
Override
KC_HOSTNAMEwithspec.unsupported.podTemplateYeah, this is weird but works.
Environment variables specified via podTemplate take precedence over those specified directly by the operator (I don't know whether this applies to all env vars).
The trade-off again is clear. The use of
spec.unsupportedis discouragedSolution?
Perhaps the simplest solution is to instruct the operator not to set
KC_HOSTNAMEwhenspec.hostname.strictis set tofalse. I mean, whenspec.hostname.strictis set tofalseoperator should usespec.hostname.hostnamejust for create the ingress.Another way would be to have a
spec.ingress.hostnameoption but I guess that will turn all more complex and error prone.I was going to create a new issue, but I thought it would be better to create this discussion first to see more opinions.
Beta Was this translation helpful? Give feedback.
All reactions