Repository navigation
cli/context/store: create directories with 0700 permissions - #7428
Open
StevenLi-phoenix wants to merge 1 commit into
Open
StevenLi-phoenix wants to merge 1 commit into
StevenLi-phoenix wants to merge 1 commit into
Conversation
The config-file writer creates the config directory (~/.docker) with 0700 permissions, but the context store created its directories with 0755. Depending on which command ran first (for example, running "docker context create" when ~/.docker did not exist yet), the config directory itself was created with 0755 permissions. Create the metadata directories with 0700 permissions, and remove the step that created the parent of the TLS store with 0755 permissions before creating the TLS directories; os.MkdirAll creates any missing parent directories with the same (0700) permissions. Existing directories are not modified. Co-authored-by: Claude Opus-5-5 <[email protected]> Signed-off-by: Steven Li <[email protected]>
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.
Summary
The config-file writer creates the CLI config directory (
~/.docker) with0700permissions (cli/config/configfile/file.go), but the context store created its directories with0755. If a context command ran before anything had saved the config file, for exampledocker context createwhen~/.dockerdid not exist yet, then~/.dockeritself and thecontexts,contexts/metaandcontexts/meta/<id>directories were created with0755:The TLS store had the same problem. It first created the parent of its root (
~/.docker/contexts, and~/.dockerif missing) with0755, and then created the TLS directories themselves with0700.This PR:
metadatastore.go: creates the metadata directories with0700(was0755).tlsstore.go: removes theos.MkdirAll(parentOfRoot, 0o755)step. Its only effect was to create the parent directories with more permissive permissions than the TLS directories. Theos.MkdirAll(endpointDir, 0o700)that follows already creates any missing parent directories with0700.With this change, the same command creates every directory with
drwx------, also when the context has TLS material. The TLS directories and files keep the0700/0600permissions they already had.Notes:
os.MkdirAlldoes not modify directories that already exist. Only newly created directories are affected.meta.jsonis still written with0644. I left it unchanged to keep this PR to the directories the issue is about. The directories that contain it are now0700.cli/manifest/storealso creates its directories under~/.docker/manifestswith0755, sodocker manifest createcan still create a missing~/.dockerwith0755. I left it out of this PR because the issue and discussion are about the context store. I can include it here or in a follow-up if you want.Tests:
Added
TestMetadataCreateDirectoryPermissionsandTestTlsCreateDirectoryPermissions. Each creates a store rooted under a.dockerdirectory that does not exist yet, writes one entry, and checks that every directory on the path, including.docker, has mode0700. They are skipped on Windows.Without the fix (umask 022), both tests fail:
With the fix, both pass.
Commands run on macOS arm64 with go1.26.10:
scripts/with-go-mod.sh go test ./cli/context/... ./cli/command/context/...: passscripts/with-go-mod.sh go test $(go list ./... | grep -vE '/vendor/|/e2e/|/cmd/docker-trust')(themake test-unitpackage set): passgolangci-lint run ./cli/context/...(v2.10.1, the version pinned indockerfiles/Dockerfile.lint): 0 issues.golangci-lint fmt --diff(gofumpt, goimports): no changes.GOOS=windows go test -c ./cli/context/store/: compilesManual check: I built
./cmd/dockerand randocker context create(with and withoutca=) against a freshDOCKER_CONFIG. Before the fix:cfg,contexts,contexts/metaandcontexts/meta/<id>weredrwxr-xr-x. After the fix: all directories aredrwx------.Release notes (optional)