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

Make CA valid 1 hour in the past #118631

Merged
merged 1 commit into from Jun 15, 2023
Merged

Conversation

champtar
Copy link
Contributor

@champtar champtar commented Jun 13, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

When running kubeadm / installing k8s early during boot, the CA certificate can be generated before time is synchronised and time is jumped backward.
Make notBefore 1 hour in the past to accept small clock jump.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/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 Jun 13, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot
Copy link
Contributor

Hi @champtar. Thanks for your PR.

I'm waiting for a kubernetes 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.

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.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jun 13, 2023
When running kubeadm / installing k8s early during boot,
the CA certificate can be generated before time is synchronised
and time is jumped backward.
Make notBefore 1 hour in the past to accept small clock jump.

Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 13, 2023
@alexzielenski
Copy link
Contributor

/sig auth
/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 13, 2023
@champtar
Copy link
Contributor Author

Should we add area/kubeadm and sig/cluster-lifecycle ? The only usage of NewSelfSignedCACert() outside of tests is cmd/kubeadm/app/util/pkiutil/pki_helpers.go

@dims
Copy link
Member

dims commented Jun 15, 2023

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe 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 15, 2023
@dims
Copy link
Member

dims commented Jun 15, 2023

/assign @neolit123

@neolit123
Copy link
Member

for context, we had a related duscussion in the past
#76714

IMO, if we are changing notBefore for CA certs, with one hour padding we should also do it for other certs. @champtar WDYT?

Should we add area/kubeadm and sig/cluster-lifecycle ? The only usage of NewSelfSignedCACert() outside of tests is cmd/kubeadm/app/util/pkiutil/pki_helpers.go

the k/k usage may only be by kubeadm, but there could be other external direct users of client go.

@champtar
Copy link
Contributor Author

for context, we had a related duscussion in the past #76714

IMO, if we are changing notBefore for CA certs, with one hour padding we should also do it for other certs. @champtar WDYT?

This is the only place in k/k where NotBefore == time.Now()

$ git grep 'CreateCertificate(' | grep -v test
cmd/kubeadm/app/util/pkiutil/pki_helpers.go:	certDERBytes, err := x509.CreateCertificate(cryptorand.Reader, &certTmpl, caCert, key.Public(), caKey)
pkg/controller/certificates/authority/authority.go:	der, err := x509.CreateCertificate(rand.Reader, tmpl, ca.Certificate, cr.PublicKey, ca.PrivateKey)
staging/src/k8s.io/client-go/util/cert/cert.go:	certDERBytes, err := x509.CreateCertificate(cryptorand.Reader, &tmpl, &tmpl, key.Public(), key)
staging/src/k8s.io/client-go/util/cert/cert.go:	caDERBytes, err := x509.CreateCertificate(cryptorand.Reader, &caTemplate, &caTemplate, &caKey.PublicKey, caKey)
staging/src/k8s.io/client-go/util/cert/cert.go:	derBytes, err := x509.CreateCertificate(cryptorand.Reader, &template, caCertificate, &priv.PublicKey, caKey)
vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener.go:	derBytes, err := x509.CreateCertificate(rand.Reader, &tmpl, &tmpl, &priv.PublicKey, priv)

In the kubeadm case NotBefore == ca.NotBefore

NotBefore: caCert.NotBefore,

In pkg/controller/certificates/authority there is already some backdate logic

tmpl.NotBefore = now.Add(-p.Backdate)

In client-go in GenerateSelfSignedCertKeyWithFixtures() there is already -1hour (that's why I picked 1h)

func GenerateSelfSignedCertKeyWithFixtures(host string, alternateIPs []net.IP, alternateDNS []string, fixtureDirectory string) ([]byte, []byte, error) {
validFrom := time.Now().Add(-time.Hour) // valid an hour earlier to avoid flakes due to clock skew

Should we add area/kubeadm and sig/cluster-lifecycle ? The only usage of NewSelfSignedCACert() outside of tests is cmd/kubeadm/app/util/pkiutil/pki_helpers.go

the k/k usage may only be by kubeadm, but there could be other external direct users of client go.

Good point, if we want to be safe I can introduce a new function that take NotBefore as parameter and not change the behavior for everyone, please tell me what is preferred

@neolit123
Copy link
Member

thanks for the info.

In client-go in GenerateSelfSignedCertKeyWithFixtures() there is already -1hour (that's why I picked 1h)

+1 given we already have this in other places and it was discussed before.

Good point, if we want to be safe I can introduce a new function that take NotBefore as parameter and not change the behavior for everyone, please tell me what is preferred

unclear what is better. likely the -1h padding without opt-out is fine. i can lgtm, but approval is up to api machinery (owners of client go).

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 15, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 468ef00647a9d69239999ddfd3b63cb304100524

@neolit123
Copy link
Member

/release-note-edit

client-go: make generated CA certificates valid 1 hour in the past (NewSelfSignedCACert). Applies to CA certificates and other certificates generated by kubeadm.

owners: please adjust the note if needed

@dims
Copy link
Member

dims commented Jun 15, 2023

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: champtar, dims

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 Jun 15, 2023
@k8s-ci-robot k8s-ci-robot merged commit 604584d into kubernetes:master Jun 15, 2023
12 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Jun 15, 2023
@champtar champtar deleted the ca-not-before branch June 15, 2023 20:21
@aojea
Copy link
Member

aojea commented Jun 26, 2023

This function is exported from client-go, is this really safe to do?

@neolit123
Copy link
Member

neolit123 commented Jun 26, 2023

This function is exported from client-go, is this really safe to do?

i think the change is fine based on prior discussions.
#76714 (comment)
but as i noted earlier api machinery should take a look.

@champtar , your backports state "feature". we don't backport features per se. usually it has to be a blocking bug fix..

@champtar
Copy link
Contributor Author

@champtar , your backports state "feature". we don't backport features per se. usually it has to be a blocking bug fix..

I just copied the kind/feature from this PR.

It's blocking for my use case because I want to start as fast as possible, so before time sync, and the install fails if there is a time jump just after certificate generation, and I don't have a workaround except this PR.
So it's a blocking bug fix for me, but for k8s is it a bug fix ?

@neolit123
Copy link
Member

neolit123 commented Jun 26, 2023

It's blocking for my use case because I want to start as fast as possible, so before time sync, and the install fails if there is a time jump just after certificate generation, and I don't have a workaround except this PR.

a slightly involved workaround for kubeadm would be to sign your own CA/certs/keys.

So it's a blocking bug fix for me, but for k8s is it a bug fix ?

i think the client-go owners should take a look at this PR and the backports.

EDIT: you can ping #sig-api-machinery on k8s slack.

@champtar
Copy link
Contributor Author

It's blocking for my use case because I want to start as fast as possible, so before time sync, and the install fails if there is a time jump just after certificate generation, and I don't have a workaround except this PR.

a slightly involved workaround for kubeadm would be to sign your own CA/certs/keys.

openssl doesn't provide an easy way to put the not before time in the past, my simplest workaround involved using faketime + openssl and some certificates templates, but that's seemed a lot compared to a 1 line change

So it's a blocking bug fix for me, but for k8s is it a bug fix ?

i think the client-go owners should take a look at this PR and the backports.

EDIT: you can ping #sig-api-machinery on k8s slack.

Will do, thanks

@aojea
Copy link
Member

aojea commented Jun 26, 2023

/assign @enj @deads2k @jpbetz

This is exposed and used in more places that kubeadm , it will be better if both sig-auth and sig-apimachinery sign on this and on the backports to be completely sure and have consensus

@champtar
Copy link
Contributor Author

@neolit123
Copy link
Member

/release-note-none

@k8s-ci-robot
Copy link
Contributor

@neolit123: you can only set the release note label to release-note-none if the release-note block in the PR body text is empty or "none".

In response to this:

/release-note-none

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.

@neolit123
Copy link
Member

/release-note-edit

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jun 27, 2023
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

9 participants