Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--read-write-tmpfs=false should set /dev/* tmpfs to readonly #12954

Closed
wants to merge 1 commit into from

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Jan 20, 2022

Change the --read-only-tmpfs option to --read-write-tmpfs since
this makes sense and the old name was doing the exact opposite.

Fixes: #12937

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 20, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Jan 20, 2022

@giuseppe When I do this I attempt to make /dev, /dev/tty, /dev/shm, /dev/mqueue as read-only but crun blows up with

./bin/podman run -ti --read-only --read-only-tmpfs=false alpine sh
Error: OCI runtime error: crun: opening file /dev/console for writing: Read-only file system

@giuseppe
Copy link
Member

/dev is still used by the OCI runtime after setting the mounts.

I've fixed an issue in crun so it works when --tty is not used, but for a read-only /dev also in the tty case, we'd need to set the ro flag later. I'll take a look at it.

I've tried with runc and it fails as well, so I think it should be optional to set /dev read-only. Could we extend --read-only-tmpfs to accept a string and have something like --read-only-tmpfs=all?

@giuseppe
Copy link
Member

this seems to help with your PR: containers/crun#859

@rhatdan
Copy link
Member Author

rhatdan commented Jan 21, 2022

@kolyshkin WDYT?

@rhatdan
Copy link
Member Author

rhatdan commented Jan 21, 2022

I think if we leave any tmpfs writable, we don't solve the problem.

@rhatdan
Copy link
Member Author

rhatdan commented Jan 21, 2022

Fixes: #12937

@kolyshkin
Copy link
Contributor

As @giuseppe mentioned earlier, runc can't work with ro /dev, but this fix is easy opencontainers/runc#3345 (and very similar to containers/crun#857).

One other thing, @rhatdan, I also find it very confusing how --read-only-tmpfs=false results in read-only /dev mounts. Maybe a separate option (--read-only-dev) or something else entirely?

@rhatdan
Copy link
Member Author

rhatdan commented Jan 22, 2022

@kolyshkin I am not crazy about adding another function, Since I believe the original goal of --read-only-tmpfs (A badly named option, which we should probably change) was to make the entire container read-only. (At least the way I think about it).

@rhatdan
Copy link
Member Author

rhatdan commented Jan 22, 2022

Changed the option to read-write-tmpfs.

@rhatdan rhatdan changed the title [WIP] --read-only-tmpfs=false should set /dev/* tmpfs to readonly [WIP] --read-write-tmpfs=false should set /dev/* tmpfs to readonly Jan 22, 2022
@rhatdan rhatdan added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 25, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Jan 27, 2022

This PR is waiting for an updated released version of runc, which will allow it to work with /dev set to read/only mode.
@kolyshkin @AkihiroSuda Any idea when that will be?

@rhatdan rhatdan added the 4.1 label Jan 27, 2022
@kolyshkin
Copy link
Contributor

This PR is waiting for an updated released version of runc, which will allow it to work with /dev set to read/only mode.
@kolyshkin @AkihiroSuda Any idea when that will be?

Depending on how soon you need it.

We can certainly release runc 1.1.1, either now (= soon) with this change alone, or a bit later, waiting for a few more fixes to pile up.

@kolyshkin
Copy link
Contributor

This PR is waiting for an updated released version of runc,

Backport PR: opencontainers/runc#3355

@rhatdan
Copy link
Member Author

rhatdan commented Jan 28, 2022

Well since this is a post 4.0 feature, it is not needed immediately, but soon.

@rhatdan rhatdan changed the title [WIP] --read-write-tmpfs=false should set /dev/* tmpfs to readonly --read-write-tmpfs=false should set /dev/* tmpfs to readonly Feb 21, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 21, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 28, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rhatdan rhatdan force-pushed the tmpfs branch 3 times, most recently from 68c331b to 28e0ef1 Compare August 16, 2022 15:01
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 3, 2022
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 5, 2022
@github-actions github-actions bot added the kind/api-change Change to remote API; merits scrutiny label Oct 20, 2022
@rhatdan rhatdan force-pushed the tmpfs branch 3 times, most recently from eac20a3 to 1f312b6 Compare October 31, 2022 12:48
@edsantiago
Copy link
Collaborator

This is my fault, #16240. Can you run make docs, then git add the changed file and git commit --amend?

Copy link
Collaborator

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of little nits, sorry for not catching them earlier.

####> are applicable to all of those.
#### **--read-write-tmpfs**

If container is running in --read-only mode, then mount a read-write tmpfs on /run, /tmp, and /var/tmp. When false, Podman the entire container has no tmpfs that are read/write unless specified on the command line. Podman mounts /dev, /dev/mqueue, /dev/pts, /dev/shm as read only. The default is *true*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When false, Podman the entire container

Does not parse. I think Podman is the part that needs to go, but I'm not sure what the intention was.

Did you deliberately un-underscore the directory names? Our guidelines say:

Strings of characters or numbers can be highlighted with backticks. Paths of any kind must be highlighted.

(which suggests that backticks are preferred, underscores are ok, but leaving them unadorned is not).

Comment on lines +847 to +854
run_podman run --rm --read-only $IMAGE touch ${rwdir}/foo
run_podman run --rm --read-only --read-write-tmpfs=true $IMAGE touch ${rwdir}/foo
run_podman 1 run --rm --read-only --read-write-tmpfs=false $IMAGE touch ${rwdir}/foo
is "$output" "touch: ${rwdir}/foo: Read-only file system" "Should fail with ${rwdir}/foo read only file system"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: some of these are tabs, some are eight spaces.

# FIXME once ubuntu gets a newer crun
if is_ubuntu; then
if [ $(podman_runtime) == "crun" ]; then
skip "The version of crun shipped by ubuntu is too old. Needs crun-1.4.2 or greater"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a find-obsolete-skips script that I run periodically. Could you add "FIXME:" to this and the above skip/Skips ? That will bring these to my attention when I run the script next time.

skip "The version of crun shipped by ubuntu is too old. Needs crun-1.4.2 or greater"
fi
fi
HOST=$(random_string 25)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover from copy/paste (hence misleading, because it's never used). Please remove.

@@ -114,6 +114,11 @@ func commonFlags(cmd *cobra.Command) error {
if cmd.Flags().Changed("image-volume") {
cliVals.ImageVolume = cmd.Flag("image-volume").Value.String()
}

if cmd.Flags().Changed("read-write-tmpfs") && !cliVals.ReadOnly {
return errors.New("--read-write-tmpfs is only used if --read-only=true")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be clearer as "...is only valid if", or "...is only meaningful when..."

@@ -477,7 +477,7 @@ tmpfs directories on _/run_ and _/tmp_.
```
$ podman run --read-only -i -t fedora /bin/bash

$ podman run --read-only --read-only-tmpfs=false --tmpfs /run -i -t fedora /bin/bash
$ podman run --read-only --read-write-tmpfs=false --tmpfs /run -i -t fedora /bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(commenting on code that github does not show by default, so please click the uparrow-on-bar to see lines 473-475). Those lines read:

The best way to handle this is to mount tmpfs directories on /run and /tmp.

This looks like a holdover from a previous age: the implication is that /run and /tmp are also read-only. I haven't taken the time to go through history, but is it possible that the read-only-tmpfs option (the one that is being renamed here) was added after this was written, and that this used to be true but no longer is? Can you re-review lines 473-475 and see if they should be rewritten, maybe something like

Read-only containers still mount /run, /tmp, /var/tmp, /dev, and /dev/shm as read-write tmpfs. Use --read-write-tmpfs=false to protect even tmpfs directories, and --tmpfs=PATH to explicitly limit the read-write tmpfs filesystems.

(Idea only. That reads horribly. My documentation-writing brain is not fully engaged yet).

@rhatdan rhatdan force-pushed the tmpfs branch 4 times, most recently from 1551a20 to 970f3b8 Compare November 1, 2022 19:32
read-write tmpfs on _/run_, _/tmp_, and _/var/tmp_. When false, Podman sets
the entire container such that no tmpfs can be written to unless specified on
the command line. Podman mounts _/dev_, _/dev/mqueue_, _/dev/pts_, _/dev/shm_
as read only. The default is *true*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this hard to parse, and am really confused by the discrepancies between the first list of "these are tmpfs" and the second. I'm just going to hope that @TomSweeneyRedHat will offer his always-helpful input. Otherwise my (much less refined) thinking goes something like:

Only valid in combination with **--read-only**.  Default: **true**.

Normally a container run with **read-only** will mount the following `tmpfs` filesystems read/write:
   [ complete enumeration of those filesystems, possibly with a reference to where in the code that list is found ]
With **--read-write-tmpfs=false**, even those filesystems are mounted read-only.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 5, 2022
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 7, 2022
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 2, 2022
Change the --read-only-tmpfs option to --read-write-tmpfs since
this makes sense and the old name was doing the exact opposite.

Fixes: containers#12937

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Dec 20, 2022

Replaced by #16545

@rhatdan rhatdan closed this Dec 20, 2022
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 17, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Change to remote API; merits scrutiny kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFE: --read-only: add sub-option to make /dev readonly as well
10 participants