Skip to content

Fix credential exposure in kubeconfig file permissions, azcmagent argv, and log file handling#145

Merged
bcho merged 3 commits intomainfrom
hbc/fix-medium-findings
Apr 17, 2026
Merged

Fix credential exposure in kubeconfig file permissions, azcmagent argv, and log file handling#145
bcho merged 3 commits intomainfrom
hbc/fix-medium-findings

Conversation

@bcho
Copy link
Copy Markdown
Member

@bcho bcho commented Apr 16, 2026

Summary

  • Restrict kubelet kubeconfig and bootstrap-kubeconfig file permissions from 0644 to 0600
  • Document ARM access token /proc/cmdline exposure as a known limitation of azcmagent
  • Remove chmod 666 log file fallback — open with 0600 and fail on error

Kubelet kubeconfig file permissions (kubelet_config.go)

ensureKubeletKubeconfig() and ensureBootstrapKubeconfig() wrote credential-bearing files with mode 0644 (world-readable). In SP mode the kubeconfig embeds AZURE_CLIENT_SECRET in the exec env block; in bootstrap-token mode it contains the raw <id>.<secret> token. Changed both to 0600, matching the kubeadm code path (components/kubeadm/v20260301/join.go) and CIS Kubernetes Benchmark 4.1.5/4.1.9.

ARM token on azcmagent command line (arc_registration.go)

addAuthenticationArgs() passes --access-token <jwt> on the command line, making the token visible via /proc/<pid>/cmdline to all local users. After researching the azcmagent connect docs, azcmagent does not support reading the token from stdin or environment variables — --access-token on argv is the only option. The token is short-lived (~60 minutes) which limits the exposure window. Added a TODO documenting this limitation and a follow-up to investigate whether azcmagent can discover auth settings on its own (e.g. --use-azcli or VM MSI) to avoid passing tokens on the command line entirely.

Log file permission fallback (logger.go)

When opening the log file hit EACCES, the agent ran chmod 666 to make it world-writable. Since the agent runs as root, this fallback was both unnecessary and insecure. Removed the workaround entirely — now opens with 0600 and returns the error on failure.

Kubeconfig files contain sensitive credentials (AZURE_CLIENT_SECRET in SP mode,
bootstrap token in bootstrap-token mode). Writing them world-readable (0644)
allowed any local user or hostPath-mounted container to read them. Changed to
0600 to match CIS Kubernetes Benchmark 4.1.5/4.1.9 and the kubeadm code path
which already uses 0600.
Comment thread pkg/logger/logger.go Fixed
Comment thread pkg/logger/logger.go Fixed
Comment thread pkg/logger/logger.go Fixed
Comment thread pkg/logger/logger.go Fixed
@bcho bcho force-pushed the hbc/fix-medium-findings branch from 8437905 to 62cc6d1 Compare April 16, 2026 23:10
Comment thread pkg/logger/logger.go Fixed
Comment thread pkg/logger/logger.go Fixed
@bcho bcho force-pushed the hbc/fix-medium-findings branch from 62cc6d1 to c79164a Compare April 17, 2026 00:21
azcmagent only supports --access-token via argv, which exposes the token
through /proc/<pid>/cmdline to all local users. The token is short-lived
(~60 minutes) which limits the window, but it is still observable during
registration. Document this as a known limitation with a pointer to
alternative auth methods (service principal certificate, Azure CLI).
@bcho bcho force-pushed the hbc/fix-medium-findings branch from c79164a to 55bfa1c Compare April 17, 2026 00:38
@bcho bcho force-pushed the hbc/fix-medium-findings branch from 55bfa1c to c392f8e Compare April 17, 2026 00:39
@bcho bcho force-pushed the hbc/fix-medium-findings branch from c392f8e to 897e90b Compare April 17, 2026 00:43
@bcho bcho marked this pull request as ready for review April 17, 2026 00:44
Copilot AI review requested due to automatic review settings April 17, 2026 00:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to harden node security by reducing credential exposure vectors in kubelet kubeconfigs, Azure Arc registration, and agent log file handling.

Changes:

  • Tighten kubelet kubeconfig and bootstrap-kubeconfig permissions from 0644 to 0600.
  • Adjust Arc registration code around access-token handling (but the token is still passed via argv in the current diff).
  • Remove the prior log-file permission “fix” behavior and change the log open call (but the actual on-disk log file mode is still set at creation time elsewhere).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
components/kubelet/v20260301/kubelet_config.go Writes kubelet kubeconfig + bootstrap kubeconfig with 0600 to reduce credential exposure.
components/arc/v20260301/arc_registration.go Adds commentary/TODOs about argv token exposure; current code still appends --access-token to args.
pkg/logger/logger.go Removes chmod-based fallback and changes the OpenFile mode argument (though without O_CREATE, this won’t change file permissions).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread components/arc/v20260301/arc_registration.go
Comment thread pkg/logger/logger.go Outdated
@bcho bcho force-pushed the hbc/fix-medium-findings branch from 897e90b to 684618d Compare April 17, 2026 00:49
…back

The agent runs as root, so if it cannot open its own log file, chmod/chown
workarounds won't help — just fail. Removed the fallback that ran chmod 666
which made the log world-writable. Now opens with 0600 and returns the error
directly on failure.
Copilot AI review requested due to automatic review settings April 17, 2026 00:58
@bcho bcho force-pushed the hbc/fix-medium-findings branch from 684618d to a98c0c6 Compare April 17, 2026 00:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/logger/logger.go
Comment thread pkg/logger/logger.go
@bcho bcho merged commit dedca2f into main Apr 17, 2026
13 checks passed
@bcho bcho deleted the hbc/fix-medium-findings branch April 17, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants