Engine: a tmpfs volume loses its uid, gid and mode when the image doesn't have the mount target

Open
#296 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
docker, linux, rust

Research direction

Read crates/kiri-init/src/linux/container.rs at apply_mount and inspect the image_tree() lookup and copy_tree behavior. The report describes reproduction commands for tmpfs volumes and a workaround, but asks maintainers to choose between an xattr marker and another way to inspect image lower layers. Done means preserving the tmpfs root's requested uid, gid and mode on first and later container starts while keeping the #30 copy-up case intact; the proposed regression coverage is in tests/e2e.sh.

Written by the indexing model from the issue text.

Description

bug
Kiri version and system

0.2.1 on macOS 27.0.1 (Apple silicon)

What you did

docker volume create -d local -o type=tmpfs -o device=tmpfs -o o=size=1m,uid=10001,gid=10050,mode=2750 tmpfs-owner
docker run --rm -v tmpfs-owner:/t alpine:3 sh -c 'stat -c "%u:%g %a" /t; grep " /t " /proc/mounts'
docker run --rm --tmpfs /t:uid=10001,gid=10050,mode=2750 alpine:3 stat -c '%u:%g %a' /t
docker volume rm tmpfs-owner

What happened
0:0 755
tmpfs /t tmpfs rw,relatime,size=1024k,mode=2750,uid=10001,gid=10050 0 0
10001:10050 2750
What you expected instead

The volume's root should be 10001:10050 2750, as the mount options say. That's what Docker's local driver gives, because alpine has no /t and so there is nothing to copy up. The plain --tmpfs mount in the third command already gets this right on Kiri.

Anything else

It happens every time, and on every later start of the same container too. I hit it with a Compose project in which one service writes a config file into a shared tmpfs volume (uid=10001,gid=10050,mode=2750) and another reads it. The writer runs as 10001 and gets "permission denied", so the stack never comes up.

Workaround: after the containers start, chown and chmod the volume's root from a root container:

docker run --rm -v tmpfs-owner:/t alpine:3 sh -c 'chown 10001:10050 /t && chmod 2750 /t'

This lasts only until the volume is unmounted.

Cause, as far as I can tell: the tmpfs mount itself is correct (volmount::ensure passes uid=,gid=,mode= to mount(2), and /proc/mounts shows them). The root gets changed afterwards, in apply_mount's copy-up (crates/kiri-init/src/linux/container.rs). The target is looked up in image_tree(), an open_tree clone of the container root's own mount, so it also holds the directory that inroot::open has just made for the mount. Copy-up takes that empty root:root 755 directory for the image's and copy_tree's last keep(to, &meta) copies its owner and mode over the volume. On later starts the directory is still in the container's upper layer, so the same thing happens again. Docker copies up only what the image has. This lookup came in with the fix for #30.

I have a fix that passes the cases above, the #30 case (./:/app with /app/node_modules still gets the image's node_modules) and normal copy-up from an image path:

  • When the image lookup reaches the directory that was just made (same dev and inode), skip copy-up and mark that directory with a user.kiri.mountpoint xattr in the container's layer.
  • On later starts, skip copy-up from a marked directory.
  • A directory made inside a bind is never marked, so the host folder is left alone.

It's about 30 lines in container.rs plus one tests/e2e.sh case that checks the owner and mode on a container's first and second start. Is the xattr marker an approach you'd take? Or would you rather check the image's lower layers some other way? I can open the PR once we agree.

Dominant language
Rust
Stars
7.5k
Forks
329
Avg merge
7h 48m
Merged PRs (30d)
105

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from libracoder/kiri

All issues in libracoder/kiri

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.