[Bug]: --mount and -v accept a relative container path and mount it at /<path>

Aperta Adatta ai principianti
#2,324 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@devops-thiago ci sta già lavorando.

Dal 1/10/2026.

  • #2328 di @devops-thiago — aperta
  • #2362 di @dajiaohuang — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
86/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
swift
Ambito
cli

Direzione di ricerca

Inizia in Sources/Services/ContainerAPIService/Client/Parser.swift, in particolare in Parser.validateMount e Parser.tmpfsMounts, e confronta il modo in cui ciascuna forma di mount valida la propria destinazione. Il lavoro è completato quando i percorsi del container relativi, vuoti e basati su punti vengono rifiutati in modo coerente per --mount, -v e --tmpfs con l'errore esistente per i percorsi assoluti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I have done the following
  • I have searched the existing issues
  • If possible, I've reproduced the issue using the 'main' branch of this project
Steps to reproduce

Give any mount form a relative path on the container side:

container run --rm --mount type=bind,source=/tmp,target=data alpine:latest sh -c 'ls -ld /data; mount | grep " /data "'

The container starts and the host folder is mounted at /data (image pull progress omitted):

drwxrwxrwt 1241 root     root         39712 Oct  1 17:26 /data
virtiofs on /data type virtiofs (rw,relatime)

The other forms are accepted the same way and also end up at /data:

container volume create evvol
container run --rm --mount type=volume,source=evvol,target=data alpine:latest ...   # ext4 on /data
container run --rm -v evvol:data alpine:latest ...                                  # ext4 on /data
container run --rm -v data alpine:latest ...                                        # anonymous volume, ext4 on /data
container run --rm --mount type=tmpfs,target=data alpine:latest ...                # tmpfs on /data

Paths with . and .. are accepted too. target=../x is mounted at /x, -v data:a/../../y at /y and target=./z at /z.

--tmpfs rejects the same path:

$ container run --rm --tmpfs data alpine:latest true
Error: data is not an absolute path

container create stores the value as typed. container inspect shows "destination" : "data" for a container whose running mount is /data.

A debug build of main at 0a48a1b accepts the same forms and rejects --tmpfs.

Problem description

Parser.validateMount is where parsed --mount and -v values are checked. For a filesystem or volume mount it only checks that the container path is not empty:

https://github.com/apple/container/blob/0a48a1bd/Sources/Services/ContainerAPIService/Client/Parser.swift#L654-L660

if fs.destination.isEmpty {
    throw ContainerizationError(.invalidArgument, message: "mount destination cannot be empty")
}

--tmpfs is stricter. Parser.tmpfsMounts rejects a relative path, added in #2103 for #2094, which says the destination "must be a non-empty absolute path". The same input is therefore an error for one flag and quietly reinterpreted by the others. A typo such as -v data:app/data mounts at /app/data without a word.

The container path is a location inside the container, and the OCI runtime spec requires it to be an absolute path (mounts[].destination in config.md). Every mount form should fail at parse time with the message --tmpfs already gives.

Environment
  • OS: macOS 26.6.2 (25G83)
  • Xcode: 26.6 (17F113)
  • Container: 1.5.0 (Homebrew), and main at 0a48a1b
Code of Conduct
  • I agree to follow this project's Code of Conduct
Lingua principale
Swift
Stelle
51k
Fork
1.8k
Merge medio
2g 10h
PR unite (30g)
39

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apple/container

Tutte le issue di apple/container

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.