fix(cmd): write k6 config with owner-only permissions (0o600/0o700) - #6011
Merged
Merged
Conversation
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.
What?
The on-disk k6 config file (default
~/.config/k6/config.json) can contain the Grafana Cloud API token undercollectors.cloud.token, persisted byk6 cloud loginand read back byk6 cloud run,k6 cloud test, and the launcher's build-service auth. It was previously written with mode 0o644 inside a directory created with mode 0o755, leaving the token readable by any other local user on shared hosts (CI runners, multi-user dev boxes, sidecar containers, container images that bake in $HOME) — an attacker could lift the token and impersonate the user against Grafana Cloud.Tighten the modes to 0o600 for the file and 0o700 for the directory. afero's WriteFile and MkdirAll don't change permissions on pre-existing paths, so an explicit Chmod is performed after each, so existing installs are upgraded the next time writeDiskConfig runs (e.g. the next
k6 cloud login). The modes are exposed as named constants (configFileMode, configDirMode) so the policy is documented in one place.Add regression tests covering both the fresh-install case and the upgrade path (pre-existing 0o644 file / 0o755 directory get tightened on the next write).
Checklist
make check) and all pass.