Repository navigation
Operator logic for clients in admin api v2 - #45316
Conversation
24fc40f to
c6df9af
Compare
|
Had to tweak things further to get the CRD definition as expected. @keycloak/cloud-native just wanted to check more on how we want to access the servers. http/edge scenarios are not a problem, so my initial thinking is that we'd go directly to the service endpoints. For pass-through that's a problem as we'll likely fail any hostname validation checks. Also this approach doesn't work for testing in local mode as the operator is not running in cluster - I've hacked in a workaround with access via a NodePort. I can either:
|
70efeb1 to
27c62df
Compare
I'm not sure about this. Relaxing hostname checks feels kinda insecure... for a secure product like an IAM solution. Using |
I realize that it's not great, but I was wondering if this situation already comes up - if someone configures keycloak for tls passthrough, and does not enable http, does that mean dynamic back channel requests:
I'd like to say this only needs done in the passthrough case - but we can't reliably differentiate between passthrough and reencrypt. So I think the logic would need to be that if tls is configured, but http is not enabled, then we'll have to access via hostname / hostname-admin. Thinking about it more and looking at customizability of the client, I think we should be able to still access internally, but validate against the expected external hostname - although it would be better to cleanly know when we in a passthrough vs a reencrypt scenario. |
That's a good point – that the Operator is in the same position as any app doing a backchannel request through the internal network. Thinking about it more, I believe we'll need to document that passthrough TLS (without HTTP enabled) is generally incompatible with the backchannel requests. Exposing internal hostnames in the cert might be considered a security vulnerability, IMHO. Similarly to relaxing hostname checks. For now, let's make the Operator use hostname/hostname-admin. If we ever see issues with that, we can add some explicit setting for telling the Operator whether passthrough or reencrypt is used, and based on that we'll decide whether to use internal host. |
|
@vmuzikar what do you think of the approach in the last commit of validating against the hostname admin and the service hostname? The biggest concern I can think of is whether the reencrypt hostname will actually be the service hostname. Another corner case - if you setup the instance with hostname-strict=false and don't enable http. I realize this is generally not something we recommend or support, but in passthrough mode, we may not have any idea what hostname to use. |
Captured as #45606 |
|
@keycloak/cloud-native I know we talked about this extensively in our meeting, but after more reflection I believe we should simply disable hostname verification. Since we are only trusting only the server certificate, which we could even enforce that it's not allowed to be a ca certificate, the tlsSecret would have to be compromised for any kind of attack. |
b867772 to
119c692
Compare
There was a problem hiding this comment.
@shawkins I am sorry for the late response. I went through the changes and thought about it more as well. IMHO the approach is good as is.
No attempt has been made to separate the client crds from the existing ones.
Do you mean CRDs from the old Operator? I think it's enough the API group and version differ.
We are always attempting to use the service hostname and http if available. This may not always be desirable.
I think that's ok. If we keep the control of the address on the Operator which always uses an internal hostname (without the user option to override it), it should be safe to also disable the hostname validation.
Do we need a validation that the client-admin-api:v2 feature is enabled?
Yes, we should. The controller should be noop when this feature is disabled.
How does this relate to resource ownership - if I create some client CRs, then toggle client-admin-api:v2 from enabled to disabled, does that effectively lock the state of those clients on the server-side and prevent the deletion of the CRs?
We don't have resource ownership just not. Later I reckon any resource can be managed only by its owner, or a master realm admin. But that's for a later discussion.
The follow-ups then would be:
- mTLS support
- Usage of proper Admin Client (#45364)
- Admin Client pooling
- Other auth mechanism (K8s service accounts)
| // TODO allows for local testing - could be promoted in some way to the CR if needed | ||
| public static final String KEYCLOAK_TEST_ADDRESS = "KEYCLOAK_TEST_ADDRESS"; | ||
|
|
||
| static class KeycloakClientStatusAggregator { |
There was a problem hiding this comment.
It would be good to have this as a separate class similarly to the KeycloakStatusAggregator.
There was a problem hiding this comment.
The comment above is still valid but it's not blocking.
| private SecretKeySelector secretRef; | ||
|
|
||
| @JsonPropertyDescription("Secret containing the client secret") | ||
| public SecretKeySelector getSecretRef() { | ||
| return secretRef; | ||
| } | ||
|
|
||
| public void setSecretRef(SecretKeySelector secretRef) { | ||
| this.secretRef = secretRef; | ||
| } | ||
|
|
There was a problem hiding this comment.
Thinking about this more, I'm afraid we can't do that. The Keycloak admin and Client admin are two different personas. This would allow a Client admin to read any Secret in the namespace, incl. e.g. the DB Secret, or admin bootstrap Secret.
I wonder if we should wait for #13102 to rather fully leverage Vault with security sensitive values. On the other hand, we could potentially end up in a similar situation – Client admin reading any secret from the Vault.
We'll probably need to lock this down. Maybe annotate Secrets with the CR name that they can be referenced in?
CC @stianst
There was a problem hiding this comment.
Potential solution would be if we allowed referencing KC instances in other namespaces, so that we'd allow referencing Secrets only in the same namespace.
There was a problem hiding this comment.
The Keycloak admin and Client admin are two different personas. This would allow a Client admin to read any Secret in the namespace, incl. e.g. the DB Secret, or admin bootstrap Secret.
They are different personas, but is that needing the be inforced a the Kubernetes level? Aren't we mostly targetting gitops flow such that there would be controls already on who can modify the client and other admin api style resources?
If you want this to be enforced a the Kubernetes level, then we'll need to probably think of this like a separate operator, which functions more like what is being requested in #44613 - but we need to then have some other notion of how to find the Keycloak cluster other than a reference to the CR.
There was a problem hiding this comment.
As discussed off-line there are two conserns here. A Client admin persona directly administering clients in the Keycloak namespace being given read permission to secrets in that namespace, and the Client admin persona being able to reference and exfiltrate Secrets they shouldn't have access to.
The proper solution to both is to introduce the ability to use separate namespaces per Client admin. Since we are reluctant to let the operator install in cluster scoped mode, this will lead to an even greater proliforation of operator instances - unless we consider splitting this into a separate operator.
For now that seems to be large shift in approach, so we'll continue how this PR currently is. At worst case this will mean initially documenting that those with the ability to create / edit Client CRs must also be namespace level admins.
No, the existing CRDs from the new operator. Alternatively we can come back to this if we get much closer to a release and don't feel good about the stability or usability of the new CRDs.
This relates to some of long-standing configuration related issues. Validating build-time options will generally mean that users will need to use unoptimized images, or to replicate the necessary build-time options on the CR. I'm generally leary of the complexity that features per api and version are bringing into this.
Until that is implemented, we'd have to document that the operator can assume ownership of existing clients, and that client modifications not done by the operator will be undone - but only based upon CR changes.
This can be done in this PR.
|
|
I'm capturing the follow-ups to this PR under the MVP issue. The admin client pooling isn't necessary for the MVP, so it will be created as a stand-alone issue for later. |
7e7c952 to
649ae48
Compare
| // TODO allows for local testing - could be promoted in some way to the CR if needed | ||
| public static final String KEYCLOAK_TEST_ADDRESS = "KEYCLOAK_TEST_ADDRESS"; | ||
|
|
||
| static class KeycloakClientStatusAggregator { |
There was a problem hiding this comment.
The comment above is still valid but it's not blocking.
| Config config; | ||
|
|
||
| @Override | ||
| public UpdateControl<R> reconcile(R resource, Context<R> context) throws Exception { |
There was a problem hiding this comment.
I'll capture this as a follow-up as it will need documentation as well.
jFTR – this is tracked under #45810.
Related to this is the consideration of checking the server state vs the CR state. You can set the feature in the CR and that not actually represent the state of the server for a while (in particular if some other invalid change is paired with it).
I'm fine with chalking this up to an eventual consistency issue and just letting the operator fail at the admin operation until the cluster is up-to-date. There is also no check currently of whether the server is in a ready state in general - we'll simply try the admin operation, record the failure in the status, and try again in 10 seconds.
That is fine. More concerning is that we ignore the actual config that might be baked in a custom image, but that's a broader issue and not specific to Client v2 and features.
| @JsonProperty("admin") | ||
| @JsonPropertyDescription("In this section you can find all properties related to making admin connections from the operator to the server. These settings are not used by the server.") | ||
| private AdminSpec adminSpec; |
There was a problem hiding this comment.
Thinking about this more, I wonder if we're not jumping the gun here with introducing the adminSpec. We might later introduce a dedicated mTLS field that would also configure the server. But I reckon ithe adminSpec will have other uses too.
There was a problem hiding this comment.
Thinking about this more, I wonder if we're not jumping the gun here with introducing the adminSpec.
We can use an annotation instead of spec if we're having qualms about this.
We might later introduce a dedicated mTLS field that would also configure the server.
I'm not sure what you mean - why whould you need to include a client private cert with the server configuration in general?
We might later introduce a dedicated mTLS field that would also configure the server.
Honestly I'm not sure if it will have other uses - or if we'd want to go the other direction given the secret discussion and introduce a whole other CR that configures Keycloak instance we're administering.
There was a problem hiding this comment.
We can use an annotation instead of spec if we're having qualms about this.
You mean annotation directly on the CR? That would feel a bit weird and inconsistent.
I'm not sure what you mean - why whould you need to include a client private cert with the server configuration in general?
Sorry, right, server needs only truststore, that's different config from what admin client needs.
Honestly I'm not sure if it will have other uses
Auth method might be one of the additional uses.
or if we'd want to go the other direction given the secret discussion and introduce a whole other CR that configures Keycloak instance we're administering.
Thinking about it further, I don't think we should go this direction. Except for auth credentials (for different tenants), I don't think there would be differences in admin client settings for a single KC instance.
closes: keycloak#43168 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
also starting to add tests local testing will need alternative logic for getting the admin url Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
…oakClientBaseController.java Co-authored-by: Václav Muzikář <vaclav@muzikari.cz> Signed-off-by: Steven Hawkins <shawkins@redhat.com>
|
Just information from my end - I built it locally, and it looks very good. I think the missing parts were already mentioned here - like there should be improvements in the status area for sure. Then the Client CR name is used as the clientId of the client (which is nice), but would it be possible to warn users that changing the name of the CR does not do anything? But overall, very good job! |
Operator logic for clients in admin api v2 Closes keycloak#46022 Signed-off-by: Steven Hawkins <shawkins@redhat.com>
Closes #46022
Creates base controller logic that is really just performing puts or deletes.
Differences between the CRD and admin api resources are handled via subclasses that add targeted JsonIgnores and new fields. There may be a way to do this Jackson views, but none of the serialization logic is view aware.
Once set, the CRD enforces that you cannot change the Keycloak instance nor the realm name in the client CRs because these should effectively trigger cleanups, which we're not guaranteed to get the event for.
Assumes that a "keycloak cr name"-admin Secret will contain a clientId and clientSecret. This is just a placeholder - it is likely that it will get refined, such as the operator invoking bootstrap admin to create the necessary service account.
Puts only a minimal amount of information in the status. If the returned representation (because of defaulting or normalizations) is of interest, then we'll need to add a sanitized version of that to the status.
Getting the admin client is hacked in.
No attempt has been made to separate the client crds from the existing ones.
We are always attempting to use the service hostname and http if available. This may not always be desirable. A user has even requested targeting arbitrary Keycloak instances: Support creating a client CR in cluster where keycloak is not deployed #44613
Do we need a validation that the client-admin-api:v2 feature is enabled?
Let me know your early thoughts.