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

OCPBUGS-31384: UPSTREAM: <carry>: allow type mutation for specific secrets #1924

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

tkashem
Copy link

@tkashem tkashem commented Mar 29, 2024

some of our operators were accidentally creating secrets of type "SecretTypeTLS", and this patch enables us to move these secrest objects to the intended type in a ratcheting manner
we can drop this patch when we migrate all of the affected secret objects to to intended type, see https://issues.redhat.com/browse/API-1800

@openshift-ci-robot openshift-ci-robot added the backports/unvalidated-commits Indicates that not all commits come to merged upstream PRs. label Mar 29, 2024
@openshift-ci-robot
Copy link

@tkashem: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

@tkashem tkashem changed the title UPSTREAM: <carry>: allow type mutation for specific secrets [WIP] UPSTREAM: <carry>: allow type mutation for specific secrets Mar 29, 2024
@openshift-ci openshift-ci bot requested review from deads2k and mfojtik March 29, 2024 20:28
@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 29, 2024
@openshift-ci-robot
Copy link

@tkashem: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

@tkashem
Copy link
Author

tkashem commented Mar 30, 2024

/test e2e-aws-ovn-serial
/test verify

@tkashem
Copy link
Author

tkashem commented Mar 30, 2024

/retest

@openshift-ci-robot
Copy link

@tkashem: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

@openshift-ci-robot
Copy link

@tkashem: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

Comment on lines 6410 to 6411
// TODO: this is a short term fix, the long term goal is to improve the
// cert rotation logic that is not reliant on this hack.
Copy link

Choose a reason for hiding this comment

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

Should explicitly say that the criteria for dropping the patch is migrating all of the affected secret types.

)

