Skip to content

Added certificate owner ref field - #5158

Closed
RomanenkoDenys wants to merge 8 commits into
cert-manager:masterfrom
RomanenkoDenys:certificate-owner-ref
Closed

RomanenkoDenys wants to merge 8 commits into
cert-manager:masterfrom
RomanenkoDenys:certificate-owner-ref

Conversation

@RomanenkoDenys

@RomanenkoDenys RomanenkoDenys commented May 25, 2022 •

Copy link
Copy Markdown
Contributor
✨ Design document: #5324

Pull Request Motivation

The cert-manager has the ability to set the owner reference field in generated secrets. We can enable this option globally by setting the --enable-certificate-owner-ref cli flag.
We want to configure it in more detail, at the certificate level. So we add a new field to the certificate CRD, cleanupPolicy.
When this field is set to Delete, the owner reference is always created on the Secret resource and the secret will be automatically removed when the certificate resource is deleted.
When this field is set to Never, the owner reference is never created on the Secret resource and the secret will not be automatically removed when the certificate resource is deleted.
Also, we add cli flag --default-secret-cleanup-policy to set default policy for certificates if certificate CRD field cleanupPolicy is not set.
--enable-certificate-owner-ref cli flag is declared as deprecated but takes precedence over --default-secret-cleanup-policy for backward compatibility.

This option is useful if the cluster contains both prod environments, where secrets should not be deleted, and development environments, where secrets should be deleted all the time.

Kind

Release Note

Added new field `cleanupPolicy` to Certificate CRD.
Added new cli flag `--default-secret-cleanup-policy`.
`--enable-certificate-owner-ref` cli flag is declared as deprecated.

@jetstack-bot jetstack-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. 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 needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels May 25, 2022
@jetstack-bot

Copy link
Copy Markdown
Contributor

Hi @RomanenkoDenys. Thanks for your PR.

I'm waiting for a 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 25, 2022
@RomanenkoDenys
RomanenkoDenys force-pushed the certificate-owner-ref branch from be271d9 to 0717496 Compare May 25, 2022 18:15
egegunes added a commit to percona/percona-xtradb-cluster-operator that referenced this pull request Jun 1, 2022
We shouldn't set owner references to cert-manager objects if we don't
want to delete secrets too. This way, after the PXC cluster is deleted
issuers, certificates and their secrets will remain intact in the
cluster.

If users want to cleanup objects created for SSL, we introduce a new
finalizer: `delete-ssl`. If this finalizer is set, the operator will
delete secrets, certificates and issuers. Unfortunately, cert-manager
doesn't set owner reference to the secret it created and this behaviour
can only configured by command line flag in the controller. Since we
can't control how users deploy cert-manager to their clusters, we
shouldn't rely on this feature and cleanup certificates and secrets
altogether. Hopefully,
cert-manager/cert-manager#5158 will merged and
we can configure this behaviour on certificate level.
egegunes added a commit to percona/percona-xtradb-cluster-operator that referenced this pull request Jun 1, 2022
We shouldn't set owner references to cert-manager objects if we don't
want to delete secrets too. This way, after the PXC cluster is deleted
issuers, certificates and their secrets will remain intact in the
cluster.

If users want to cleanup objects created for SSL, we introduce a new
finalizer: `delete-ssl`. If this finalizer is set, the operator will
delete secrets, certificates and issuers. Unfortunately, cert-manager
doesn't set owner reference to the secret it created and this behaviour
can only configured by command line flag in the controller. Since we
can't control how users deploy cert-manager to their clusters, we
shouldn't rely on this feature and cleanup certificates and secrets
altogether. Hopefully,
cert-manager/cert-manager#5158 will merged and
we can configure this behaviour on certificate level.
@irbekrm

irbekrm commented Jun 10, 2022

Copy link
Copy Markdown
Contributor

Hi thank you for the PR. I haven't looked at the contents yet, a couple thoughts:

  • because accidentally removing owner references for Secrets where they shouldn't have been removed could have very bad effect it would be good to have a clear write up of the expected behaviour in all cases where this new field gets added or removed to certain Certificates with and without the flag also being set either on cert creation or later. Do you think you could write that up? (Arguably this feature could have benefitted from a design doc)

  • then we will probably want to have a brief discussion about this - do you think you would be able to attend one of our dev meetings or a standup?

  • we will also probably want to make this an alpha field initially, but that can be discussed later

@RomanenkoDenys

RomanenkoDenys commented Jun 21, 2022 •

Copy link
Copy Markdown
Contributor Author

Hi, thank you for reply.

Hi thank you for the PR. I haven't looked at the contents yet, a couple thoughts:

  • because accidentally removing owner references for Secrets where they shouldn't have been removed could have very bad effect it would be good to have a clear write up of the expected behaviour in all cases where this new field gets added or removed to certain Certificates with and without the flag also being set either on cert creation or later. Do you think you could write that up? (Arguably this feature could have benefitted from a design doc)

We use certificateOwnerRef in our clusters.
Certificate resource

apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: dashboard
  namespace: d8-dashboard
spec:
  certificateOwnerRef: false
  dnsNames:
  - dashboard.test.com
  issuerRef:
    kind: ClusterIssuer
    name: letsencrypt
  secretName: ingress-tls
status:
  conditions:
  - lastTransitionTime: "2022-04-13T15:26:06Z"
    message: Certificate is up to date and has not expired
    observedGeneration: 2
    reason: Ready
    status: "True"
    type: Ready
  notAfter: "2022-09-10T13:26:29Z"
  notBefore: "2022-06-12T13:26:30Z"
  renewalTime: "2022-08-11T13:26:29Z"
  revision: 2

Corresponding secret -

apiVersion: v1
data:
  tls.crt: CRTCRT
  tls.key: KEYKEY
kind: Secret
metadata:
  annotations:
    cert-manager.io/alt-names: dashboard.test.com
    cert-manager.io/certificate-name: dashboard
    cert-manager.io/common-name: dashboard.test.com
    cert-manager.io/ip-sans: ""
    cert-manager.io/issuer-group: ""
    cert-manager.io/issuer-kind: ClusterIssuer
    cert-manager.io/issuer-name: letsencrypt
    cert-manager.io/uri-sans: ""
  creationTimestamp: "2022-04-13T15:26:06Z"
  name: ingress-tls
  namespace: d8-dashboard
  resourceVersion: "54898985"
  uid: c968fbbe-d25e-4f34-b7d2-b413a9c4c621
type: kubernetes.io/tls

Let's change certificate certificateOwnerRef field to true.
The secret resource does not change.
But if i remove secret, and cert-manager re-order them, ownerRef field will appear.

apiVersion: v1
data:
  tls.crt: CRTCRT
  tls.key: KEYKEY
kind: Secret
metadata:
  annotations:
    cert-manager.io/alt-names: dashboard.test.com
    cert-manager.io/certificate-name: dashboard
    cert-manager.io/common-name: dashboard.test.com
    cert-manager.io/ip-sans: ""
    cert-manager.io/issuer-group: ""
    cert-manager.io/issuer-kind: ClusterIssuer
    cert-manager.io/issuer-name: letsencrypt
    cert-manager.io/uri-sans: ""
  creationTimestamp: "2022-06-21T07:50:57Z"
  name: ingress-tls
  namespace: d8-dashboard
  ownerReferences:
  - apiVersion: cert-manager.io/v1
    blockOwnerDeletion: true
    controller: true
    kind: Certificate
    name: dashboard
    uid: 4c38d61d-6cee-4dac-a3c4-f373310b69fa
  resourceVersion: "61815950"
  uid: ddc81af0-e169-4ec9-8814-fa9841463c05
type: kubernetes.io/tls

if i restore certificateOwnerRef field to false, secret will changed on the next reorder.
So the secret only changes when cert-manager recreates it and this is the safest behavior in my opinion.
I think i should add this to documentation.

Yes, wi will discuss on the next biweekly meet.

  • we will also probably want to make this an alpha field initially, but that can be discussed later

