Skip to content

Make /proc, /sys, & /dev readonly for readonly containers - #13669

Merged
jessfraz merged 1 commit into
moby:masterfrom
ewindisch:readonly-proc
Jul 10, 2015
Merged

jessfraz merged 1 commit into
moby:masterfrom
ewindisch:readonly-proc

Conversation

@ewindisch

Copy link
Copy Markdown
Contributor

If a container is read-only, also set /proc, /sys,
& /dev to read-only. This should apply to both privileged and
unprivileged containers.

Note that when /dev is read-only, device files may still be
written to. This change will simply prevent the device paths
from being modified, or performing mknod of new devices within
the /dev path.

Tests are included for all cases. Also adds a test to ensure
that /dev/pts is always mounted read/write, even in the case of a
read-write rootfs. The kernel restricts writes here naturally and
bad things will happen if we mount it ro.

Signed-off-by: Eric Windisch [email protected]

@ewindisch ewindisch changed the title Make /proc readonly for readonly containers Make /proc & /sys readonly for readonly containers Jun 3, 2015
@ewindisch
ewindisch force-pushed the readonly-proc branch 2 times, most recently from ab8b440 to 1d0ad78 Compare June 3, 2015 17:04
@ewindisch

Copy link
Copy Markdown
Contributor Author

Warning that this patch strips the noexec, nosuid flags from /proc and /dev. The risk here is minimized because the paths are (now) read-only, but it's worth noting in case anyone has issue with this. I believe the right fix for that will be in libcontainer, so this code should not need to be changed.

@ewindisch ewindisch changed the title Make /proc & /sys readonly for readonly containers Make /proc, /sys, & /dev readonly for readonly containers Jun 3, 2015
@ewindisch

Copy link
Copy Markdown
Contributor Author

ping @crosbymichael @jfrazelle

@jessfraz

jessfraz commented Jun 8, 2015

Copy link
Copy Markdown
Contributor

design LGTM

@icecrime

Copy link
Copy Markdown
Contributor

Design LGTM

@cpuguy83

Copy link
Copy Markdown
Member

LGTM

Comment thread daemon/execdriver/native/create.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if !container.Readonlyfs

@ewindisch

Copy link
Copy Markdown
Contributor Author

Addressed @LK4D4 's nits and rebased.

@LK4D4

LK4D4 commented Jul 2, 2015

Copy link
Copy Markdown
Contributor

@ewindisch Compile error :)

If a container is read-only, also set /proc, /sys,
& /dev to read-only. This should apply to both privileged and
unprivileged containers.

Note that when /dev is read-only, device files may still be
written to. This change will simply prevent the device paths
from being modified, or performing mknod of new devices within
the /dev path.

Tests are included for all cases. Also adds a test to ensure
that /dev/pts is always mounted read/write, even in the case of a
read-write rootfs. The kernel restricts writes here naturally and
bad things will happen if we mount it ro.

Signed-off-by: Eric Windisch <[email protected]>
@ewindisch

Copy link
Copy Markdown
Contributor Author

@LK4D4 FYI, I fixed the compiler error

@LK4D4

LK4D4 commented Jul 2, 2015

Copy link
Copy Markdown
Contributor

LGTM

@thaJeztah

Copy link
Copy Markdown
Member

ping @cpuguy83 does this still LGTY (code changes were made since)

@ewindisch does this need a mention in the documentation somewhere? I.e., will users run into a change in behavior because of this?

@ewindisch

Copy link
Copy Markdown
Contributor Author

@thaJeztah a change of behavior will be noted, but I'd argue it should have been this way from the beginning.

(I have also deleted another comment I had made which was supposed to be submitted on another issue but accidentally posted it here)

@thaJeztah

Copy link
Copy Markdown
Member

@ewindisch ah, that explains! (had this one marked to ask further)

@jessfraz

Copy link
Copy Markdown
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants