Skip to content

Commit

Permalink
Merge pull request #6380 from mheon/fix_mount_readonly
Browse files Browse the repository at this point in the history
Add support for `readonly` option to --mount
  • Loading branch information
openshift-merge-robot authored May 29, 2020
2 parents 8e048b2 + e26f9ed commit 78c3846
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
22 changes: 21 additions & 1 deletion cmd/podman/common/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,29 @@ func getBindMount(args []string) (spec.Mount, error) {
switch kv[0] {
case "bind-nonrecursive":
newMount.Options = append(newMount.Options, "bind")
case "readonly", "read-only":
if setRORW {
return newMount, errors.Wrapf(optionArgError, "cannot pass 'readonly', 'ro', or 'rw' options more than once")
}
setRORW = true
switch len(kv) {
case 1:
newMount.Options = append(newMount.Options, "ro")
case 2:
switch strings.ToLower(kv[1]) {
case "true":
newMount.Options = append(newMount.Options, "ro")
case "false":
// RW is default, so do nothing
default:
return newMount, errors.Wrapf(optionArgError, "readonly must be set to true or false, instead received %q", kv[1])
}
default:
return newMount, errors.Wrapf(optionArgError, "badly formatted option %q", val)
}
case "ro", "rw":
if setRORW {
return newMount, errors.Wrapf(optionArgError, "cannot pass 'ro' or 'rw' options more than once")
return newMount, errors.Wrapf(optionArgError, "cannot pass 'readonly', 'ro', or 'rw' options more than once")
}
setRORW = true
// Can be formatted as one of:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/markdown/podman-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ Current supported mount TYPES are `bind`, `volume`, and `tmpfs`.

· dst, destination, target: mount destination spec.

· ro, read-only: true or false (default).
· ro, readonly: true or false (default).

Options specific to bind:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/markdown/podman-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ Current supported mount TYPEs are **bind**, **volume**, and **tmpfs**.

· dst, destination, target: mount destination spec.

· ro, read-only: true or false (default).
· ro, readonly: true or false (default).

Options specific to bind:

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ var _ = Describe("Podman run with volumes", func() {
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(ContainSubstring(dest + " ro"))

session = podmanTest.Podman([]string{"run", "--rm", "--mount", mount + ",readonly", ALPINE, "grep", dest, "/proc/self/mountinfo"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(ContainSubstring(dest + " ro"))

session = podmanTest.Podman([]string{"run", "--rm", "--mount", mount + ",shared", ALPINE, "grep", dest, "/proc/self/mountinfo"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expand Down

0 comments on commit 78c3846

Please sign in to comment.