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

✨ secret: Add generator for etcd client certs #2029

Closed

Conversation

randomvariable
Copy link
Member

What this PR does / why we need it:
Adds a generator for etcd client certificates for use by the control plane controller to connect into the workload cluster's etcd endpoint.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of #1902

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 9, 2020
@randomvariable
Copy link
Member Author

/assign @dlipovetsky

@randomvariable randomvariable changed the title secret: Add generator for etcd client certs ✨ secret: Add generator for etcd client certs Jan 9, 2020
Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

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

couple of logic questions around the case statement.

util/secret/certificates.go Outdated Show resolved Hide resolved
util/secret/certificates.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 9, 2020
util/secret/certificates.go Outdated Show resolved Hide resolved
util/secret/certificates.go Outdated Show resolved Hide resolved
@randomvariable randomvariable force-pushed the etcd-cert-gen branch 3 times, most recently from e09ecd1 to 9ea2265 Compare January 9, 2020 16:04
Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

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

🙏 thank you for adding this!

/approve

util/secret/certificates.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chuckha, randomvariable

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

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 9, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 9, 2020
@randomvariable
Copy link
Member Author

/hold
one final thing

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 9, 2020
Signed-off-by: Naadir Jeewa <jeewan@vmware.com>
@randomvariable
Copy link
Member Author

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 9, 2020
@@ -215,10 +232,11 @@ func (c Certificates) Generate() error {
continue
case ServiceAccount:
generator = generateServiceAccountKeys
case ClusterAPIEtcdClient: // Depends on the etcd CA, so needs to be handled separately
Copy link
Contributor

Choose a reason for hiding this comment

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

I found the Generate hard to understand; good candidate for a refactor in the future, I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's painful/very organic.

CommonName: cfg.CommonName,
Organization: cfg.Organization,
},
NotBefore: now.Add(time.Minute * -5),
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever way to handle potential clock drift between management cluster and target host 😄

Organization: cfg.Organization,
},
NotBefore: now.Add(time.Minute * -5),
NotAfter: now.Add(time.Hour * 24 * 365 * 10), // 10 years
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth defining as a constant somewhere?

Off-topic thought: I don't think we support user-defined expiration in general, but it might be a nice feature

Copy link
Contributor

Choose a reason for hiding this comment

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

I see we define this in line here:

NotAfter: now.Add(time.Hour * 24 * 365 * 10), // 10 years

Copy link
Member

Choose a reason for hiding this comment

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

+1 for consts

Copy link
Member Author

Choose a reason for hiding this comment

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

+100

now := time.Now().UTC()

tmpl := x509.Certificate{
SerialNumber: new(big.Int).SetInt64(0),
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be pedantic...

The serial number MUST be a positive integer assigned by the CA to
each certificate. It MUST be unique for each certificate issued by a
given CA (i.e., the issuer name and serial number identify a unique
certificate). CAs MUST force the serialNumber to be a non-negative
integer.

-- https://tools.ietf.org/html/rfc3280#section-4.1.2.2

If we fix this, we could also fix it here:

SerialNumber: new(big.Int).SetInt64(0),

Copy link
Member Author

Choose a reason for hiding this comment

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

It looked wrong to me, but I didn't think to question it further.

@randomvariable
Copy link
Member Author

The comments on this suggest it might as well be refactored now, and verified against the spec.

I'm going to close for the moment, and make sure this works with downstream consumption before reopening.

@randomvariable
Copy link
Member Author

/close

@k8s-ci-robot
Copy link
Contributor

@randomvariable: Closed this PR.

In response to this:

/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/test-infra repository.

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants