Conversation
daemon/cluster/convert/container.go
Outdated
There was a problem hiding this comment.
Redundant switch. IMO should be
mode := swarmapi.SecretReference_FILE
if s.Mode == types.SecretReferenceSystem {
mode = swarmapi.SecretReference_SYSTEM
}
daemon/cluster/convert/container.go
Outdated
There was a problem hiding this comment.
maybe make convertSecretReferenceMode function
daemon/cluster/convert/secret.go
Outdated
There was a problem hiding this comment.
I think you can embed Version and Spec in structure initialization
daemon/cluster/convert/secret.go
Outdated
daemon/cluster/convert/secret.go
Outdated
daemon/container_operations_unix.go
Outdated
There was a problem hiding this comment.
you can use WithFields for creating such structured messages :)
daemon/container_operations_unix.go
Outdated
There was a problem hiding this comment.
we have pkg/errors vendored now. Would you mind to use errors.Wrap{f} in such cases?
daemon/container_operations_unix.go
Outdated
There was a problem hiding this comment.
shouldn't this func cleanup on error? I mean like unmount and remove secrets dir.
There was a problem hiding this comment.
ok i added a defer func that should cleanup. ptal thx!
daemon/secrets.go
Outdated
There was a problem hiding this comment.
Sounds like this warning will be logged on each container run. Is that right?
cpuguy83
left a comment
There was a problem hiding this comment.
Having issues making this work:
$ echo foo=bar | docker secret create test
$ docker service create --name test --secret test:/foo busybox top
$ docker exec <cid> ls /foo
/foo does not exist.
I have concerns on supporting the format <name>:<target> which puts us in the same sticky situation we are in with -v on run.
There was a problem hiding this comment.
Can we use api/errors with something like a BadRequest?
There was a problem hiding this comment.
thx -- i was following the convention. i'll update
There was a problem hiding this comment.
Would this only ever be an internal error? If not I'd not wrap the error here and make sure the backend provides a sufficient message.
cli/command/service/parse.go
Outdated
There was a problem hiding this comment.
👎
This format is nice in the happy case, but in the long run is a nightmare.
There was a problem hiding this comment.
ok. do you have an alternative?
There was a problem hiding this comment.
I think @stevvooe once suggested the unicode arrow ;)
But seriously, I think the code here has the right approach. The secret name and target need to be specified adjacent to each other instead of using separate options. We could use key-value pairs, but I think that would be really ugly and unintuitive.
There was a problem hiding this comment.
@cpuguy83 @aaronlehmann what about something like
--secret ssh-dev,target=id_rsa,uid=1000,gid=1000,mode=0600
There was a problem hiding this comment.
any thoughts on the above @cpuguy83 @aaronlehmann ?
There was a problem hiding this comment.
I would say in general it looks good.
I think ssh-dev should be source=ssh-dev to match --mount (big discussion on whether to allow the positional syntax from that PR).
Only question I'd ask is, how does this work with if/when an alternative secrets backend is supported (e.g. Vault). Would the current options work on all backends/platforms? Can Windows support this?
There was a problem hiding this comment.
Not a big fan of source=. It complicates the normal case where all you want to specify is a source, which now involves key/value pairs. --secret-add source=secretname doesn't look like a particularly friendly CLI to me.
What about keeping the key/value pairs as the general case, but allowing a shorthand of --secret-add secretname (i.e. if no = is found, take the argument as the source)? I'm not completely sure I like this, but I think I like it more than forcing key/value syntax for this argument.
There was a problem hiding this comment.
But mixing positional and k/v in the same spec (e.g. --secret-add secretname,target=mysecret) not so much.
There was a problem hiding this comment.
I agree with @aaronlehmann's suggestion. We should have a shorthand of --secret-add secretname
daemon/container_operations_unix.go
Outdated
There was a problem hiding this comment.
we decided to not use ramfs since the swarmkit storage swaps to disk so we don't gain anything by using ramfs.
There was a problem hiding this comment.
@ehazlett does this mean secrets are effectively stored plain-text on disk?
There was a problem hiding this comment.
For the container they are stored in tmpfs (in memory). They are encrypted at rest in the Swarm storage.
container/container_unix.go
Outdated
There was a problem hiding this comment.
Why do we have a slice but only ever append one thing to it?
There was a problem hiding this comment.
it was to add more in the future but good point. i'll remove the slice.
container/container_unix.go
Outdated
container/container.go
Outdated
There was a problem hiding this comment.
Don't like that we're shoving secrets in here purely for indexing, but I guess we are doing it for other things as well right now.
daemon/cluster/secrets.go
Outdated
There was a problem hiding this comment.
Doesn't work when a name is specified.
There was a problem hiding this comment.
correct. swarmkit only supports getting by id atm
There was a problem hiding this comment.
swarmkit can filter by name or name prefix using the ListSecrets RPC. This is the same as other object types like service and node - Get is always by ID.
There was a problem hiding this comment.
So we could implement a GetSecretByName that effectively uses ListSecrets with a name filter under it.
|
Also sorry, I added some code review in there though it's still in design review. The other item would be only supporting stdin... but that's probably not a big deal... who knows for Windows though. |
|
Tests are also failing because of the linter. |
|
lint issues should be fixed. @cpuguy83 the design was to have the |
|
Aha! It goes in |
|
@cpuguy83 I was possibly thinking something like the more granular mount syntax in the future but it might be too much for now. idk |
|
@ehazlett looks like vendor needs to be updated. |
api/types/swarm/secret.go
Outdated
api/types/swarm/secret.go
Outdated
There was a problem hiding this comment.
We probably don't want omitempty for SecretSize. Probably not for any of these fields, actually.
api/types/swarm/secret.go
Outdated
There was a problem hiding this comment.
Again, probably don't want to omit the Data field if the secret is zero-length.
cli/command/service/opts.go
Outdated
There was a problem hiding this comment.
I suppose we still need to add the ability for the user to specify a custom target?
There was a problem hiding this comment.
There seems to be an inconsistency between service create and service update. Shouldn't they both take secrets in the format that specifies a name and target (i.e. use parseSecrets)?
There was a problem hiding this comment.
ya we actually don't even need this because i set it outside in order to do the lookup. good catch thx!
cli/command/service/parse.go
Outdated
There was a problem hiding this comment.
targetName = secretName to avoid the else case below?
cli/command/service/parse.go
Outdated
There was a problem hiding this comment.
This looks wrong. It will set every map value to point to the same iterator. Just make the map values secret IDs instead of pointers to secrets. That will make things simpler.
client/errors.go
Outdated
container/container_unix.go
Outdated
There was a problem hiding this comment.
Is it correct to return an empty Mount structure in this case? I see that it's unconditionally appended to a slice in createSpec.
There was a problem hiding this comment.
I had this as a nil check before; i'll switch back
There was a problem hiding this comment.
Few questions :
What should happen if I remove a secret that is mounted ? Right now it's still available in the container, that might be by design, just asking 👼.
On service create, there is a problem if I specify multiple secrets (using --secret) ; I get the same content for all the secrets.
$ docker service create sec1 <<EOF
A
EOF
$ docker secret create sec2 <<EOF
B
EOF
$ docker service create --name test --secret sec1 --secret sec2 busybox top
# Task container is 2b66…
$ docker exec -ti 2b66 sh
$ ls /run/secrets
sec1 sec2
$ cat /run/secrets/sec1
B
# should have be A
$ cat /run/secrets/sec2
B
On service update, it doesn't seems it updates the secret or re-create the task. Not sure what is the preferred way to go (I would think re-create the container), but as of now, it doesn't have any effect. — just saw the checkbox, nevermind 👼
$ docker service ps test
NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
test.1.imutqdjh4k2cm24e90mpkt9vh busybox 4c780a8f3912 Running Running 37 seconds ago
$ docker secret create sec3 <<EOF
C
EOF
$ docker service update --secret sec3 test
test
$ docker service ps test
NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
test.1.imutqdjh4k2cm24e90mpkt9vh busybox 4c780a8f3912 Running Running 7 minutes ago
$ docker exec -ti 2b6 sh
$ ls /run/secrets
sec1 sec2
For docker secret subcommands (like rm or inspect), should we support prefixes (like on all container subcommands) and names ? right now it just supports the full ID.
Other than that, it looks good 👼 🐸
api/server/router/swarm/cluster.go
Outdated
There was a problem hiding this comment.
This could be router.NewPostRoute("/secrets", sr.createSecret) 👼
There was a problem hiding this comment.
Ya I was trying to follow the convention but I like /secrets better. thx!
That's probably because of this: https://github.com/docker/docker/pull/27794/files#r85236096 |
daemon/container_operations_unix.go
Outdated
There was a problem hiding this comment.
Args to a deferred function are evaluated at the time of the defer statement, so this won't work as expected.
There was a problem hiding this comment.
i'm using a named return now so i think this should work. PTAL
There was a problem hiding this comment.
It still looks wrong. You shouldn't pass setupErr as an argument to the deferred function. You should just let it capture the variable from the outer scope.
There was a problem hiding this comment.
you are correct. thx
daemon/container_operations_unix.go
Outdated
There was a problem hiding this comment.
Is it correct to continue if the directory can't be created?
There was a problem hiding this comment.
nope -- i need to rework the cleanup
daemon/container_operations_unix.go
Outdated
There was a problem hiding this comment.
Is it correct to continue if the mount fails?
|
We need a way to define the secret on the container. Since we can't call the secret store direct from the engine side I chose to implement it here and have the cluster define it as discussed during design.
|
|
@ehazlett In general, these types should be isomorphic to swarm types. We can share types with swarm types, just fine. We do this for mounts. |
|
Is the design of the secret management allowing for future features like one-time-read options? Or is the design not allowing that kind of extensions of dynamically adding/removing secrets in a secure way? |
The design of the secrets functionality in this PR does not preclude such future features. Many of the existing features were designed with these use cases in mind for the future. |
|
opened #28516 for tracking the remaining review comments |
- `cassandra`: 3.0.10 - `docker`: 1.13.0-rc1 (currently failing the `override-cmd` test; see moby/moby#28329), `docker daemon` -> `dockerd` (docker-library/docker#31) - `drupal`: 8.2.3 - `java`: alpine 7.121.2.6.8-r0, 8.111.14-r0 - `openjdk`: alpine 7.121.2.6.8-r0, 8.111.14-r0 - `python`: 3.6.0b3 (docker-library/python#157), pip 9.0.1 (docker-library/python#154) - `ruby`: 2.3.2, 2.2.6 - `tomcat`: 6.0.48, 7.0.73, 8.0.39, 8.5.8, 9.0.0.M13 - `wordpress`: add `WORDPRESS_*_FILE` support for passing parameters via files especially for [Docker secrets](moby/moby#27794) (docker-library/wordpress#186)
|
@jefflill You might also want to make sure your second tmpfs is mounted securely, with Short term, I also wish the /run/secrets/ could have an option to simply o-rwx the directory (since it's read-only and we can't chmod it). That said, read once sounds a lot better... :) |
|
Actually, I've verified that opts/mount: add tmpfs-specific options This is super clean now. --Jeff On Fri, Nov 18, 2016 at 7:30 AM, Alexandre Guédon [email protected]
|
|
@ehazlett wow it's pretty cool ! Was working on a vault integration of our own when I've seen that. As the feature comes from swarmkit, could we imagine to have it in non swarm docker use (docker for mac, docker engine)? And what about docker-compose support? There's already a discussion opened about secrets docker/compose#1534 To wum up, I would be very pleased to be able to use secrets on my local machine/ci/... the same way than on the big cluster ;) |
|
@shouze this all works on docker for mac, but currently only for "services" (so if you have swarm mode enabled ( |
|
@thaJeztah ho nice! I've just tested it, very very nice ;) I guess that when enhancements in |
|
Hi, Sorry for the question but does the secrets are stored in an encrypted way ? |
|
@nasskach yes; see the (work in progress) documentation; https://github.com/docker/docker.github.io/pull/568/files |
This adds support for the new Secret API in Swarmkit (moby/swarmkit#1567). This adds commands (
create,inspect,ls,rm) for managing secrets in a Swarm cluster. This is currently for Swarm mode only as the backing store is Swarm and as such is only for Linux. This is the foundation for future secret support in Docker with potential improvements such as Windows support, different backing stores, etc.This takes the ideas and collective recommendations from #13490 to set the groundwork. It exposes a file system based interface for secret access. The engine creates a tmpfs and mounts it in container (
/run/secrets). A file is created for each secret that is assigned to the service. For example, if a secret named "ssh-dev" with a target of "id_rsa" is assigned to the service, a file with the secret contents will be created at/run/secrets/id_rsa.TODO:
Service update support to add / rm secrets from a serviceUser facing docsMore testsDepends on Fixed bug in secrets assignment, added logging swarmkit#1697Examples (these will be turned into user docs):
Create a Secret:
Create a Service with a Secret
We can then check the created container for the secret:
Create with full options