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

enable kubelet server to dynamically load tls certificate files #124574

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

zhangweikop
Copy link

@zhangweikop zhangweikop commented Apr 26, 2024

What type of PR is this?

/kind bug
/kind feature

What this PR does / why we need it:

It enable kubelet tls server to watch and reload certificate files.

In our kubelet deployment, we don't use ServerTLSBootstrap or let kubelet to create a self-signed cert.
We have other mechanism (based on internal PKI & CA) to generate and rotate the certificate files for kubelet on each host.

Therefore, we want that kubelet TLS (both client and server side) can handle the certificate update. This feature is important for us when we start generating short shorter-lived certificates for kubelet

Currently in Kubelet:

  • The client side TLS has been handling the certificate reload very well thanks to the client-go.
    In our testing, the kubelet -> API server requests never encountered issues. The pod can be deployed and started correctly on the host after the kubelet certificate file expired and then regenerated.
  • But the server side TLS doesn't have auto-reload. Therefore, the https requests to kubelet (such as access container kubectl log or kubectl exec) would fail with following error message if the certificate loaded in kubelet server TLSconfig expired.
Error from server: Get "https://<...hostname>.com:20250/containerLogs/....: x509: certificate has expired or is not yet valid: current time 2024-04-24T00:11:34Z is after 2024-04-12T00:52:35Z

Special notes for your reviewer:

  1. The logic is expressed as a certificate.Manager so that it could be used similarly to other struct in pkg/kubelet/certificate/kubelet.go.
  2. The internal file watch and read implementation is based on DynamicCertKeyPairContent struct in k8s.io/apiserver/pkg/server/dynamiccertificates.

Does this PR introduce a user-facing change?

kubelet server can now dynamically load certificate files

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. kind/feature Categorizes issue or PR as related to a new feature. labels Apr 26, 2024
Copy link

linux-foundation-easycla bot commented Apr 26, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Apr 26, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @zhangweikop!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 26, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @zhangweikop. 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 needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubelet sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 26, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 26, 2024
@kannon92
Copy link
Contributor

/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 Apr 26, 2024
@kannon92
Copy link
Contributor

I would suggest taking this feature to sig-auth.

@kannon92
Copy link
Contributor

/remove-kind bug

@k8s-ci-robot k8s-ci-robot removed the kind/bug Categorizes issue or PR as related to a bug. label Apr 26, 2024
@bart0sh bart0sh added this to Triage in SIG Node PR Triage Apr 27, 2024
@bart0sh
Copy link
Contributor

bart0sh commented Apr 29, 2024

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 29, 2024
@bart0sh bart0sh moved this from Triage to Needs Reviewer in SIG Node PR Triage Apr 29, 2024
@enj
Copy link
Member

enj commented Apr 30, 2024

2. The internal file watch and read implementation is based on DynamicCertKeyPairContent struct in k8s.io/apiserver/pkg/server/dynamiccertificates.

I would expect that logic to be re-used, not copied.

@enj
Copy link
Member

enj commented Apr 30, 2024

  1. The internal file watch and read implementation is based on DynamicCertKeyPairContent struct in k8s.io/apiserver/pkg/server/dynamiccertificates.

I would expect that logic to be re-used, not copied.

Sorry, ignore me, I read the description without reading the code. I see that the code is re-used.

pkg/kubelet/certificate/kubelet.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
pkg/kubelet/kubelet.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zhangweikop
Once this PR has been reviewed and has the lgtm label, please assign derekwaynecarr for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

pkg/kubelet/certificate/kubelet.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
Copy link
Member

@enj enj left a comment

Choose a reason for hiding this comment

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

Minor comments.

This LGTM from an auth perspective.

I will defer to SIG node to determine if they are happy with the code, and if this change requires a feature gate / if that gate should be enabled or disabled by default.

pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
pkg/kubelet/certificate/kubelet_test.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubelet 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/node Categorizes an issue or PR as relevant to SIG Node. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Changes Requested
SIG Node PR Triage
Needs Reviewer
Development

Successfully merging this pull request may close these issues.

None yet

5 participants