Skip to content

CertificateSigningRequest selfsigned controller - #4100

Merged
jetstack-bot merged 3 commits into
cert-manager:masterfrom
JoshVanL:certificate-signing-request-selfsigned
Jun 15, 2021
Merged

jetstack-bot merged 3 commits into
cert-manager:masterfrom
JoshVanL:certificate-signing-request-selfsigned

Conversation

@JoshVanL

@JoshVanL JoshVanL commented Jun 14, 2021 •

Copy link
Copy Markdown
Contributor

This PR adds the SelfSigned CertificateSigningRequest controller for signing requests referencing a self-signed Issuer or ClusterIssuer.

Like the CertificateRequest controller, this requires an annotation which is used to reference the Secret containing the private key that signed the requester's CSR.

This PR contains no E2E tests. I have created a conformance suite for CertificateSigningRequest controllers which includes both the CA and SelfSigned issuers. This will be in a follow-up PR in to help reviewing.


cert-manager is now able to sign CertificateSigningRequests using the SelfSigned issuer. Note that
the CertificateSigningRequests support is experimental and requires the use of a flag on the
controller: `--feature-gates=ExperimentalCertificateSigningRequestControllers=true`

/assign @jakexks @irbekrm @maelvls @SgtCoDFish
/milestone Next
/kind feature

@jetstack-bot jetstack-bot added kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jun 14, 2021
@jetstack-bot jetstack-bot added this to the Next milestone Jun 14, 2021
@jetstack-bot jetstack-bot added 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 size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 14, 2021
@jetstack-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JoshVanL

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 14, 2021

@SgtCoDFish SgtCoDFish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Sorry this is long, it's a fiddly thing to discuss 😅 )

When I looked into the SelfSigned issuer for CSR resources, the block I highlighted with a ⭐ is the bit that made me really stop and think.

For CertificateRequests - which are created because of a Certificate resource - the Certificate will cause a secret with a private key to be created.

That's the thing which makes SelfSigned CertificateRequests worth using, really. For CSR resources today, without the secret being generated by cert-manager, the workflow is really hostile and circuitous:

  1. Create a private key locally, using openssl or something else
  2. Upload the private key into Kubernetes as a Secret (this is a pain with kubectl)
  3. Create a CSR locally, using openssl or something else
  4. Upload the CSR into Kubernetes as a CertificateSigningRequest
  5. The CSR is processed by cert-manager and a cert is issued.

Crucially, because the cert is self-signed, step 3 is entirely pointless. The user already has the private key and the details of the cert they want to issue. They can just issue the cert rather than faffing around with CSRs.

I detailed this in #3646 where @munnerz pointed out that the goal was for CertificateSigningRequest to eventually entirely replace CertificateRequest. If that's the case, we absolutely do need to support SelfSigned issuers with CSR resources at some point, because somewhere down the line we'll do "the switch" and Certificate resources will (have the option to) create CertificateSigningRequests instead of CertificateRequests.

That leads me to my main point:

Summary: Until (and unless) we do "the switch" I think the SelfSigned issuer type for CSRs provides no value to users. More pertinently: before "the switch", I think everyone who even thinks about using a SelfSigned issuer with a CSR resource is almost certainly making a mistake and what they actually want is a CA issuer.

Adding support for SelfSigned - like any new code - increases the amount of code we have to maintain and test, and could risk us locking in design choices now which will be harder to change in the future.

Given all that, is it maybe worth considering shelving adding support for SelfSigned until we're ready to make "the switch"?

Comment on lines +86 to +93
// Sign attempts to sign the given CertificateSigningRequest based on the
// provided SelfSigned Issuer or ClusterIssuer. This function will update the
// resource if signing was successful. Returns an error which, if not nil,
// should trigger a retry.
// CertificateSigningRequests must have the
// "experimental.cert-manager.io/private-key-secret-name" annotation present to
// be signed. This annotation must reference a valid Secret containing a CA
// private key for signing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick: I like this comment and it's a big improvement to have it versus the lack of one for the CR selfsigned controller.

Just a minor nitpick that "CA private key" could be confusing for people, since there isn't really such a concept.

Suggested change
// Sign attempts to sign the given CertificateSigningRequest based on the
// provided SelfSigned Issuer or ClusterIssuer. This function will update the
// resource if signing was successful. Returns an error which, if not nil,
// should trigger a retry.
// CertificateSigningRequests must have the
// "experimental.cert-manager.io/private-key-secret-name" annotation present to
// be signed. This annotation must reference a valid Secret containing a CA
// private key for signing.
// Sign attempts to sign the given CertificateSigningRequest based on the
// provided SelfSigned Issuer or ClusterIssuer. This function will update the
// resource if signing was successful. Returns an error which, if not nil,
// should trigger a retry.
// CertificateSigningRequests must have the
// "experimental.cert-manager.io/private-key-secret-name" annotation present to
// be signed. This annotation must reference a valid Secret containing a
// private key for signing.

}

if cmerrors.IsInvalidData(err) {
message := fmt.Sprintf("Failed to parse signing CA key from secret %s/%s", resourceNamespace, secretName)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion/nitpick: I think "signing CA key" has the potential to be confusing for people because it makes the SelfSigned issuer sound like the CA issuer. I guess it does end up being the "signing CA key" in a way, but I think just plain "private key" is clearer.

Suggested change
message := fmt.Sprintf("Failed to parse signing CA key from secret %s/%s", resourceNamespace, secretName)
message := fmt.Sprintf("Failed to parse private key from secret %s/%s", resourceNamespace, secretName)

Comment on lines +109 to +117
privatekey, err := kube.SecretTLSKey(ctx, s.secretsLister, resourceNamespace, secretName)
if apierrors.IsNotFound(err) {
message := fmt.Sprintf("Referenced Secret %s/%s not found", resourceNamespace, secretName)
log.Error(err, message)
s.recorder.Event(csr, corev1.EventTypeWarning, "SecretNotFound", message)
util.CertificateSigningRequestSetFailed(csr, "SecretNotFound", message)
_, err = s.certClient.UpdateStatus(ctx, csr, metav1.UpdateOptions{})
return err
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Marking this block with a ⭐ to refer to it in the review overall.

@JoshVanL

Copy link
Copy Markdown
Contributor Author

I have updated the strings containing "CA private key".


Summary: Until (and unless) we do "the switch" I think the SelfSigned issuer type for CSRs provides no value to users. More pertinently: before "the switch", I think everyone who even thinks about using a SelfSigned issuer with a CSR resource is almost certainly making a mistake and what they actually want is a CA issuer.

Adding support for SelfSigned - like any new code - increases the amount of code we have to maintain and test, and could risk us locking in design choices now which will be harder to change in the future.

Given all that, is it maybe worth considering shelving adding support for SelfSigned until we're ready to make "the switch"?

Whilst I understand the sentiment, we should still add support for this Issuer since having full coverage of all Issuer types is the target.

I disagree that adding this code is more arduous since it has units tests and is well contained. This PR moves to a conformance e2e testing strategy similar to Certificates which makes testing different issuers easy to add. I also don't think we should be too concerned with locking in the design since it follows the same design as CR's.

I'd rather merge this sooner rather than merging it later.

@SgtCoDFish

Copy link
Copy Markdown
Member

/lgtm

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 15, 2021
@jetstack-bot
jetstack-bot merged commit 91540b1 into cert-manager:master Jun 15, 2021
@jetstack-bot jetstack-bot modified the milestones: Next, v1.4 Jun 15, 2021
@JoshVanL JoshVanL modified the milestones: v1.4, v1.5 Jun 15, 2021
@maelvls maelvls mentioned this pull request Jun 26, 2021
13 tasks done
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 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. 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.

6 participants