Yes, let's discuss later.

Thank you !

@RomanenkoDenys
RomanenkoDenys force-pushed the certificate-owner-ref branch from 0717496 to 1ac262c Compare July 13, 2022 10:21
@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 Jul 13, 2022
@RomanenkoDenys
RomanenkoDenys force-pushed the certificate-owner-ref branch from 1ac262c to cc830e4 Compare July 13, 2022 10:23
@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 Jul 13, 2022
hors added a commit to percona/percona-xtradb-cluster-operator that referenced this pull request Jul 19, 2022
* K8SPXC-1030: Don't delete cert-manager certs by default

We shouldn't set owner references to cert-manager objects if we don't
want to delete secrets too. This way, after the PXC cluster is deleted
issuers, certificates and their secrets will remain intact in the
cluster.

If users want to cleanup objects created for SSL, we introduce a new
finalizer: `delete-ssl`. If this finalizer is set, the operator will
delete secrets, certificates and issuers. Unfortunately, cert-manager
doesn't set owner reference to the secret it created and this behaviour
can only configured by command line flag in the controller. Since we
can't control how users deploy cert-manager to their clusters, we
shouldn't rely on this feature and cleanup certificates and secrets
altogether. Hopefully,
cert-manager/cert-manager#5158 will merged and
we can configure this behaviour on certificate level.

* fix tests

Co-authored-by: Viacheslav Sarzhan <[email protected]>
@munnerz

munnerz commented Jul 19, 2022

Copy link
Copy Markdown
Member

I'd also like to discuss the API surface for this - I think something more like cleanupPolicy: [Delete|Never] may feel more natural and be more informative to our users :) (as well as potentially allowing us to extend the different policies we offer in future too)

@maelvls

maelvls commented Jul 20, 2022 •

Copy link
Copy Markdown
Member

I have created the design document 20220720-per-certificate-owner-ref.md with the aim to continue the discussion about the API surface.

Update: I will be on vacation from 30 July to 15 August 2022.

egegunes added a commit to percona/percona-xtradb-cluster-operator that referenced this pull request Aug 1, 2022
* K8SPXC-1030: Don't delete cert-manager certs by default

We shouldn't set owner references to cert-manager objects if we don't
want to delete secrets too. This way, after the PXC cluster is deleted
issuers, certificates and their secrets will remain intact in the
cluster.

If users want to cleanup objects created for SSL, we introduce a new
finalizer: `delete-ssl`. If this finalizer is set, the operator will
delete secrets, certificates and issuers. Unfortunately, cert-manager
doesn't set owner reference to the secret it created and this behaviour
can only configured by command line flag in the controller. Since we
can't control how users deploy cert-manager to their clusters, we
shouldn't rely on this feature and cleanup certificates and secrets
altogether. Hopefully,
cert-manager/cert-manager#5158 will merged and
we can configure this behaviour on certificate level.

* fix tests

Co-authored-by: Viacheslav Sarzhan <[email protected]>
nmarukovich pushed a commit to percona/percona-xtradb-cluster-operator that referenced this pull request Aug 1, 2022
* K8SPXC-1030: Don't delete cert-manager certs by default

We shouldn't set owner references to cert-manager objects if we don't
want to delete secrets too. This way, after the PXC cluster is deleted
issuers, certificates and their secrets will remain intact in the
cluster.

If users want to cleanup objects created for SSL, we introduce a new
finalizer: `delete-ssl`. If this finalizer is set, the operator will
delete secrets, certificates and issuers. Unfortunately, cert-manager
doesn't set owner reference to the secret it created and this behaviour
can only configured by command line flag in the controller. Since we
can't control how users deploy cert-manager to their clusters, we
shouldn't rely on this feature and cleanup certificates and secrets
altogether. Hopefully,
cert-manager/cert-manager#5158 will merged and
we can configure this behaviour on certificate level.

* fix tests

Co-authored-by: Viacheslav Sarzhan <[email protected]>
@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 Sep 24, 2022
@jetstack-bot jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 14, 2023
@maelvls

