Skip to content

Add cfssl issuer#665

Closed
badie wants to merge 2 commits intocert-manager:masterfrom
autonomic-ai:master
Closed

Add cfssl issuer#665
badie wants to merge 2 commits intocert-manager:masterfrom
autonomic-ai:master

Conversation

@badie
Copy link
Copy Markdown
Contributor

@badie badie commented Jun 18, 2018

What this PR does / why we need it:

It adds support for a cfssl issuer to allow issuing certs from a cfssl based CA.

Release note:

Add support for CFSSL issuers

@jetstack-bot jetstack-bot added 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. labels Jun 18, 2018
@jetstack-bot jetstack-bot requested a review from wallrj June 18, 2018 16:46
@jetstack-bot jetstack-bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 18, 2018
@munnerz
Copy link
Copy Markdown
Member

munnerz commented Jun 18, 2018

/ok-to-test

@jetstack-bot jetstack-bot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 18, 2018
)

// Lister is a struct that implements kubernetes api secrets.SecretLister interface
// It is used solely for testing to mock calls to list secrets
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.

So client-go already has fairly extensive lister testing capabilities. I'd like to see us re-using these instead of creating our own 😄.

You can create a fake clientset using the fake sub-package of the client-go client (or our own clientset in pkg/client, if you need to test with cert-manager types).

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.

Same goes for basically this whole package 😄

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.

Makes sense. I'll reuse that package for the tests and delete this custom pkg


type CFSSLCertificateKeyConfig struct {
Size int `json:"size"`
Algo string `json:"algo"`
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.

These fields should be removed in favour of generic fields on the Certificate itself that apply to all issuer types (and not just specific to individual issuers).

As we do not currently support all of these fields in the spec (although there is some pre-existing work to add support), we should simply omit them for now and hardcode values (similar to how the other issuers currently do it). I think the majority of the algorithm and size selection is now handled in the pkg/utils/pki package now, anyway 😄

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.

@munnerz Thanks for the recommendation. It makes sense to have generic fields on the certificate thats not specific to any issuer.

I created a PR to add fields to Certificate spec and add helper functions to pki package for generating private keys #722

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.

Once that PR #722 is reviewed, I'll change this PR to use it.

CommonName: pki.CommonNameForCertificate(crt),
},
DNSNames: pki.DNSNamesForCertificate(crt),
}
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.

There is a new function in the pki package to handle this now.

return nil, fmt.Errorf("error building request body: %s", err)
}

issuerSpec := c.issuer.GetSpec().CFSSL
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.

It should never be the case that this is nil, but worth double checking in case (and just returning an unexpected error or something if it is). Better weird errors than panics 😄

return []byte(certificate.(string)), nil
}

func (c *CFSSL) buildRequestBody(csrPem []byte) ([]byte, error) {
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.

Let's make csrPem type-safe and accept a *x509.CertificateRequest here - we can perform encoding at the time then.

authKeySecret := c.issuer.GetSpec().CFSSL.AuthKey
if authKeySecret == nil {
return requestBytes, nil
}
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.

Could you add a comment to clarify why we return early if authKeySecret is nil 😄

}

h := hmac.New(sha256.New, []byte(hexAuthKey))
h.Write(requestBytes)
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.

missing err check

keyAlgo: ecdsaKeyAlgo,
keySize: ecdsaKeySize,
expectedCrt: certStr,
expectedRespBody: fmt.Sprintf(`{"success":true,"result":{"certificate":"%s"}}`, certStr),
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.

this test case says it should fail, but this response includes success? 🤔


return ecdsa.GenerateKey(ecCurve, rand.Reader)
}

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.

The addition of EC keys is great, but can this be extracted out into a separate PR? It will take additional work to support this for all Issuer types.

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.

Cool. I've extracted this work to PR #722

f := framework.NewDefaultFramework("create-cfssl-issuer")

issuerName := "test-cfssl-issuer"
serverURL := "http://local.cfssl.server"
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.

How does this work? 🤔

@jetstack-bot jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 18, 2018
@jetstack-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: munnerz

If they are not already assigned, you can assign the PR to them by writing /assign @munnerz in a comment when ready.

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 removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 20, 2018
@badie badie force-pushed the master branch 4 times, most recently from 4578002 to 8f27756 Compare July 22, 2018 02:22
@badie
Copy link
Copy Markdown
Contributor Author

badie commented Jul 24, 2018

/ping @munnerz

Please review when you get a chance to. I'd like to get this going and hopefully accepted and merged by the next release 🙂

@badie badie force-pushed the master branch 3 times, most recently from 7a33cd8 to b836360 Compare July 30, 2018 03:26
@jetstack-bot
Copy link
Copy Markdown
Contributor

@badie: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
cert-manager-chart-verify 163324c link /test chart-verify
cert-manager-e2e-v1-8 163324c link /test e2e v1.8
cert-manager-e2e-v1-9 163324c link /test e2e v1.9
cert-manager-e2e-v1-7 163324c link /test e2e v1.7

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 jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 8, 2018
@jetstack-bot
Copy link
Copy Markdown
Contributor

@badie: 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.

@badie badie closed this Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.

3 participants