The docker stack deploy command does not mount secrets correctly when a service spec is overridden
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
Description
When using docker stack deploy with multiple compose files overriding the same service spec, the secrets defined in the base spec are munged, at least in the case where the same secret (eg - foobar) is mounted to multiple target locations (ie - foobar --> /run/secrets/foobar1 and foobar --> /run/secrets/foobar2).
For information, I encountered this issue when creating a base configuration for a server and providing an override file with extra environment variables set depending on use-case, even without the override file modifying the secrets.
File: foobar.yml
version: '3.7'
services:
foobar:
image: nginx
secrets:
- source: foobar
target: foobar1
- source: foobar
target: foobar2
secrets:
foobar:
file: foobar.secret
File: foobar-extend.yml
version: '3.7'
services:
foobar:
environment:
HELLO: WORLD
File: foobar.secret
foobar
Steps to reproduce the issue:
- Create files as specified above.
- Run
docker stack deploy -c foobar.yml -c foobar-extend.yml foobar. - Run
docker service inspect foobar_foobar | jq -r ".[0].Spec.TaskTemplate.ContainerSpec.Secrets"to evaluate the secrets mounted onto the service.
Describe the results you received:
The secret foobar is only mounted into one of the two locations.
[
{
"File": {
"Name": "foobar2",
"UID": "0",
"GID": "0",
"Mode": 292
},
"SecretID": "7szqcfqgk62xwy4j4r7ldi92k",
"SecretName": "foobar_foobar"
}
]
Describe the results you expected:
The secret foobar should be mounted into both /run/secrets/foobar1 and /run/secrets/foobar2
Additional information you deem important (e.g. issue happens only occasionally):
I have Swarm mode active, I have not tried the same test with Swarm mode inactive.
Output of docker version:
Client:
Version: 19.03.6-ce
API version: 1.40
Go version: go1.13.4
Git commit: 369ce74
Built: Fri May 29 04:01:26 2020
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 19.03.6-ce
API version: 1.40 (minimum version 1.12)
Go version: go1.13.4
Git commit: 369ce74
Built: Fri May 29 04:01:57 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.2
GitCommit: ff48f57fc83a8c44cf4ad5d672424a98ba37ded6
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
Additional environment details (AWS, VirtualBox, physical, etc.):
AWS Workspace
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with foobar.yml, foobar-extend.yml, and foobar.secret, then run the listed docker stack deploy and docker service inspect commands. Trace the stack deploy service-spec override and secret merge behavior; done means the inspection shows both foobar targets mounted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- cli, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100