go-dockerclient: Error message may leak credentials used for mounting
I opened https://github.com/hashicorp/nomad/issues/12296 because we observed that nomad logs would openly display credentials used for (cifs) mounts when the mounting failed (e.g. because of a mistyped server path) and was told that the error is from go-dockerclient, so that it might make sense to discuss the problem here as well.
When we’re trying to mount a server share into a docker container with options like
{
"device": "//servername.organization.lan/share/path/does/not/exist/",
"o": "addr=servername.organization.lan,_netdev,iocharset=utf8,noperm,uid=0,gid=0,username=${MOUNT_USERNAME},password=${MOUNT_PASSWORD},domain=org_domain",
"type": "cifs"
}
the error message looks like
error while mounting volume '/var/lib/docker/volumes/mount_input_3f6a4f51-3b97-2b0a-3dc1-f14cad6a5bb9/_data':
failed to mount local volume:
mount //servername.organization.lan/share/path/does/not/exist/:/var/lib/docker/volumes/mount_input_3f6a4f51-3b97-2b0a-3dc1-f14cad6a5bb9/_data,
data: addr=11.22.33.44,_netdev,iocharset=utf8,noperm,uid=0,gid=0,username=secret_user,password=secret_password_in_plaintext,domain=org_domain: no such file or directory
for example. (I added a few linebreaks this time in order to make the output easier to read, since the important part is at the end of the rather long message.)
I think everyone would be happy if there was an alternative way to specify the password (via a file, for instance) so that it does not appear in the options in the first place. A colleague looked into this, but as far as I understood him, the way the mounting currently happens via a syscall does not allow this option (which seems to be handled by mount.cifs client-side, usually.)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (6 by maintainers)
Commits related to this issue
- volume: mask password in cifs mount error messages In managed environment (such as Nomad clusters), users are not always supposed to see credentials used to mount volumes. However, if errors occur (m... — committed to shoeffner/moby by shoeffner 2 years ago
- volume: mask password in cifs mount error messages In managed environment (such as Nomad clusters), users are not always supposed to see credentials used to mount volumes. However, if errors occur (m... — committed to shoeffner/moby by shoeffner 2 years ago
- volume: mask password in cifs mount error messages In managed environment (such as Nomad clusters), users are not always supposed to see credentials used to mount volumes. However, if errors occur (m... — committed to shoeffner/moby by shoeffner 2 years ago
- volume: mask password in cifs mount error messages In managed environment (such as Nomad clusters), users are not always supposed to see credentials used to mount volumes. However, if errors occur (m... — committed to shoeffner/moby by shoeffner 2 years ago
- volume: mask password in cifs mount error messages In managed environment (such as Nomad clusters), users are not always supposed to see credentials used to mount volumes. However, if errors occur (m... — committed to shoeffner/moby by shoeffner 2 years ago
It would be possible to filter all errors/methods, but you will never know in which places users will have credentials, so that will become tricky. In this particular instance you (@fsouza) already pinned down the error handling in moby, so maybe it’s good to patch it right there? They already resolve addr= options and replace them for the error messages:
https://github.com/moby/moby/blob/7c69b6dc08c7ce128c3015e08076641c2c5c40e5/volume/local/local_unix.go#L137-L143
We could adapt that to mask the password, maybe something along these lines:
I will try to setup some local test to see if the error output is suppressed this way; if so, I will create an issue/PR with moby and see what they say about it. Or do you have other ideas?
Yeah confirmed it’s a matter of upgrading Docker itself and there’s no action needed on the client.
@hmeine thank you very much for pushing this through!