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

Validate CABundle when writing CRD #124061

Merged
merged 2 commits into from
Jul 23, 2024

Conversation

Jefftree
Copy link
Member

@Jefftree Jefftree commented Mar 26, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #123835

Special notes for your reviewer:

Does this PR introduce a user-facing change?

CustomResourceDefinition objects created with non-empty `caBundle` fields which are invalid or do not contain any certificates will not appear in discovery or serve endpoints until a valid `caBundle` is provided. Updates to CustomResourceDefinition are no longer allowed to transition a valid `caBundle` field to an invalid `caBundle` field, because this breaks serving of the existing CustomResourceDefinition.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 26, 2024
@k8s-ci-robot k8s-ci-robot added area/apiserver kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Mar 26, 2024
@Jefftree Jefftree force-pushed the conversion-webhook-invalidca branch from 91ef3a6 to eda7cd6 Compare March 26, 2024 16:30
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 26, 2024
@Jefftree Jefftree force-pushed the conversion-webhook-invalidca branch from eda7cd6 to b66a7cf Compare March 26, 2024 16:31
@Jefftree Jefftree changed the title [WIP] Validate CABundle when writing CRD Validate CABundle when writing CRD Mar 26, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 26, 2024
@Jefftree
Copy link
Member Author

flake #123786
/test pull-kubernetes-node-e2e-containerd

@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@Jefftree Jefftree force-pushed the conversion-webhook-invalidca branch from 08e155c to 6417510 Compare March 26, 2024 19:23
@leilajal
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 26, 2024
@Jefftree Jefftree force-pushed the conversion-webhook-invalidca branch from 0ea4bdb to 72c7a59 Compare March 27, 2024 17:27
// Allows invalid CA Bundle to be specified only if the existing CABundle is invalid
// or if the CRD is not established yet.
func allowInvalidCABundle(oldCRD *apiextensions.CustomResourceDefinition) bool {
if !apiextensions.IsCRDConditionTrue(oldCRD, apiextensions.Established) {
Copy link
Member

Choose a reason for hiding this comment

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

in the controller where we set Established=true (https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiextensions-apiserver/pkg/controller/establish/establishing_controller.go#L119), after names are accepted, we now need to check if the caBundle is valid before setting Established=True

if it is not, set Established=False with a specific reason indicating the caBundle is not valid

Copy link
Member Author

@Jefftree Jefftree Jul 19, 2024

Choose a reason for hiding this comment

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

@jpbetz
Copy link
Contributor

jpbetz commented Jul 19, 2024

@Jefftree can we get this in for 1.31?

@Jefftree Jefftree force-pushed the conversion-webhook-invalidca branch 2 times, most recently from 1b72efd to 99fb350 Compare July 19, 2024 19:36
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Jefftree, liggitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Jefftree Jefftree force-pushed the conversion-webhook-invalidca branch from 99fb350 to a5791b3 Compare July 19, 2024 19:39
@jpbetz
Copy link
Contributor

jpbetz commented Jul 23, 2024

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 23, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: a0d51675e22df120e27cf58b9080a9a1dca10d5e

@Jefftree
Copy link
Member Author

/hold

need to think about how this will interact with any special handling we do of whitespace-only caBundle fields

Next steps discussed via #124061 (comment) and this PR addresses part of it.

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 23, 2024
@k8s-ci-robot k8s-ci-robot merged commit 04d2f33 into kubernetes:master Jul 23, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.31 milestone Jul 23, 2024
@liggitt
Copy link
Member

liggitt commented Jul 25, 2024

Next steps discussed via #124061 (comment) and this PR addresses part of it.

is there an open issue tracking the remaining work to do?

@liggitt
Copy link
Member

liggitt commented Jul 25, 2024

updated release note to accurately describe the new behavior

@Jefftree
Copy link
Member Author

#126447 tracks the remaining work

akutz added a commit to akutz/vm-operator that referenced this pull request Jul 31, 2024
This patch removes the caBundle field from the conversion webhook
definitions. This field was set to the base-64 encoded newline,
i.e. Cg==, to allow the creation of the webhooks since the field
was previously marked as required. This was in error. The field
was supposed to be marked optional, which was fixed in 2018. By
then the pattern had already been established to ensure
Cert-Manager could find the webhook def and replace the CABundle
field with a valid value.

However, this pattern created havoc on updates, replacing certs
when updating infra components with newline chars. A change in
K8s 1.30 rc1 disallows this pattern, requiring clients to omit the
field entirely.

This patch is in accordance with the new guidelines. Now that
kubernetes/kubernetes#124061 is merged,
continuing to use "caBundle: Cg==" will cause the manifests to
fail when used to update an existing CRD.

The K8s Slack thread
https://kubernetes.slack.com/archives/C0EG7JC6T/p1722441161968339
has more information.
akutz added a commit to akutz/vm-operator that referenced this pull request Jul 31, 2024
This patch removes the caBundle field from the conversion webhook
definitions. This field was set to the base64-encoded newline,
i.e. Cg==, to allow the creation of the webhooks since the field
was previously marked as required. This was in error. The field
was supposed to be marked optional, which was fixed in 2018. By
then the pattern had already been established to ensure
Cert-Manager could find the webhook def and replace the CABundle
field with a valid value.

However, this pattern created havoc on updates, replacing certs
when updating infra components with newline chars. A change in
K8s 1.31-rc1 disallows this pattern, requiring clients to omit the
field entirely.

This patch is in accordance with the new guidelines. Now that
kubernetes/kubernetes#124061 is merged,
continuing to use "caBundle: Cg==" will cause the manifests to
fail when used to update an existing CRD.

The K8s Slack thread
https://kubernetes.slack.com/archives/C0EG7JC6T/p1722441161968339
has more information.
akutz added a commit to akutz/vm-operator that referenced this pull request Jul 31, 2024
This patch removes the caBundle field from the conversion webhook
definitions. This field was set to the base64-encoded newline,
i.e. Cg==, to allow the creation of the webhooks since the field
was previously marked as required. This was in error. The field
was supposed to be marked optional, which was fixed in 2018. By
then the pattern had already been established to ensure
Cert-Manager could find the webhook def and replace the CABundle
field with a valid value.

However, this pattern created havoc on updates, replacing certs
when updating infra components with newline chars. A change in
K8s 1.31-rc1 disallows this pattern, requiring clients to omit the
field entirely.

This patch is in accordance with the new guidelines. Now that
kubernetes/kubernetes#124061 is merged,
continuing to use "caBundle: Cg==" will cause the manifests to
fail when used to update an existing CRD.

The K8s Slack thread
https://kubernetes.slack.com/archives/C0EG7JC6T/p1722441161968339
has more information.
@Jefftree Jefftree deleted the conversion-webhook-invalidca branch September 12, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.31
Development

Successfully merging this pull request may close these issues.

CRD validation allows invalid CABundles that will fail setting up handlers
7 participants