Skip to content

certrotation: cover corner case when invalid secret type has necessary metadata#1687

Closed
vrutkovs wants to merge 1 commit intoopenshift:masterfrom
vrutkovs:improve-cert-rotation-type
Closed

certrotation: cover corner case when invalid secret type has necessary metadata#1687
vrutkovs wants to merge 1 commit intoopenshift:masterfrom
vrutkovs:improve-cert-rotation-type

Conversation

@vrutkovs
Copy link
Copy Markdown
Contributor

@vrutkovs vrutkovs commented Mar 6, 2024

In this case cert-rotation won't convert secret type as ensureSecretTLSTypeSet would never run

@vrutkovs
Copy link
Copy Markdown
Contributor Author

vrutkovs commented Mar 6, 2024

/cc @stlaz @benluddy

This covers a corner case Standa found, follow up for #1681 (comment)

@vrutkovs
Copy link
Copy Markdown
Contributor Author

vrutkovs commented Mar 6, 2024

/test unit

@vrutkovs vrutkovs force-pushed the improve-cert-rotation-type branch from 5843cc5 to 3880026 Compare March 7, 2024 11:20
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Mar 7, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vrutkovs
Once this PR has been reviewed and has the lgtm label, please assign stlaz for approval. For more information see the Kubernetes Code Review Process.

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

Details 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

@vrutkovs vrutkovs force-pushed the improve-cert-rotation-type branch from 3880026 to 14409e3 Compare April 10, 2024 12:37
@vrutkovs
Copy link
Copy Markdown
Contributor Author

/retest

// this is done before content update to prevent unexpected rollouts
if ensureMetadataUpdate(signingCertKeyPairSecret, c.Owner, c.AdditionalAnnotations) && ensureSecretTLSTypeSet(signingCertKeyPairSecret) {
needsMetadataUpdate := ensureMetadataUpdate(signingCertKeyPairSecret, c.Owner, c.AdditionalAnnotations)
needsTypeUpdate := ensureSecretTLSTypeSet(signingCertKeyPairSecret)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does ensureSecretTLSTypeSet have to mess with the content of the secret?

xref:

func ensureSecretTLSTypeSet(secret *corev1.Secret) bool {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ensureSecretTLSTypeSet may change secret type if its not kubernetes.io/tls

t.Helper()
actions := client.Actions()
if len(actions) != 2 {
if len(actions) != 4 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why does the create scenario sends additional get and update requests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Previously only one create was invoked, because ensureMetadataUpdate returned true (no ownership annotations/refs) and ensureSecretTLSTypeSet returned false (if ResourceVersion is unset no type change necessary). That means the secret was created after needNewSigningCertKeyPair was returning true.

With this change needsMetadataUpdate || needsTypeUpdate and secret is created with empty data and required annotaitons/ownerrefs, later being updated with secret contents when needNewSigningCertKeyPair returns true.

This may seem like extra actions, but it protects us from unexpected changes when secret contents and metadata are fully compliant, but secret type is still invalid. Its not possible in the standard flow for born-in-4.7-clusters, but may be possible in later cycles

Data: map[string][]byte{"tls.crt": {}, "tls.key": {}},
ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "signer",
ResourceVersion: "10",
Annotations: map[string]string{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why the change, the scenario says update no annotations

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm, I should rename this to "no necessary signer annotations"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

…y metadata

In this case cert-rotation won't convert secret type as `ensureSecretTLSTypeSet` would never run
@vrutkovs vrutkovs force-pushed the improve-cert-rotation-type branch from 14409e3 to 67adba7 Compare April 15, 2024 10:16
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 15, 2024

@vrutkovs: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@vrutkovs
Copy link
Copy Markdown
Contributor Author

Included in #1693

@vrutkovs vrutkovs closed this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants