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

オープン
#296 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
docker, linux, rust

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Rust
スター
7.5k
フォーク
329
平均マージ
7時間 48分
マージ済み PR(30日)
105

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

libracoder/kiri のほかの issue

libracoder/kiri の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。