Skip to content

Commit 3b86328

Browse files
authored
Merge pull request #511 from AkihiroSuda/mount-rro
Support recursive read-only (RRO) mounts: `nerdctl run -v /foo:/bar:rro,rprivate`
2 parents 661ca97 + c103287 commit 3b86328

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Major:
123123
- [On-demand image pulling (lazy-pulling) using Stargz Snapshotter](./docs/stargz.md): `nerdctl --snapshotter=stargz run IMAGE` .
124124
- [Image encryption and decryption using ocicrypt (imgcrypt)](./docs/ocicrypt.md): `nerdctl image (encrypt|decrypt) SRC DST`
125125
- [P2P image distribution using IPFS](./docs/ipfs.md): `nerdctl run ipfs://CID`
126+
- Recursive read-only (RRO) bind-mount: `nerdctl run -v /mnt:/mnt:rro` (make children such as `/mnt/usb` to be read-only, too).
127+
Requires kernel >= 5.12, and crun >= 1.4 or runc >= 1.1 (PR [#3272](https://github.com/opencontainers/runc/pull/3272)).
126128

127129
Minor:
128130
- Namespacing: `nerdctl --namespace=<NS> ps` .
@@ -339,7 +341,13 @@ Runtime flags:
339341
- :whale: `--sysctl`: Sysctl options, e.g \"net.ipv4.ip_forward=1\"
340342

341343
Volume flags:
342-
- :whale: :blue_square: `-v, --volume`: Bind mount a volume
344+
- :whale: :blue_square: `-v, --volume <SRC>:<DST>[:<OPT>]`: Bind mount a volume, e.g., `-v /mnt:/mnt:rro,rprivate`
345+
- :whale: option `rw` : Read/Write (when writable)
346+
- :whale: option `ro` : Non-recursive read-only
347+
- :nerd_face: option `rro`: Recursive read-only. Should be used in conjunction with `rprivate`. e.g., `-v /mnt:/mnt:rro,rprivate` makes children such as `/mnt/usb` to be read-only, too.
348+
Requires kernel >= 5.12, and crun >= 1.4 or runc >= 1.1 (PR [#3272](https://github.com/opencontainers/runc/pull/3272)). With older runc, `rro` just works as `ro`.
349+
- :whale: option `shared`, `slave`, `private`: Non-recursive "shared" / "slave" / "private" propagation
350+
- :whale: option `rshared`, `rslave`, `rprivate`: Recursive "shared" / "slave" / "private" propagation
343351
- :whale: `--tmpfs`: Mount a tmpfs directory
344352

345353
Rootfs flags:

pkg/mountutil/mountutil_linux.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ func parseVolumeOptionsWithMountInfo(vType, src, optsRaw string, getMountInfoFun
9494
)
9595
for _, opt := range strings.Split(optsRaw, ",") {
9696
switch opt {
97-
case "rw":
98-
writeModeRawOpts = append(writeModeRawOpts, opt)
99-
case "ro":
97+
case "rw", "ro", "rro":
10098
writeModeRawOpts = append(writeModeRawOpts, opt)
10199
case "private", "rprivate", "shared", "rshared", "slave", "rslave":
102100
propagationRawOpts = append(propagationRawOpts, opt)
@@ -112,9 +110,24 @@ func parseVolumeOptionsWithMountInfo(vType, src, optsRaw string, getMountInfoFun
112110

113111
if len(writeModeRawOpts) > 1 {
114112
return nil, nil, fmt.Errorf("duplicated read/write volume option: %+v", writeModeRawOpts)
115-
} else if len(writeModeRawOpts) > 0 && writeModeRawOpts[0] == "ro" {
116-
opts = append(opts, "ro")
117-
} // No need to return option when "rw"
113+
} else if len(writeModeRawOpts) > 0 {
114+
switch writeModeRawOpts[0] {
115+
case "ro":
116+
opts = append(opts, "ro")
117+
case "rro":
118+
// Mount option "rro" is supported since crun v1.4 / runc v1.1 (https://github.com/opencontainers/runc/pull/3272), with kernel >= 5.12.
119+
// Older version of runc just ignores "rro", so we have to add "ro" too, to our best effort.
120+
opts = append(opts, "ro", "rro")
121+
if len(propagationRawOpts) != 1 || propagationRawOpts[0] != "rprivate" {
122+
logrus.Warn("Mount option \"rro\" should be used in conjunction with \"rprivate\"")
123+
}
124+
case "rw":
125+
// NOP
126+
default:
127+
// NOTREACHED
128+
return nil, nil, fmt.Errorf("unexpected writeModeRawOpts[0]=%q", writeModeRawOpts[0])
129+
}
130+
}
118131

119132
if len(propagationRawOpts) > 1 {
120133
return nil, nil, fmt.Errorf("duplicated volume propagation option: %+v", propagationRawOpts)

0 commit comments

Comments
 (0)