Skip to content

Commit f1019b4

Browse files
authored
Merge pull request #4992 from mayur-tolexo/fix/mount-remove-rw
fix(mount): remove the non-Docker `rw` option from --mount
2 parents 46b82c9 + 7d2afb4 commit f1019b4

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

docs/command-reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ Volume flags:
302302
- Common Options:
303303
- :whale: `src`, `source`: Mount source spec for bind and volume. Mandatory for bind.
304304
- :whale: `dst`, `destination`, `target`: Mount destination spec.
305-
- :whale: `readonly`, `ro`, `rw`, `rro`: Filesystem permissions.
305+
- :whale: `readonly`, `ro`: mount the filesystem read-only.
306+
- :nerd_face: `rro`: mount the filesystem recursively read-only.
306307
- Options specific to `bind`:
307308
- :whale: `bind-propagation`: `shared`, `slave`, `private`, `rshared`, `rslave`, or `rprivate`(default).
308309
- :whale: `bind-nonrecursive`: `true` or `false`(default). If set to true, submounts are not recursively bind-mounted. This option is useful for readonly bind mount.

pkg/mountutil/mountutil_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func ProcessFlagMount(s string, volStore volumestore.VolumeStore) (*Processed, e
332332

333333
if len(parts) == 1 {
334334
switch key {
335-
case "readonly", "ro", "rw", "rro":
335+
case "readonly", "ro", "rro":
336336
rwOption = key
337337
continue
338338
case "bind-nonrecursive":
@@ -361,7 +361,7 @@ func ProcessFlagMount(s string, volStore volumestore.VolumeStore) (*Processed, e
361361
src = value
362362
case "target", "dst", "destination":
363363
dst = value
364-
case "readonly", "ro", "rw", "rro":
364+
case "readonly", "ro", "rro":
365365
trueValue, err := strconv.ParseBool(value)
366366
if err != nil {
367367
return nil, fmt.Errorf("invalid value for %s: %s", key, value)

pkg/mountutil/mountutil_linux_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,66 @@ func TestProcessFlagVAnonymousVolumes(t *testing.T) {
352352
})
353353
}
354354
}
355+
356+
// TestProcessFlagMountRW verifies that the non-Docker `rw` option is no longer
357+
// accepted by --mount, while ro/readonly/rro remain valid read-only flags.
358+
func TestProcessFlagMountRW(t *testing.T) {
359+
// rw is no longer a valid --mount option.
360+
rejected := []struct {
361+
spec string
362+
want string
363+
}{
364+
{"type=bind,source=/foo,target=/bar,rw", "must be a key=value pair"},
365+
{"type=bind,source=/foo,target=/bar,rw=true", "unexpected key 'rw'"},
366+
{"type=bind,source=/foo,target=/bar,rw=false", "unexpected key 'rw'"},
367+
}
368+
for _, tt := range rejected {
369+
t.Run(tt.spec, func(t *testing.T) {
370+
_, err := ProcessFlagMount(tt.spec, nil)
371+
assert.ErrorContains(t, err, tt.want)
372+
})
373+
}
374+
375+
// ro/rro still parse into a complete read-only bind mount.
376+
src := t.TempDir()
377+
accepted := []struct {
378+
spec string
379+
wants *Processed
380+
}{
381+
{
382+
spec: "type=bind,source=" + src + ",target=/bar,ro",
383+
wants: &Processed{
384+
Type: Bind,
385+
Mount: specs.Mount{
386+
Type: "bind",
387+
Source: src,
388+
Destination: "/bar",
389+
Options: []string{"rbind", "ro", "rprivate"},
390+
},
391+
},
392+
},
393+
{
394+
spec: "type=bind,source=" + src + ",target=/bar,rro",
395+
wants: &Processed{
396+
Type: Bind,
397+
Mount: specs.Mount{
398+
Type: "bind",
399+
Source: src,
400+
Destination: "/bar",
401+
Options: []string{"rbind", "ro", "rro", "rprivate"},
402+
},
403+
},
404+
},
405+
}
406+
for _, tt := range accepted {
407+
t.Run(tt.spec, func(t *testing.T) {
408+
got, err := ProcessFlagMount(tt.spec, nil)
409+
assert.NilError(t, err)
410+
assert.Equal(t, got.Type, tt.wants.Type)
411+
assert.Equal(t, got.Mount.Type, tt.wants.Mount.Type)
412+
assert.Equal(t, got.Mount.Source, tt.wants.Mount.Source)
413+
assert.Equal(t, got.Mount.Destination, tt.wants.Mount.Destination)
414+
assert.DeepEqual(t, got.Mount.Options, tt.wants.Mount.Options)
415+
})
416+
}
417+
}

0 commit comments

Comments
 (0)