Restrict permissions on mounted secrets and generated key files - #238
Merged
Conversation
Set defaultMode 0440 on the bee-secret, bee-libp2p and bee-swarm secret volumes. Without it Kubernetes mounts them 0644, so the wallet password and key material carry a world-readable mode. podSecurityContext.fsGroup 999 keeps them readable by the bee process. Reorder the libp2p and swarm init containers to write the key file, chmod it 0600, and only then chown -R. Previously the chown ran before the file was written, so swarm.key and libp2p_v2.key persisted on the volume as root-owned and 0644. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Required by CI: ct lint enforces a version increment for changed charts. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related file-permission fixes in the
beechart'sstatefulset.yaml.1. Secret volumes mounted
0644The
bee-secret,bee-libp2pandbee-swarmsecret volumes specify nodefaultMode, so Kubernetes mounts them0644— a world-readable mode on the wallet password and key material. This setsdefaultMode: 0440.This is safe because
podSecurityContext.fsGroup: 999(charts/bee/values.yaml, lines 29-30) makes the filesroot:999 r--r-----, and bee runs as gid 999, so it can still read them.Caveat worth flagging: anyone overriding
podSecurityContextto dropfsGroupwhile running bee as non-root would need to adjust this, otherwise the process loses read access to its own password file.Checked against a fleet of ~45 live deployments of this chart: all of them run with
podSecurityContext.fsGroup: 999and currently mountbee-secretatdefaultMode: 420(decimal — i.e.0644, the Kubernetes default). Tightening to0440therefore leaves the file readable by bee via gid 999 in every one of them.Scope note: the proxy sidecars do not currently mount these volumes, so this is defense in depth rather than a closed hole — it removes the world-readable mode so that any container that does mount the volume cannot read the material regardless of the UID it runs as.
2. Generated key files persist as
root:root 0644The libp2p and swarm init containers run
chown -R 999:999 /home/bee/.bee/keys;before the key file is written. The result is that
swarm.keyandlibp2p_v2.keyland on the PVC asroot:root 0644— world-readable, and not even owned by the bee user thechownwas meant to give them to.Reordered to write →
chmod 600→chown -R, with the chown preserved on the early-exit path when no key is mapped.This affects clusters that enable
swarmSettings/libp2pSettings. On those, existing key files already on disk keep their current mode until the init container rewrites them.Testing caveat, stated plainly: these init containers are not rendered in any of our own deployments (we run with
swarmSettings/libp2pSettingsdisabled), so this second change has not been exercised against a running deployment on our side. It is verified by template rendering andsh -nonly.Testing
sh -n(both init containers).helm lint charts/beepasses.helm templaterenders cleanly, both with defaults and withlibp2pSettings.enabled=true/swarmSettings.enabled=true.0.17.3→0.17.4, asct lintrequires a version increment for changed charts.sh -nonly.🤖 Generated with Claude Code