container: make hostconfig.json non-world-readable (0600)

When writing container's `hostconfig.json`, permissions were set to 0644 (world-
readable). While this is not a security concern (as the `/var/lib/docker/containers`
directory has `0700` or `0701` permissions), there is no real need to have these
permissions, as this file is only accessed by the daemon.

Looking at history for file permissions;

- 06b53e3fc7 (first implementation) used `0666` (world-writable)
- cf1a6c08fa refactored the code, and removed explicit permissions
- ea3cbd3274 introduced atomic writes, and brought back the `0666` permissions
- 3ec8fed747 removed world-writable bits, but kept world-readable

This patch updates the permissions to `0600`, matching what's used for `config.v2.json`,
which was updated in ae52cea3ab, but forgot to update
`hostconfig.json`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-11-02 10:27:51 +01:00
parent 0e8023ddea
commit 5c0b694ef3
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -244,7 +244,7 @@ func (container *Container) WriteHostConfig() (*containertypes.HostConfig, error
return nil, err
}
f, err := ioutils.NewAtomicFileWriter(pth, 0644)
f, err := ioutils.NewAtomicFileWriter(pth, 0600)
if err != nil {
return nil, err
}