Skip to content

feat: add support to secretTemplates#3828

Merged
jetstack-bot merged 17 commits intocert-manager:masterfrom
jonathansp:master
Aug 3, 2021
Merged

feat: add support to secretTemplates#3828
jetstack-bot merged 17 commits intocert-manager:masterfrom
jonathansp:master

Conversation

@jonathansp
Copy link
Contributor

@jonathansp jonathansp commented Mar 31, 2021

Signed-off-by: jonathansp jonathansimonprates@gmail.com

What this PR does / why we need it:

This change introduces the concept of SecretTemplate for Certificates. When a certificate is issued, a new secret is created to hold the certificate data. This secret is created by cert-manager. In order to use solutions like kubed to copy this secret to multiple namespaces, this created secret must be annotated.

SecretTemplate is a property of CertificateSpec. Labels and Annotations defined there will be copied to the Secret when required.

Which issue this PR fixes:

fixes #2576

Special notes for your reviewer:

This PR is not 100% finished yet. After reviewing I will add the documentation of the new feature as well as the release note.

Release note:

Add support for adding custom annotations and labels to the Secret containing the TLS key pair.

@jetstack-bot jetstack-bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 31, 2021
@jetstack-bot
Copy link
Contributor

Hi @jonathansp. Thanks for your PR.

I'm waiting for a jetstack or cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@jetstack-bot jetstack-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 31, 2021
@jetstack-bot jetstack-bot requested review from munnerz and wallrj March 31, 2021 11:23
@jetstack-bot jetstack-bot added area/api Indicates a PR directly modifies the 'pkg/apis' directory area/testing Issues relating to testing labels Mar 31, 2021
@jonathansp
Copy link
Contributor Author

/assign @JoshVanL

@jetstack-bot jetstack-bot added dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. and removed dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Apr 2, 2021
@jonathansp jonathansp force-pushed the master branch 2 times, most recently from 3c2857c to fbdf402 Compare April 2, 2021 11:58
@jetstack-bot jetstack-bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. and removed dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. labels Apr 2, 2021
@lzecca78
Copy link

so, when this PR will be merged?

@jonathansp
Copy link
Contributor Author

I will be happy to change or improve any implementation or design you guys are not happy with. Let me know.

@ubergesundheit
Copy link
Contributor

How would one use this through the an Ingress?

@wallrj
Copy link
Member

wallrj commented May 27, 2021

/milestone Next

I'm adding this to the next milestone during our 2021-05-27 triage session, because it seems like it is close to being mergable and because it solves a much reported issue.

It also ties in quite closely with #3537 which makes cert-manager copy the Certificate labels to the Secret.

@jetstack-bot jetstack-bot added this to the Next milestone May 27, 2021
@deveshk0
Copy link

When can we expect this to get merged?

Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

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

Thanks @jonathansp

This is a much requested feature and the code and tests all make sense.

I asked myself if this feature needs an E2E test, but I think these additional SecretManager integration tests are sufficient.

I think you'll see quite a few bazel build and verification checks fail until you make various changes to Bazel.build files, regenerate the CRD files, and add the new fields to all APIs.

/ok-to-test

@jetstack-bot jetstack-bot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 24, 2021
… prefix

Signed-off-by: jonathansp <jonathansimonprates@gmail.com>
Signed-off-by: jonathansp <jonathansimonprates@gmail.com>
Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

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

Thanks for all your work on this @jonathansp

I tried it locally and it worked well. Thanks for creating the followup GitHub issue.
We can add the label and annotation cleanup feature in a future PR.

/lgtm
/approve

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 3, 2021
@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jonathansp, wallrj

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

The pull request process is described 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

@jetstack-bot jetstack-bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Aug 3, 2021
@wallrj
Copy link
Member

wallrj commented Aug 3, 2021

Added a release note.

@wallrj
Copy link
Member

wallrj commented Aug 3, 2021

/kind feature

@jetstack-bot jetstack-bot added kind/feature Categorizes issue or PR as related to a new feature. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Aug 3, 2021
@jetstack-bot jetstack-bot merged commit 6108170 into cert-manager:master Aug 3, 2021
@jetstack-bot jetstack-bot modified the milestones: Next, v1.5 Aug 3, 2021
@jonathansp
Copy link
Contributor Author

Thanks for all your work on this @jonathansp

I tried it locally and it worked well. Thanks for creating the followup GitHub issue.
We can add the label and annotation cleanup feature in a future PR.

/lgtm
/approve

Thanks @wallrj. I'm glad to contribute. Anything I can help with, just let me know.

@reda-sj
Copy link

reda-sj commented Aug 3, 2021

Awesome work @jonathansp 👏

@ubergesundheit
Copy link
Contributor

Hey sorry to chime in again,

just wanting to confirm this does not make it possible to add the secretTemplates to certificate Secrets automatically generated for Ingresses, right?

Thanks!

@wallrj
Copy link
Member

wallrj commented Aug 4, 2021

just wanting to confirm this does not make it possible to add the secretTemplates to certificate Secrets automatically generated for Ingresses, right?

@ubergesundheit No, I'm afraid not. The ingress-shim creates a Certificate based on annotations on your Ingress. But there are only a few Certificate fields that can be controlled by Ingress annotations. See https://cert-manager.io/docs/usage/ingress/#supported-annotations

There is an idea for Certificate presets, which would allow you to add defaults for every field in the Certificates created by ingress-shim. See #2239

Comment on lines +188 to +192
for a := range crt.SecretTemplate.Annotations {
if strings.HasPrefix(a, "cert-manager.io/") {
el = append(el, field.Invalid(secretTemplateAnnotationsPath, a, "cert-manager.io/* annotations are not allowed"))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I just noticed that we are iterating on a map here. Since the iterating order is random on Go maps, this means we end up with flakiness, e.g. in https://prow.build-infra.jetstack.net/view/gs/jetstack-logs/logs/ci-cert-manager-previous-previous-experimental/1439782520404054016 😅

To reproduce:

$ bazel run //pkg/internal/apis/certmanager/validation:go_default_test
$ ./bazel-bin/pkg/internal/apis/certmanager/validation/go_default_test_/go_default_test -test.run "TestValidateCertificate/invalid_with_disallowed_'CertificateSecretTemplate'_annotations" -test.count=10
--- FAIL: TestValidateCertificate (0.00s)
    --- FAIL: TestValidateCertificate/invalid_with_disallowed_'CertificateSecretTemplate'_annotations (0.00s)
        certificate_test.go:747: Expected error spec.secretTemplate.annotations: Invalid value: "cert-manager.io/alt-names": cert-manager.io/* annotations are not allowed but got spec.secretTemplate.annotations: Invalid value: "cert-manager.io/certificate-name": cert-manager.io/* annotations are not allowed
        certificate_test.go:747: Expected error spec.secretTemplate.annotations: Invalid value: "cert-manager.io/certificate-name": cert-manager.io/* annotations are not allowed but got spec.secretTemplate.annotations: Invalid value: "cert-manager.io/alt-names": cert-manager.io/* annotations are not allowed
FAIL

We can fix the flakiness by expecting the errors in the unit test to appear in any order.

Instead of

for i, e := range errs {
	expectedErr := s.errs[i]
	if !reflect.DeepEqual(e, expectedErr) {
		t.Errorf("Expected error %v but got %v", expectedErr, e)
	}
}

we could use ElementsMatch (from the testify module):

assert.ElementsMatch(t, s.errs, errs)

Copy link
Member

@maelvls maelvls Sep 20, 2021

Choose a reason for hiding this comment

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

Oops, I just noticed that #4365 fixes the flakiness issue!

The reason we have this flakiness is that we forgot to backport this fix to the branch release-1.5.

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/api Indicates a PR directly modifies the 'pkg/apis' directory area/deploy Indicates a PR modifies deployment configuration area/testing Issues relating to testing dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support adding custom annotations to generated secret