fix(etcd): set correct permissions on certs generated on first etcd node - #13447
fix(etcd): set correct permissions on certs generated on first etcd node#13447mehrdadbn9 wants to merge 1 commit into
Conversation
|
Hi @mehrdadbn9. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mehrdadbn9 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
9149ffd to
5fd73d1
Compare
|
/ok-to-test |
There was a problem hiding this comment.
🟡 Changes recommended
The new file: loop can create empty cert/key files when a listed path doesn’t exist (e.g., node certs on a dedicated etcd host), and the proposed modes don’t currently match the existing copy-path behavior, so the “normalization” may still be inconsistent.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR addresses inconsistent ownership/permissions of etcd certificates on the first etcd node (the node where make-ssl-etcd.sh generates certs), so that jobs reading the certs (e.g., backups) behave consistently across all etcd nodes.
Changes:
- Adds a post-generation normalization task in
roles/etcd/tasks/gen_certs_script.ymlto set owner/group/mode for certs generated on the first etcd node.
File summaries
| File | Description |
|---|---|
| roles/etcd/tasks/gen_certs_script.yml | Adds a new task intended to normalize ownership/mode of generated etcd PKI artifacts on the first etcd node. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| - name: Gen_certs | Normalize permissions on generated etcd certs on first etcd node | ||
| file: | ||
| path: "{{ item.path }}" | ||
| owner: "{{ item.owner | default(etcd_owner) }}" | ||
| group: "{{ item.group | default(etcd_cert_group) }}" | ||
| mode: "{{ item.mode | default('0640') }}" | ||
| loop: | ||
| - { path: "{{ etcd_cert_dir }}/ca.pem", mode: "0644" } | ||
| - { path: "{{ etcd_cert_dir }}/ca-key.pem", mode: "0600" } | ||
| - { path: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem", mode: "0644" } | ||
| - { path: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem", mode: "0600" } | ||
| - { path: "{{ etcd_cert_dir }}/member-{{ inventory_hostname }}.pem", mode: "0644" } | ||
| - { path: "{{ etcd_cert_dir }}/member-{{ inventory_hostname }}-key.pem", mode: "0600" } | ||
| - { path: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}.pem", mode: "0644" } | ||
| - { path: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem", mode: "0600" } | ||
| delegate_to: "{{ groups['etcd'][0] }}" | ||
| run_once: true | ||
| when: | ||
| - gen_certs | ||
| - inventory_hostname == groups['etcd'][0] | ||
|
|
On the first etcd node, make-ssl-etcd.sh generates certs and moves them to the etcd cert dir with root:root ownership and umask-based permissions. Other nodes receive certs via the slurp/copy path with correct ownership and modes, so only the generating node ends up with wrong perms. Normalize the generated certs on the first etcd node: - public certs (ca, member-*, admin-*, node-* for control-plane hosts that generate certs): owner etcd, mode 0644 - private keys: same ownership, mode 0600 The stems are derived from groups['etcd'] and the intersection of gen_node_certs_True with kube_control_plane, matching exactly the hosts for which make-ssl-etcd.sh generates member/admin/node certs in this task file. Referencing node-<etcd-host> certs directly fails on topologies with separate etcd and control-plane nodes because those files are named after control-plane hosts. Fixes the CI failures on ubuntu24-ha-separate-etcd and ubuntu24-cilium-sep seen in the previous revision of this change. Signed-off-by: Mehrdad Biukian Naeini <mehrdadbiukian@gmail.com>
5fd73d1 to
e180f63
Compare
|
Root-caused the 2 CI failures (ubuntu24-ha-separate-etcd, ubuntu24-cilium-sep): the previous revision referenced node- The pushed revision derives the file list from the same group expressions the generator uses: member/admin for every etcd host, node-* for gen_node_certs_True ∩ kube_control_plane hosts, plus ca. Verified locally with ansible 2.16 against a separate-etcd topology (etcd1/etcd2 + cp1/cp2): certs land 0644, keys 0600, both tasks ok, and the absent-file case that broke CI is gone because the file list now matches exactly what the generator produces on that node. |
What type of PR is this?
/kind bug
What this PR does / why we need it
On the first etcd node,
make-ssl-etcd.shgenerates the etcd certs and moves them into/etc/ssl/etcdasroot:rootwith umask-based permissions (0600for keys,0644for certs). Every other etcd node receives the certs through the slurp/copy path with the correctetcd:${etcd_cert_group}ownership and0640mode, so only the generating node is inconsistent.This broke an etcd backup job running on the first control-plane node with a read-permission error (see issue for repro).
This PR adds one normalization task in
roles/etcd/tasks/gen_certs_script.ymlright after cert generation on the first etcd node. It sets the same owner/group and the same mode split the copy path already uses:0644for public certs (ca.pem, admin-.pem, member-.pem, node-*.pem)0600for private keys (*-key.pem)The task reuses
etcd_owner/etcd_cert_groupso behavior stays consistent with the copy tasks, and it only runs whengen_certsis true (generation happened).Which issue(s) this PR fixes
Fixes #13250
Special notes for your reviewer
delegate_to: "{{ groups['etcd'][0] }}"+run_once: true, so it runs exactly where the certs are generated.{{ inventory_hostname }}because that is how the generator names certs (same pattern as the slurp/copy tasks above).Does this PR introduce a user-facing change?