feat: disable oauth2 client deletion#149
Conversation
fedd3c2 to
09201b6
Compare
Demonsthere
left a comment
There was a problem hiding this comment.
I agree with your goal, but not the method of implementation. Imho a better solution would be to add a field to the CR deletionPolicy: Delete | Orphan with delete being the default option. Orhpan would allow for deleting the CR without client deletion.
wdyt? :)
09201b6 to
40994e1
Compare
That would work too 👍 And more fine-grained, since it can be defined on a client-per-client basis. I'll push some edits. |
3fe7600 to
d12c170
Compare
Demonsthere
left a comment
There was a problem hiding this comment.
The code looks simple and good :) I am just wondering about an integration test case for this, supplying 2 clients with different policies, deleting the CRs and asserting the controller state afterwards, wdyt?
Would be neat! Also, is there already a manner to check that an oauth2 client has been properly deleted? I'd be grateful for a hand here 😅 |
|
If we would like to do it in-code only, then https://github.com/ory/dockertest would be useful. However a full e2e test would require starting up k8s in k3d or similar, deploying the controller with hydra using helm and a build image, applying manifests and then calling the hydra api to list clients. Delete both clients (assuming they have different policies) and listing clients again. |
d12c170 to
7759bd0
Compare
Hey @Demonsthere ! Finally came around to have some time and dive into the integration tests. I've added two tests:
I hope that'll do the trick :) Let me know what you think. |
| // OAuth2ClientDeletionPolicy represents if a deleted oauth2 client object should delete the database row or not. | ||
| type OAuth2ClientDeletionPolicy string | ||
|
|
||
| const ( |
There was a problem hiding this comment.
In general I have no issues with the changes and tests :) The only thing I would modify is to change the type to use iota and specify the valid values.
Also, please run the generation makefile commands to generate the api schemas :)
There was a problem hiding this comment.
Hey @Demonsthere 👋
Sure, I pushed some changes.
I hope everything is up to date now :)
b53e0d5 to
881194c
Compare
This new feature allows to disable hydra-maester OAuth2 client deletion. It can be a pitfall that, when a Kube CRD gets deleted, the OAuth2 client gets deleted. OAuth2 clients can be critical for production environments to work properly, and allowing to delete one when a Kubernetes CRD gets deleted has shown to be brittle. This feature should make hydra-maester safer.
881194c to
b471499
Compare
| Indicates if a deleted OAuth2Client custom resource should delete the database row or not. | ||
| Value 0 means deletion of the OAuth2 client, value 1 means keep an orphan oauth2 client. | ||
| enum: | ||
| - 0 | ||
| - 1 |
There was a problem hiding this comment.
This seems to be wrong - 1 is delete and 2 is orphan. With this CRD, we cannot set deletionPolicy: 2, so it's impossible to use this new feature.
There was a problem hiding this comment.
Anyway, why were integers chosen here? This is extremely non-descriptive. Instead strings Delete/Retain should be supported.
There was a problem hiding this comment.
I reckon there is indeed a bug, feel free to open a pull request to address the issue :)
This new feature allows to disable hydra-maester OAuth2 client deletion. It can be a pitfall that, when a Kube CRD gets deleted, the OAuth2 client gets deleted too.
OAuth2 clients can be critical for production environments to work properly, and allowing to delete one when a Kubernetes CRD gets deleted has shown to be brittle for us. The CRDs are can be (temporarily) deleted for various reasons: human error, misconfiguration, etc.)
This feature should make hydra-maester safer.
Related Issue or Design Document
No issue or design document - it's an implementation attempt of a feature that we would find useful on hydra-maester :)
Checklist
If this pull request addresses a security vulnerability,
I confirm that I got approval (please contact security@ory.sh) from the maintainers to push the changes.
Further comments