Skip to content

Mismatching User/Group cause file permission issues on Unix #43

@boukeversteegh

Description

@boukeversteegh

Description

Files created by dockerized commands are not owned by the host's current user, but for example root.
This makes dockerized hard to use on unix systems, as generated files cannot be modified by the user.

It is also inconsistent with the design goal that Dockerized commands should behave the same as native commands.

Reproduction

> dockerized bash -c 'touch foo'
ls -l foo
-rw-r--r-- 1 root root 0 Apr 22 10:57 foo

Possible Solutions

These are all ideas I could come up with so far. Your thoughts and suggestions are welcome.
The goal is to find a solution with no blockers (:x:), and remove ❔ by doing more research.

  • Run the docker image with the uid/gid of the host system
  • ❔ Ensure container images still work
    • ❌ The host's user id will not exist in the container. This leads to several problems:
      • Container files owned by root (which is the default on most images) may become inaccessible, e.g. /root
      • The user will not have a username
      • The user will not have a home directory (~ will point to /)
    • ❔ Create a user inside the docker container with the host uid/gid, upon start (i.e. with an entrypoint)
      • ❔ Might clash if the specific container already uses that user-id.
    • ❔ Create a dockerfile for each app, that creates a host user, baked into the image
      • ❔ How to ensure this works for multiple host users? E.g. if the host switches to user2, dockerized should still work, and create files as user2.
  • ❔ Map host ids to container ids
  • ❔ ID translation at the filesystem level
    • ❔ Change mounting settings so that id's are immediately mapped by docker
    • ❔ Re-mount the working directory within Unix, and somehow do id translation there, then mount that directory into docker
  • ❔ ID translation within the container
  • ✔/:x: Changing the owners/permissions of the generated files after each command is run
    • ❌ This won't work for long running commands, such as npm run which continuously updates files. Permissions won't be fixed until the program finishes.
    • Detecting which files need permission fixes:
      • ❌ Cannot use file stats, as some commands output files with specific mtimes (e.g. tar)
      • ❌ Cannot rely on just detecting new files, as some files may have been re-created with different owners
      • ✔️ Remembering all files + permissions before the command, and detecting new files and files with different owners/permissions.
      • ❔ Another way to detect generated / changed files?
    • Implementation: Let Dockerized fix the permissions
      • ❌ requires running dockerized as root
    • ✔️ Implementation: Let docker fix the permissions. I.e. run dockerized alpine chown $(id -u):$(id -g) $FILES (this works)
      • ☹ Performance (running another container adds 450ms, on my local virtual ubuntu)
      • If docker can generate the files as root on the host system, it can also run chmod on those files
      • If docker cannot generate files as root, then the problem didn't occur either, although the files may be owner by docker or another user.
    • Implementation: Run chown within the container, after the user's command. E.g. with an entrypoint script.
      • ❔ Do all unix containers have chown?
      • 😄 Performance will be better (no extra container overhead)
      • Can combine the two approaches (within container if possible, otherwise in separate container)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions