fix(use_api_socket): give each service its own credentials file mode
Some checks are pending
ci / validate (lint) (push) Waiting to run
ci / validate (relay-lint) (push) Waiting to run
ci / validate (relay-test) (push) Waiting to run
ci / validate (validate-docs) (push) Waiting to run
ci / validate (validate-go-mod) (push) Waiting to run
ci / validate (validate-headers) (push) Waiting to run
ci / validate (validate-mocks) (push) Waiting to run
ci / binary (push) Waiting to run
ci / binary-finalize (push) Blocked by required conditions
ci / bin-image-test (push) Waiting to run
ci / relay-image-test (push) Waiting to run
ci / test (push) Waiting to run
ci / e2e (plugin, oldstable, graphdriver) (push) Waiting to run
ci / e2e (standalone, oldstable, graphdriver) (push) Waiting to run
ci / e2e (plugin, stable, containerd) (push) Waiting to run
ci / e2e (plugin, stable, graphdriver) (push) Waiting to run
ci / e2e (standalone, stable, containerd) (push) Waiting to run
ci / e2e (standalone, stable, graphdriver) (push) Waiting to run
ci / coverage (push) Blocked by required conditions
ci / ci-ok (push) Blocked by required conditions
ci / release (push) Blocked by required conditions
merge / bin-image-prepare (push) Waiting to run
merge / bin-image (push) Blocked by required conditions
merge / relay-image (push) Waiting to run
merge / module-image (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
zizmor / zizmor (push) Waiting to run

The mode of the injected config file was declared once for the whole
project, so every service that received the credentials held a pointer to
the same value, and changing it for one would have changed it for all of
them. Nothing does that today, but the sharing is easy to trip on.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2026-10-29 22:15:39 +01:00 • committed by Nicolas De loof
parent 82d8bcb288
commit 5bceecf985
2 changed files with 20 additions and 2 deletions

View file

@ -99,8 +99,6 @@ func (s *composeService) useAPISocket(project *types.Project) (*types.Project, e
Content: configBuf.String(),
}
// like the file of the Docker CLI: readable by root only
mode := types.FileMode(0o600)
for name, service := range project.Services {
if !service.UseAPISocket {
continue
@ -119,6 +117,9 @@ func (s *composeService) useAPISocket(project *types.Project) (*types.Project, e
path := "/run/secrets/docker"
service.Environment["DOCKER_CONFIG"] = &path
// like the file of the Docker CLI: readable by root only. One mode
// per service, so that no service shares it with another.
mode := types.FileMode(0o600)
service.Configs = append(service.Configs, types.ServiceConfigObjConfig{
Source: apiSocketConfigName,
Target: "/run/secrets/docker/config.json",

View file

@ -121,6 +121,23 @@ func TestUseAPISocketCredentialsAreForRootOnly(t *testing.T) {
assert.Assert(t, project.Configs["#apisocket"].Content != "", "the config carries the credentials")
}
// TestUseAPISocketServicesDoNotShareTheirMode pins that each service gets its
// own mode: changing it for one must not change it for the others.
func TestUseAPISocketServicesDoNotShareTheirMode(t *testing.T) {
svc := newAPISocketTestService(t, hostRegistryConfig())
project, err := svc.useAPISocket(apiSocketProject(
apiSocketService("one", types.MappingWithEquals{}),
apiSocketService("two", types.MappingWithEquals{}),
))
assert.NilError(t, err)
one, two := project.Services["one"].Configs[0], project.Services["two"].Configs[0]
assert.Assert(t, one.Mode != two.Mode, "the services share the same mode pointer")
*one.Mode = 0o644
assert.Equal(t, *two.Mode, types.FileMode(0o600))
}
// TestUseAPISocketHonorsDockerConfig pins that a service which sets
// DOCKER_CONFIG itself gets the socket but no credentials, as with `docker run
// --use-api-socket`: it is taken to know where its credentials are, and its