-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(crd): restrict database secret name to be immutable #831
Conversation
/build_test |
There might be cases where the user simply migrate the content of the custom database secret to another one. This means the keys are the same but the operator will consider it as updated. I am not sure if it's good practice or secure to check secret contents or I am overthinking. Let me know what you think :D |
|
Seems to me like it should be OK to do in general, so long as we are careful with how we handle the secret after we have accessed it. ie don't log the secret contents, don't copy it to another file/secret/configmap/etc., avoid holding it in memory on heap and if this can't be avoided then be sure to write over the char/byte array so that the secret is unlikely to be seen within a heap dump. |
Thanks! Make sense to me! Are we looking to implement the checks at secret field level here? If so, I make this draft and move in that direction. Or is this good? |
I don't think it's necessary to do that, but if we were to implement something like that, those would be the constraints. For example,
as a very rough pseudocode example. Here the idea is that the generated secret is hashed and the hash stored in the CR status, so we can use this hash for change detection rather than relying on Secret naming for change detection. There are probably better k8s-specific ways to do this, but if you were to directly examine the Secret contents to do change detection, I think it would look something like this. |
Ahh how about the cases where the secret contains more than just I guess I am also a bit hesitant to save to secret hash in CR status. Another way is to save the hashes in another secrets but that seems not ideal. I wonder if it is worth it to handle these unlikely cases or just make the |
Making it immutable sounds like another good option. Basically, I think the right options are the ones that are intuitive for the user. So if it's immutable, they will understand that they need to delete and recreate things over again if they want to make any changes. If it is mutable then I think they would expect full change detection and automatic redeploy as needed - having it mutable but only checking for name changes seems like it could be confusing, since a rename with no content change should not actually do anything, whereas keeping the same name with updated content should cause a redeploy. |
Ahh thanks make sense! I think, IMO, the more simple and easier way with more restrictions (i.e. immutable field) would fit more since it's common in k8s too. I can try: https://kubernetes.io/blog/2022/09/29/enforce-immutability-using-cel/ (k8s 1.25+) or with an admission webhook. Though, the PR essentially does the similar thing by erroring out from the changes and emit the Event. We can also suggest the users to make their secret immutable: https://kubernetes.io/docs/concepts/configuration/secret/#secret-immutable (k8s 1.21+). That being said, we are still supporting k8s 1.19+? |
I'd be fine with us bumping the minimum support to 1.25. |
Ah nice, considering pretty much k8s 1.25- are EOL. |
07341a6
to
47739b1
Compare
https://kubernetes.io/blog/2022/09/23/crd-validation-rules-beta/#crd-transition-rules
Unfortunately, I ran into a bit of a roadblock here. The CRD's validation/transition rules have above restrictions for optional fields (i.e. both There are possible workaround that requires k8s 1.30+ or with explicit enabling of CRD validation ratcheting feature gate. IMO, I don't think this is ideal to enforce it. So, I kept the original implementation that would detect the change in |
I think the change itself makes sense, just the two documentation notes above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, @ebaron?
5f0aa76
to
7c418f2
Compare
Signed-off-by: Thuan Vo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
/build_test |
|
Welcome to Cryostat! 👋
Before contributing, make sure you have:
main
branch[chore, ci, docs, feat, fix, test]
git commit -S -m "YOUR_COMMIT_MESSAGE"
Fixes: #475
Description of the change:
Updated the reconciler logic to emit an Event to warn against mismatched secret name for database and return an approriate error.
Motivation for the change:
See #475. The secret used to database encryption must not change (i.e.
databaseOptions.secretName
is immutable).How to manually test:
Create a secret:
Deploy the operator and create a CR:
Wait for the controller finishes reconciling. Then, update the CR to remove the databaseOptions.secretName spec. The controller should show an error in reconciler loop and an event emitted. Vice versa, create an empty CR, wait for reconciling, and update the CR to specify the databaseOptions.secretName spec. The same behaviour should occur.
Controller's log:
Events