func OpenShiftValidateSecretUpdateIsTypeMutationAllowed(newSecret, oldSecret *core.Secret) bool {
// we allow "SecretTypeTLS" -> "kubernetes.io/tls" only
Copy link

Choose a reason for hiding this comment

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

Explain that some of our operators were accidentally creating secrets with type SecretTypeTLS and this patch is to allow ratcheting them to the intended type.

func OpenShiftValidateSecretUpdateIsTypeMutationAllowed(newSecret, oldSecret *core.Secret) bool {
// we allow "SecretTypeTLS" -> "kubernetes.io/tls" only
if oldSecret.Type == "SecretTypeTLS" && newSecret.Type == core.SecretTypeTLS {
key := fmt.Sprintf("%s/%s", oldSecret.Namespace, oldSecret.Name)
Copy link

Choose a reason for hiding this comment

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

Nit: Could use https://pkg.go.dev/k8s.io/apimachinery/pkg/types#NamespacedName to avoid the extra string allocation per secret update.

ns, name := split[0], split[1]

// exercise a valid type mutation: "SecretTypeTLS" -> "kubernetes.io/tls"
oldSecret, newSecret := newSecretFn(ns, name, "SecretTypeTLS"), newSecretFn(ns, name, core.SecretTypeTLS)
Copy link

Choose a reason for hiding this comment

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

Please add the reverse direction too.

pkg/apis/core/validation/validation_patch_test.go Outdated Show resolved Hide resolved
oldSecret, newSecret = newSecretFn(ns, name, "SecretTypeTLS"), newSecretFn(ns, name, core.SecretTypeOpaque)
if errGot := ValidateSecretUpdate(newSecret, oldSecret); !cmp.Equal(errExpected, errGot) {
t.Errorf("expected error: %v, diff: %s", errExpected, cmp.Diff(errExpected, errGot))
}
Copy link

Choose a reason for hiding this comment

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

I don't doubt that it works but I would like to see a test that shows the kubernetes.io/tls key validation is still enforced on these updates.

pkg/apis/core/validation/validation_patch.go Show resolved Hide resolved
@openshift-ci-robot
Copy link

@tkashem: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

@tkashem tkashem changed the title [WIP] UPSTREAM: <carry>: allow type mutation for specific secrets UPSTREAM: <carry>: allow type mutation for specific secrets Apr 1, 2024
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 1, 2024
@tkashem
Copy link
Author

tkashem commented Apr 1, 2024

/retest-required

1 similar comment
@tkashem
Copy link
Author

tkashem commented Apr 2, 2024

/retest-required

//
// we can drop this patch when we migrate all of the affected secret
// objects to to intended type: https://issues.redhat.com/browse/API-1800
whitelist = map[apimachinerytypes.NamespacedName]struct{}{

Choose a reason for hiding this comment

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

The list grew quickly. I think it contains all the secrets reconciled by concurrently running certificate controllers.

)

var (
// we make an exception for the following secret objects, during update

Choose a reason for hiding this comment

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

Maybe it's worth explaining why we are allowing for this exception. We have multiple controllers reconciling the same object, resulting in unexpected outcomes such as the generation of new key pairs. Our goal is to prevent the generation of new key pairs by disallowing deletions and permitting only updates, which appear to be 'safe'.

// we allow "SecretTypeTLS" -> "kubernetes.io/tls" only
if oldSecret.Type == "SecretTypeTLS" && newSecret.Type == core.SecretTypeTLS {
key := apimachinerytypes.NamespacedName{Namespace: oldSecret.Namespace, Name: oldSecret.Name}
if _, ok := whitelist[key]; ok {

Choose a reason for hiding this comment

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

I think you this could be changed to if whitelist[key] { return true }

@@ -6407,7 +6407,12 @@ func ValidateSecret(secret *core.Secret) field.ErrorList {
func ValidateSecretUpdate(newSecret, oldSecret *core.Secret) field.ErrorList {
allErrs := ValidateObjectMetaUpdate(&newSecret.ObjectMeta, &oldSecret.ObjectMeta, field.NewPath("metadata"))

allErrs = append(allErrs, ValidateImmutableField(newSecret.Type, oldSecret.Type, field.NewPath("type"))...)
// TODO: this is a short term fix, we can drop this patch once we

Choose a reason for hiding this comment

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

shouldn't we change the commit title to UPSTREAM: <drop>: allow type mutation for specific secrets ?

// TODO: this is a short term fix, we can drop this patch once we
// migrate all of the affected secret objects to to intended type,
// see https://issues.redhat.com/browse/API-1800
if !OpenShiftValidateSecretUpdateIsTypeMutationAllowed(newSecret, oldSecret) {

Choose a reason for hiding this comment

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

I'm wondering how we could e2e validate that the type change is allowed ?

Choose a reason for hiding this comment

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

I think the easiest way would be to have an integration test. Let me write one.

Copy link

@p0lyn0mial p0lyn0mial Apr 2, 2024

Choose a reason for hiding this comment

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

apimachinerytypes.NamespacedName{Namespace: "openshift-kube-apiserver-operator", Name: "localhost-recovery-serving-signer"}: {},
apimachinerytypes.NamespacedName{Namespace: "openshift-kube-apiserver-operator", Name: "kube-control-plane-signer"}: {},
apimachinerytypes.NamespacedName{Namespace: "openshift-kube-apiserver-operator", Name: "node-system-admin-signer"}: {},
apimachinerytypes.NamespacedName{Namespace: "openshift-etcd-operator", Name: "etcd-client"}: {},

Choose a reason for hiding this comment

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

are secrets in openshift-etcd-operator and openshift-kube-controller-manager-operator also reconciled concurrently ? How are we going to ensure these secrets can be transitioned to the new type ?

Choose a reason for hiding this comment

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

}
)

func OpenShiftValidateSecretUpdateIsTypeMutationAllowed(newSecret, oldSecret *core.Secret) bool {

Choose a reason for hiding this comment

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

we could make it a private function.

@openshift-ci-robot
Copy link

@tkashem: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

atiratree pushed a commit to atiratree/kubernetes that referenced this pull request Sep 20, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
atiratree pushed a commit to atiratree/kubernetes that referenced this pull request Sep 20, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
atiratree pushed a commit to atiratree/kubernetes that referenced this pull request Sep 25, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
atiratree pushed a commit to atiratree/kubernetes that referenced this pull request Oct 1, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Nov 26, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Nov 26, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Nov 27, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Nov 27, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Nov 27, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Nov 28, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Nov 28, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Nov 29, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Nov 29, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 2, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 4, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 4, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 4, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 5, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 6, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 7, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 9, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 10, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 11, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 11, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 11, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 12, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 16, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Dec 17, 2024
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Jan 16, 2025
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
bertinatto pushed a commit to bertinatto/kubernetes that referenced this pull request Jan 16, 2025
This is a short term fix, once we improve the cert rotation logic
in library-go that does not depend on this hack, then we can
remove this carry patch.

squash with the previous PR during the rebase
openshift#1924

squash with the previous PRs during the rebase
openshift#1924
openshift#1929
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. backports/validated-commits Indicates that all commits come to merged upstream PRs. jira/severity-critical Referenced Jira bug's severity is critical for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants