Repository navigation
CKS: keep registry credentials out of node logs and safe from special characters - #14918
bhouse-nexthop wants to merge 1 commit into
Conversation
… characters
The private registry script on every node ran under bash -x, so the
registry user name and password, in plain text and base64, were written
to the cloud-init output log. The registry URL, user name and password
were also put into the cloud-config as they are: a quote, backslash, $
or newline broke the script or the cloud-config, and {{ or {% made
cloud-init fail to render the control node template, so it dropped the
whole cloud-config and the node was never set up.
Run the script without tracing. Pass the URL and its endpoint
base64-encoded and decode them in the script, and give containerd only
the base64 auth string instead of the user name and password, so no
character in them can change the cloud-config, the template or the
script. Make the script and the containerd config readable by root
only, as they hold the credentials. Refuse a registry URL that is not a
valid URI, such as one with double quotes, backslashes or spaces, which
would break the containerd config.
Signed-off-by: Brad House <bhouse@nexthop.ai>
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## 4.22 #14918 +/- ##
=============================================
- Coverage 18.34% 4.08% -14.26%
=============================================
Files 5939 449 -5490
Lines 537817 38282 -499535
Branches 65938 7083 -58855
=============================================
- Hits 98640 1564 -97076
+ Misses 427954 36503 -391451
+ Partials 11223 215 -11008
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Tested on a KVM lab with a main (24.0) build, first without and then with this change. Primary storage is Ceph RBD. The build also carries #14408 (so the control node gets the registry config too) and #14898 (the Once setup finished, every node was searched for the password, the base64
Runs without the change: the leak check passed 9 of 9 and the broken-URL check 10 of 10. Runs with the change: invalid URLs were refused in 2 of 2 runs (5 of 5 checks each), and the stacked etcd and external etcd clusters each passed 17 of 17. All clusters were deleted afterwards, and the test user was removed from the registry. Not tested: 4.22, where the base has no #14408 so the control node gets no registry config. Also not tested: a registry over HTTPS, and the external etcd node itself, which gets no registry config. |
Description
With a private registry, every CKS node ran its registry script as
bash -x /opt/bin/setup-containerd, so theregistry user name and password, in plain text and as the base64 auth string, were written to
/var/log/cloud-init-output.logon every worker and control node. The URL, user name and password were alsosubstituted into the cloud-config as plain text: a double quote, backslash,
$or newline broke the script or theYAML, and
{{or{%made cloud-init fail to render the control node template (it is a Jinja template), so itdropped the whole cloud-config and the control node was never set up.
Now:
-x. It prints its own progress lines, and the credentials are the reason it exists, sotracing it can't be made safe by turning tracing off around some lines.
password are no longer substituted at all: containerd gets only
auth = "<base64 of user:password>", which itreads the same way as the
username/passwordpair. No character in the values can change the cloud-config, theJinja template or the script.
/opt/bin/setup-containerdis 0700 and/etc/containerd/config.toml0600, as both hold the auth string.createKubernetesClusterrefuses a registry URL that is not a valid URI (double quotes, backslashes, whitespace),which would break the containerd config.
new URL()accepted them.Other secrets in the same templates, checked: the kubeadm join token and certificate keys are generated values with
safe characters and their scripts are not traced; the API server key is written 0600. Not changed.
Not changed here: on 4.22 the control node template only writes the registry script under
{% if registry is defined %}, which is never true, so the control node gets no registry (#14408 fixes that).Fixes: #14917
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
Unit tests in
KubernetesClusterActionWorkerTest, for the worker, control and added control node templates, with apassword containing
{{,{%, quotes, a backslash,$(...)and a newline and a URL with',$(...)and&: noplain value is left in the rendered cloud-config, the URL, endpoint and auth are there base64-encoded, the runcmd is
bash /opt/bin/setup-containerdwithout-x, and the script is 0700.KubernetesClusterManagerImplTest: the URLcheck refuses a double quote, a newline and a missing scheme.
mvn -pl plugins/integrations/kubernetes-service -am test: all tests pass.The rendered worker script was also run against a containerd 1.7 default config with those values: the resulting
config parses as TOML, the auth string decodes to the original user name and password, and the config is 0600.
A lab test on a KVM zone follows in a comment.