pre-commit: Permission issue with rootless containers
I tried to use a docker_image
hook on a RHEL7.7 system using podman
with the podman-docker
package installed [This setup allows for rootless containers]. The hook attempts to modify the file, but gets a “permission denied” error. From looking at the source code, I see that pre-commit
is roughly trying to execute:
docker run -u $(id -u):$(id -g) -v $(pwd):/src:rw,Z --workdir /src -it <ENTRY> <FILE>
The hook does try to run, but results in permission error.
If, however, I remove the -u
option from the source code (locally, languages/docker.py, docker_cmd()), then the hook runs fine:
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 5
- Comments: 35 (12 by maintainers)
I don’t understand the AttributeError check. Also, this function can actually return
None
ifrootless
isTrue
. What about:Probably need to add a check whether the current user is not root. Or if they have capabilities to set uid/gid.
@asottile - yes I do! I try and find some time to tackle it.
Update: I installed docker 19.03 on Centos 7.7 using the instructions found here: https://docs.docker.com/engine/security/rootless/#prerequiresites
This allows the docker daemon to run as a non-root user. This mode allows the docker daemon to be installed in user space, and does not require privileges to install or run the docker daemon, as long as certain prerequisites are satisfied.
With this type of install, the exact same issue is observed as with (rootless) podman.
What about if the local docker daemon is setup as so: https://docs.docker.com/engine/security/rootless/
Pretty sure the above approach by docker is using the same set of linux kernel features that podman is using. Rootless containers are a must for any one that is security-minded.