kubernetes
) there doesn't seem to be a good devops/configuration-as-code approach to get the right owner/permissions set on docker volumes, so the (non-root) user cannot write to the volumeWhat is then good practice when running a container process as a non-root
user and I want to write to a (cloudstor, aws-ebs) docker volume.
It is considered bad practice in (and outside) docker containers to run processes as root (see for example ref1, ref2, ...). This might have security implications.
But when we start using docker volumes and that non-root user tries to write to the volume, the trouble begins. I fail to find a clean solution that will work on cloud infrastructure, without manual intervention. The working solutions I found all seem to fall short on some point (security, maintainability, ...).
As a side-note, we are deploying on docker-swarm
using cloudstor
to provision aws-ebs
volumes. We hope to move to kubernetes one day, but we don't have kubernetes yet, so we try to find an alternative solution for our setup.
As proposed here, if docker-compose
creates a new volume, the permissions on the directory inside the image will be propagated.
downsides:
cloudstor
, probably this won't work either, because it won't be docker-compose
provisioning the volume (not tested)hasnat created a volumes-provisioner image which could set the correct folder permissions just before the real container starts.
downsides:
ebs
volumes can only be mounted on a single docker container, which caused many deployment issuesdocker run
to correct file permissionsOnce the real container is running with the volume mounted (but still with the wrong permissions), we call
docker run --rm -u root -v ${MOUNT}:${TARGET} { real_image } chown -R user:group ${TARGET}
downsides:
ebs
volume can only be mounted in one container, so this will create conflictsThis implies:
root
user (otherwise we don't have the right to change directory owner/permissions)non-root
userdownsides:
This is the easiest solution, but then what about security? And everybody recommending not to do this?
As suggested here, with kubernetes we can assign a group id to a volume. This seems confirmed in the kubernetes documentation for pods.
downsides:
kubernetes
yet.Make sure directories exist on the file system with the correct owner/permissions.
downsides
cloudstor
, which allows us even to switch availability zones)I vote for the solution 4, there is no security issue to change the permissions as root then to start your application as non root. If there is a security hole in your application, the application is still not running as root whatever happened before it started. You can do this in a script use in the entrypoint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With