maelvls commented Jun 23, 2023

Copy link
Copy Markdown
Member

Hi 👋

I just wanted to let you know that I'll be on PTO from Tue 27 June to Sun 23 July. You can contact @inteon if a review is needed earlier.

Have a great weekend and a good month of July!

@RomanenkoDenys

Copy link
Copy Markdown
Contributor Author

PTO from Tue 27 June to Sun 23 July.

Hi, thanks ! Let's see you later!

@RomanenkoDenys
RomanenkoDenys force-pushed the certificate-owner-ref branch from 32dd28f to 6694245 Compare July 25, 2023 12:12
@jetstack-bot jetstack-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 25, 2023
RomanenkoDenys and others added 8 commits September 27, 2023 11:54
Added cleanupPolicy certificate field

Signed-off-by: Denis Romanenko <[email protected]>
Co-authored-by: Maël Valais <[email protected]>
Signed-off-by: Maël Valais <[email protected]>
Signed-off-by: Denis Romanenko <[email protected]>
Signed-off-by: Denis Romanenko <[email protected]>
Signed-off-by: Denis Romanenko <[email protected]>
Signed-off-by: Denis Romanenko <[email protected]>
Signed-off-by: Denis Romanenko <[email protected]>
Signed-off-by: Denis Romanenko <[email protected]>
@jetstack-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maelvls

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

Copy link
Copy Markdown
Contributor

@RomanenkoDenys: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cert-manager-master-e2e-v1-26-upgrade 3894761 link true /test pull-cert-manager-master-e2e-v1-26-upgrade
pull-cert-manager-master-e2e-v1-28 e571a9e link true /test pull-cert-manager-master-e2e-v1-28
pull-cert-manager-master-e2e-v1-28-upgrade e571a9e link true /test pull-cert-manager-master-e2e-v1-28-upgrade
pull-cert-manager-master-make-test e571a9e link true /test pull-cert-manager-master-make-test

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

@jetstack-bot

Copy link
Copy Markdown
Contributor

PR needs rebase.

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

Copy link
Copy Markdown
Contributor

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
/lifecycle stale

@jetstack-bot

Copy link
Copy Markdown
Contributor

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close.
/lifecycle rotten
/remove-lifecycle stale

@inteon

inteon commented Apr 7, 2024

Copy link
Copy Markdown
Member

/remove-lifecycle rotten

@onelapahead

Copy link
Copy Markdown

This looks to solve: #7041

@cert-manager-bot

Copy link
Copy Markdown
Contributor

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
/lifecycle stale

@cert-manager-prow

Copy link
Copy Markdown
Contributor

@RomanenkoDenys: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cert-manager-master-make-verify e571a9e link true /test pull-cert-manager-master-make-verify
pull-cert-manager-master-e2e-v1-30-upgrade e571a9e link true /test pull-cert-manager-master-e2e-v1-30-upgrade
pull-cert-manager-master-e2e-v1-30 e571a9e link true /test pull-cert-manager-master-e2e-v1-30
pull-cert-manager-master-e2e-v1-31-upgrade e571a9e link true /test pull-cert-manager-master-e2e-v1-31-upgrade
pull-cert-manager-master-e2e-v1-31 e571a9e link true /test pull-cert-manager-master-e2e-v1-31

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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-sigs/prow repository. I understand the commands that are listed here.

@cert-manager-bot

Copy link
Copy Markdown
Contributor

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close.
/lifecycle rotten
/remove-lifecycle stale

@cert-manager-bot

Copy link
Copy Markdown
Contributor

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.
/close

@cert-manager-prow

Copy link
Copy Markdown
Contributor

@cert-manager-bot: Closed this PR.

Details

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.
/close

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-sigs/prow repository.

@Suselz

Suselz commented Jan 26, 2026

Copy link
Copy Markdown

@maelvls, good afternoon.
We discussed this PR with @RomanenkoDenys. I received permission to continue working on it.
Can you tell me what steps I need to take to finally merge this PR? Should I rebase and open a new PR? Or reopen the current one?

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. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.