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

feature: Enable configuration of Kubelet TLS certs #2536

Merged
merged 1 commit into from
Nov 3, 2022

Conversation

stmcginnis
Copy link
Contributor

@stmcginnis stmcginnis commented Oct 29, 2022

Issue number:

Closes #2481

Description of changes:

This enables the ability to provide a TLS public and private key to be used by the kubelet process for HTTPS communication.
It adds settings.kubernetes.server-certificate and settings.kubernetes.server-key.

This corresponds to the --tls-cert-file and --tls-key-file arguments (or the tlsCertFile and tlsPrivateKeyFile config settings).

Testing done:

Generated an x509 public and private pair.
Used sample eksctl yaml and added the two new settings with the base64 contents of the generated certs.
Deployed cluster and verified creation successful.
Checked contents of generated /etc/kubernetes/kubelet/config file were correct.
cat'd contents of the two certificate files written out and made sure they matched my local copies of them.
Checked systemctl status kubelet and verified service was running and happy.
Checked journalctl -u kubelet to check if there were any errors.
Checked output from kubectl get pods -A and kubectl get nodes to make sure cluster was functional.

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@stmcginnis stmcginnis marked this pull request as draft October 29, 2022 02:07
@stmcginnis stmcginnis marked this pull request as ready for review October 29, 2022 14:44
Copy link
Contributor

@etungsten etungsten left a comment

Choose a reason for hiding this comment

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

We're missing a migration for the newly added settings. We need to migrate with the AddSettingsMigration helper.

Release.toml Outdated Show resolved Hide resolved
packages/kubernetes-1.24/kubelet-config Outdated Show resolved Hide resolved
Copy link
Contributor

@etungsten etungsten left a comment

Choose a reason for hiding this comment

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

packages/kubernetes-1.24/kubernetes-tls-crt Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
packages/kubernetes-1.21/kubelet-config Outdated Show resolved Hide resolved
packages/kubernetes-1.21/kubelet-config Show resolved Hide resolved
Comment on lines 104 to 105
install -m 0644 %{S:11} %{buildroot}%{_cross_templatedir}/kubernetes-tls-crt
install -m 0644 %{S:12} %{buildroot}%{_cross_templatedir}/kubernetes-tls-private-crt
Copy link
Contributor

Choose a reason for hiding this comment

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

You might also consider rendering both the certificate and the key to a single templated file, e.g. /etc/kubernetes/pki/kubelet-server-current.pem, the way that the combined client / server files are today under /var/lib/kubelet/pki.

@stmcginnis stmcginnis force-pushed the kubelet-certs branch 2 times, most recently from 7d184a4 to cbc16f3 Compare November 2, 2022 23:13
@@ -113,7 +113,12 @@ featureGates:
CSIMigration: false
protectKernelDefaults: true
serializeImagePulls: false
{{#if (and (default "" settings.kubernetes.tls-certificate) (default "" settings.kubernetes.tls-private-key))}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not too happy about this, but without the defaults in there the rendering of the file blows up with a handlebars error:

helper: Couldn't read parameter x

If anyone knows of a better way, please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could also do nested unless, e.g.

Suggested change
{{#if (and (default "" settings.kubernetes.tls-certificate) (default "" settings.kubernetes.tls-private-key))}}
{{#unless settings.kubernetes.tls-certificate}}
{{#unless settings.kubernetes.tls-private-key}}
serverTLSBootstrap: {{settings.kubernetes.server-tls-bootstrap}}
{{/unless}}
{{/unless}}

I wouldn't call it "better", just "different" - and reminiscent of C ifdef nesting, which is probably why it comes to mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would still need the if conditional to determine whether to write out of the tlsCert and tlsPrivateKeyFile though, right? So the double unless would work to determine if we need to write out serverTLSBootstrap, but we also need to know when to do the inverse.

@stmcginnis
Copy link
Contributor Author

Rebased on develop to resolve merge conflicts.

packages/kubernetes-1.21/kubelet-config Outdated Show resolved Hide resolved
packages/kubernetes-1.21/kubernetes-1.21.spec Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
sources/models/src/lib.rs Outdated Show resolved Hide resolved
This enables the ability to provide a TLS public and private key to be
used by the kubelet process for HTTPS communication.

This corresponds to the `--tls-cert-file` and `--tls-key-file`
arguments (or the `tlsCertFile` and `tlsPrivateKeyFile` config
settings).

Signed-off-by: Sean McGinnis <stmcg@amazon.com>
@stmcginnis stmcginnis self-assigned this Nov 3, 2022
@stmcginnis stmcginnis added this to the 1.11.0 milestone Nov 3, 2022
@stmcginnis stmcginnis merged commit a5a4135 into bottlerocket-os:develop Nov 3, 2022
@stmcginnis stmcginnis deleted the kubelet-certs branch November 3, 2022 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Configure kubelet parameters via BR API
3 participants