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: certificate rotation #829

Merged
merged 13 commits into from
Aug 23, 2024

Conversation

fabriziosestito
Copy link
Contributor

@fabriziosestito fabriziosestito commented Jul 26, 2024

Description

This PR introduces a new runnable (CertController) that rotates CA root and leaf certificates:

It removes the cert-manager dependency.

NOTE: this PR requires helm chart changes, see: kubewarden/helm-charts#488

TODO:

Testing

The cert controller has been tested by using gingko/envtest.

Additional information

Part-of label

Before these changes, we used the kubewarden: true label in the webhook configuration, to filter kubewarden resources.
However, using the recommended label app.kubernetes is better.io/part-of is more idiomatic.
Also, the label is already set by the helm chart on the controller's webhook configurations.
Unfortunately, we need to support both labels to be compatible with the older versions.

Injecting the CA bundle

There was the need to use the retry.RetryOnConflict utility when injecting the caBundle in the validating/mutating webhook configuration since there could be a chance to have a conflict with the neighbor controllers (namely the policy controllers).
(Cluster)AdmissionPolicyController will eventually converge to the new bundle, since it reads the secret (from the cache) every time it restores the webhook configuration.
Instead, the CertController reconciliation loop is ticker-based, so we cannot wait for the next tick to reconcile again. Therefore retrying with a certain backoff is a good strategy in this situation. See: kubernetes-sigs/controller-runtime#1748

Fixes #819, fixes #818

Copy link

codecov bot commented Jul 26, 2024

Codecov Report

Attention: Patch coverage is 61.39706% with 105 lines in your changes missing coverage. Please review.

Project coverage is 70.14%. Comparing base (aa0a426) to head (4146066).
Report is 14 commits behind head on main.

Files Patch % Lines
internal/controller/cert_controller.go 53.52% 42 Missing and 24 partials ⚠️
internal/certs/certs.go 72.85% 10 Missing and 9 partials ⚠️
internal/certs/secrets.go 33.33% 8 Missing and 8 partials ⚠️
.../controller/policyserver_controller_cert_secret.go 86.36% 1 Missing and 2 partials ⚠️
internal/controller/policy_subreconciler.go 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #829      +/-   ##
==========================================
- Coverage   70.96%   70.14%   -0.83%     
==========================================
  Files          27       29       +2     
  Lines        2435     2599     +164     
==========================================
+ Hits         1728     1823      +95     
- Misses        562      601      +39     
- Partials      145      175      +30     
Flag Coverage Δ
integration-tests 61.04% <61.39%> (-0.22%) ⬇️
unit-tests 35.92% <0.00%> (-3.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fabriziosestito fabriziosestito self-assigned this Jul 26, 2024
@fabriziosestito fabriziosestito force-pushed the feat/server-cert-rotation branch 3 times, most recently from 6372337 to 787677e Compare July 26, 2024 11:25
@fabriziosestito fabriziosestito added this to the 1.16 milestone Jul 26, 2024
@fabriziosestito fabriziosestito force-pushed the feat/server-cert-rotation branch 3 times, most recently from a24541a to dd5fc7a Compare July 29, 2024 12:53
@fabriziosestito fabriziosestito mentioned this pull request Jul 29, 2024
13 tasks
@fabriziosestito fabriziosestito force-pushed the feat/server-cert-rotation branch 2 times, most recently from 225d8c8 to fb6a2cf Compare August 1, 2024 06:50
@fabriziosestito fabriziosestito changed the title wip: server cert rotation feat: certificate rotation Aug 1, 2024
@fabriziosestito fabriziosestito force-pushed the feat/server-cert-rotation branch 2 times, most recently from 2146a33 to 43be290 Compare August 1, 2024 07:31
@fabriziosestito fabriziosestito marked this pull request as ready for review August 1, 2024 07:32
@fabriziosestito fabriziosestito requested a review from a team as a code owner August 1, 2024 07:32
@fabriziosestito fabriziosestito force-pushed the feat/server-cert-rotation branch from 43be290 to 4731544 Compare August 1, 2024 09:40
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.

Looks really good, I like it! 👏

I left some minor comments

cmd/main.go Show resolved Hide resolved
internal/certs/certs.go Show resolved Hide resolved
internal/certs/certs.go Show resolved Hide resolved
internal/certs/certs.go Show resolved Hide resolved
internal/certs/secrets.go Show resolved Hide resolved
internal/controller/cert_controller.go Show resolved Hide resolved
internal/controller/cert_controller.go Outdated Show resolved Hide resolved
Comment on lines 220 to 223
client.MatchingLabels{
"app.kubernetes.io/part-of": "kubewarden",
"app.kubernetes.io/component": "policy-server",
},
Copy link
Member

Choose a reason for hiding this comment

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

Also here, I think we're not using these labels right now (KW 1.16). I haven't finished to review the whole PR, I guess that if this PR changes the PolicyServer reconciler to add these labels everything will be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

internal/controller/cert_controller_test.go Outdated Show resolved Hide resolved
internal/controller/cert_controller_test.go Outdated Show resolved Hide resolved
Copy link
Member

@viccuad viccuad left a comment

Choose a reason for hiding this comment

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

LGTM! great work!

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.

LGTM. Thanks for the great work!

@fabriziosestito fabriziosestito force-pushed the feat/server-cert-rotation branch from 8460ed6 to 382e7ca Compare August 8, 2024 11:37
@fabriziosestito fabriziosestito requested a review from flavio August 8, 2024 11:37
@fabriziosestito fabriziosestito force-pushed the feat/server-cert-rotation branch from 382e7ca to 28a7495 Compare August 8, 2024 13:21
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 hard work!

@jvanz
Copy link
Member

jvanz commented Aug 8, 2024

Congrats! 🚀

@flavio flavio modified the milestones: 1.16, 1.17 Aug 9, 2024
@jvanz jvanz self-assigned this Aug 23, 2024
fabriziosestito and others added 13 commits August 23, 2024 08:31
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
…ollers

Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
In the recent root CA controller change we changed the labels used in
the controller. Therefore, the policy groups policies tests need to be
updated to make them work in the latest controller.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
@jvanz jvanz force-pushed the feat/server-cert-rotation branch from 28a7495 to 4146066 Compare August 23, 2024 11:54
@jvanz
Copy link
Member

jvanz commented Aug 23, 2024

@kubewarden/kubewarden-developers I've rebased this PR on top of the latest main branch. I think that after tests passes, we can merge it.

@viccuad
Copy link
Member

viccuad commented Aug 23, 2024

Thanks! everything green, merging 🚀

@viccuad viccuad merged commit 97e1e69 into kubewarden:main Aug 23, 2024
8 of 9 checks passed
@viccuad
Copy link
Member

viccuad commented Aug 23, 2024

Moved the TODO tasks on this PR to the certs epic #7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Rotate TLS certificates Rotate CA root
4 participants