Repository navigation
Conversation
…iptionConverter, ensure when client creation and policy is enabled the policy is executed
…iptionConverter, ensure when client creation and policy is enabled the policy is executed
…iptionConverter, ensure when client creation and policy is enabled the policy is executed
…iptionConverter, ensure when client creation and policy is enabled the policy is executed
There was a problem hiding this comment.
@marcelomrwin This is nice work and great start!
I've added some inline comments. But I think nothing major.
Also I have few other concerns in relation when I was reviewing and testing this. I am not sure if to address them in this PR or rather in the follow-up PRs? I vote that 1 and 2 are addressed in this PR as those are relatively minor things. The issues 3, 4, 5 I vote that you create follow-up tasks for them into "client secret rotation" epic and send separate PRs for each of them. WDYT?
Then other issues (
-
Formatting: Keycloak uses indentiation of 4 spaces inside Java file. I noticed you used 2 spaces in most of the places in this PR. Would you mind to update it?
-
Logging: Maybe a bit of debug logging will be nice to add for example to ClientSecretRotationExecutor and maybe some other places? For example add some debug message when client secret rotated for client X and that new secret expires at time Y and old secret expires at time Z etc.
-
It may be good to add some automated test that trying to configure executor with the invalid configuration will fail. Also will be nice to have some admin REST API tests for "invalidate secret" and "get rotated secret" (I commented inline).
3.a) I think I've just found a bug in relation to the point above :-) I've tried this in the admin console:
- Create new client profile
- Click to create "secret-rotation" executor inside this new profile
- When I was requested to fill the configuration, I filled "Rotated Secret expiration" to be bigger than "Secret Expiration" . Which is invalid configuration. Saving of provider was not allowed and 8000 admin console thrown the error that configuration is invalid (which is correct behaviour). So I fixed it and filled correct "Rotated Secret Expiration" .
- After click "Save", I can see that there are 2 executors of "secret-expiration" in my client profile.
It seems that failed validation of executor still managed to create this executor, which is a bug IMO.
FYI. I've tried also to update existing executor with the invalid configuration and it worked as expected. So it seems just the creation of new executor has this bug, but update works fine.
- Another point is related to the fact when client secret expiration was enabled, but now administrator wants to disable it. Example scenario:
- I have client policy enabled with the executor for client secret rotation
- I click to some existing client and click "Credentials" and then "Re-generate secret" . The secret is rotated as expected
- Now I go to disable client policy (or remove executor from it, or change the condition so it is not applicable anymore for my client)
- Now I click again to my client and click "Re-generate secret" . The new secret is generated, but there is still old secret displayed (The very old secret from rotation 1). And times of client secret rotation are not updated.
IMO, the correct behaviour should be that when client secret rotation is not enabled, then all attributes related to client secret rotiation (secret expiration, old secret, old secret expiration, old secret creation) should be removed from the client during "Re-generate secret" or client update request. WDYT?
- There is no change in the JWTClientSecretAuthenticator, only in the ClientIdAndSecretAuthenticator. So JWTClientSecretAuthenticator currently does not have support for client secret rotation. IMO it will be good to add this, but I vote to do this in the separate PR, which will be follow-up of this PR.
|
@marcelomrwin One required thing for this PR is, that all the tests must pass in the GH actions. I see that there are failed tests: BrokerLinkAndTokenExchangeTest, CredentialsTest, ClientPoliciesImportExportTest, CookieTest, ComponentExportImportTest, FederatedStorageExportImportTest (I guess some of the failures might be related to the fact that imported realms don't have "client secret creation time", but not 100% sure. The case when the client secret don't have "Client secret creation time" filled must be correctly handled) |
|
Thank you so much for the comments Marek. We're lined up.
The main question is that there is no simple way to ask: Is secret rotation active? we only have one way to know this and that is to throw one of the eve 8BD0 nts predicted in the secret rotation executor handling. But this doesn't answer us when the executor is not active. A suggestion would be: During the client update flow or regenerate the secret or during the next login (after deactivating the policy) at the beginning of the flow include a flag on the client as an attribute for example CLIENT_SECRET_ROTATION_ENABLE = false. Inside the executor, when it was executed, edit the client and update this flag to true. At the end of the flow, if this flag was kept false, we would invoke a function in the wrapper that would remove all information related to rotation. My concern with this flow is to know how much we are going to influence database operations. I haven't had time to test it yet, but I'm worried about generating an update in the database every time you want to login, for example. The inclusion of a new attribute in the client normally generates an update in the base, perhaps if we clear this attribute before the end of the flow, the transaction does not need to update the base. I'm not sure, but I need to test.
I agree with your plan, I can easily attack points 1-3 within this PR and keep 4 and 5 for the next one. In my opinion, they seem to be quick to implement, but let's keep this PR with the problems already mentioned and avoid inserting new variables. |
|
Regarding the tests I am also quite apprehensive about the test results. It doesn't make sense to get errors because of the "Client secret creation time" attribute since it is no longer used after the proposed solution and is merely informative. there is no validation in the code or throwing an exception if it is not found. I couldn't find any exceptions that pointed out something to do with secret rotation. By the way, I pulled from main and submitted a simple push and the tests failed too. I will try to identify what could be wrong. |
|
@mposolda Some notes about the tests. UserCredentialModel model = UserCredentialModel.secret(client.getSecret());
if (model == null) throw new NotFoundException("Client does not have a secret");
return ModelToRepresentation.toRepresentation(model);this snippet public void testGetAndRegenerateSecret() {
CredentialRepresentation oldCredential = accountClient.getSecret();
CredentialRepresentation newCredential = accountClient.generateNewSecret();When we updated the method getClientSecret and actually started throwing a 404 exception if the secret was empty or null, then some tests started to fail. As this change can be rolled back with no impact on PR, we return the code above. We can open a new PR to correct this test, which in my opinion is validating a wrong KC behavior. |
Yeah. It is highly possible that it is not related to "Client secret creation time" attribute at all. This was just my guess (blind tip) that it can be related to that, but maybe I am completely wrong :-) I am leaving to you to investigate. |
From my point of view, It is completely fine to either keep the behaviour you have in the PR and fix the tests. But I am leaving to you. If you think it is easier to change it to keep as a follow-up task, it is also fine for me. I think you know this, but just a note that we cannot merge PR, which introduce some test failures. Every PR must have tests passing in the GH actions. |
There was a problem hiding this comment.
@marcelomrwin Thanks for all the updates Marcelo, that was quick! :-)
I've added 3 minor comments inline. Besides this, the only remaining thing for this PR is to add a bit logging into the executor class. After that, this PR is good to go from my point of view.
We just need a follow-up tasks for the issues 3,4,5 from above and possibly follow-up task for the documentation (if you didn't create it already).
I missed you mentioned that you will also tackle point 3 inside this PR. So I will wait for that and it means that we need follow-up only for points 4 and 5. |
I wonder that maybe the simplest solution is, that at the beginning of the
Alternatively also all the attributes related to the old secret can be deleted at this point (however those are not strictly necessary to delete as administrator can do separate click to "Invalidate old secret", which will delete the old secret). I think it is not needed to do any changes during client authentication itself. I think that client authentication should always rely on the CLIENT_SECRET_EXPIRATION attribute filled previously on the client. In case that secret is expired during client authentication, administrator will be required to manually "Re-generate secret", which will create new client secret without expiration (assuming client secret rotation is disabled after it was previously enabled). Also I think that we don't need to do any changes in the "Client Update" . IMO the most important thing, that when client secret rotation becomes disabled after it was previously enabled, administrators are not completely stucked and have some way to recover from this. However IMO it is completely fine if this requires manual action from them and that they need to manually "Re-generate secret" for all the clients. |
|
After we finish this PR I will look into this scenario to identify the best solution. It is important to point out that a manual effort by the administrator can be considered and is not all bad. |
Done. |
There was a problem hiding this comment.
@marcelomrwin Thanks! I am approving the PR.
I hope GH actions pass, so it is possible to merge the PR.
I am not 100% sure I will be able to squash and merge it as it has lots of commits, but hopefully it is not the issue. I will ping you if there are any issues during the merge.
#10489