Skip to content
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

feat: Always enforce {Validating,Mutating}WebhookConfiguration state #566

Merged
merged 3 commits into from
Oct 31, 2023

Conversation

viccuad
Copy link
Member

@viccuad viccuad commented Oct 30, 2023

Description

Fix #224

  • feat: Reconcile {Validating,Mutating}WebhookConfigurations when they are changed by any other means than our controller. This is done by triggering the policy reconciler, which ends up reconciling the WebhookConfigurations.
  • Now, the {Validating,Mutating}WebhookConfigurations have an OwnerReference that points to their policy.
  • The ownerReferences.blockOwnerDeletion field is automatically set to true, which means that WebhookConfigurations block the deletion of policy CRDs (see here). This doesn't create any problem, and it's beneficial for us.

Test

  • Tested manually, by editing the WebhookConfigurations' Webhooks.ClientConfig.Service.Path for example, to simulate a MITM. After the edit getting successfully applied (bumping the Generation), our controller successfully updates the Webhook and restores its configuration.
  • CI

Additional Information

Tradeoff

Given that now the WebhookConfigurations have an OwnerReference, we could defer to the K8s garbage collector instead of deleting the webhooks on our own via the policy reconciler. Still, I prefer to let our reconciler do it.

Potential improvement

Note that the reconciliation of older WebhookConfigurations that don't have the OwnerReference yet doesn't happen until they or the policies get an update. Once that happens, they will have the OwnerReference and be watched.
This is the case for already-running Kubewarden deployments. We could try to treat this case (by adding controller code, refreshing all the policies resources, etc).

@viccuad viccuad self-assigned this Oct 30, 2023
@viccuad viccuad requested a review from a team as a code owner October 30, 2023 12:44
@viccuad viccuad force-pushed the feat-webhooks-reconciled branch 3 times, most recently from bd0efb6 to 65a7712 Compare October 30, 2023 12:57
Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
Mark `{Validating,Mutating}WebhookConfigurations` that are created ore
updated when reconciling a {validating,mutating} policy as owned by the
policy.

Note that this would mean they also get garbage-collected by Kubernetes,
which is ok.

The WebhookConfigurations get their OwnerReference set with
`controllerutil.SetControllerReference()` (don't confuse with
`controllerutil.SetOwnerReference`).

Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
@viccuad
Copy link
Member Author

viccuad commented Oct 30, 2023

rebased on top of main.

The {Validating,Mutating}WebhookConfigurations have an OwnerReference
that points to their policy.

Make the controller reconcile the WebhookConfigurations if they have any
change, by running the policy reconciler.

Signed-off-by: Víctor Cuadrado Juan <vcuadradojuan@suse.de>
Copy link
Member

@jvanz jvanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question. I think the code is using the wrong functon to set the owner reference.

internal/pkg/admission/mutating-webhook.go Show resolved Hide resolved
Copy link
Member

@flavio flavio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix

@viccuad viccuad merged commit 188def9 into kubewarden:main Oct 31, 2023
7 checks passed
jvanz added a commit to jvanz/kubewarden-controller that referenced this pull request Nov 1, 2023
…reconciled"

This reverts commit 188def9, reversing
changes made to 581729d.
flavio pushed a commit to jvanz/kubewarden-controller that referenced this pull request Nov 2, 2023
…reconciled"

This reverts commit 188def9, reversing
changes made to 581729d.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
flavio added a commit that referenced this pull request Nov 2, 2023
Revert "Merge pull request #566 from viccuad/feat-webhooks-reconciled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants