Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

stage1: implement read-only rootfs #2612

Closed
wants to merge 3 commits into from

Conversation

tmrts
Copy link
Contributor

@tmrts tmrts commented May 11, 2016

Using the Pod manifest readOnlyRootFS option mounts the rootfs of the app
as read-only using systemd-exec unit option ReadOnlyDirectories.

Fixes #2487

@@ -720,10 +724,10 @@ func writeEnvFile(p *stage1commontypes.Pod, env types.Environment, appName types

// PodToSystemd creates the appropriate systemd service unit files for
// all the constituent apps of the Pod
func PodToSystemd(p *stage1commontypes.Pod, interactive bool, flavor string, privateUsers string) error {
func PodToSystemd(p *stage1commontypes.Pod, interactive bool, flavor string, privateUsers string, rootFsIsReadOnly bool) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needs functional tests

@tmrts
Copy link
Contributor Author

tmrts commented May 11, 2016

cc @iaguis @jonboulle @alban

@@ -386,7 +386,7 @@ func findBinPath(p *stage1commontypes.Pod, appName types.ACName, app types.App,
}

// appToSystemd transforms the provided RuntimeApp+ImageManifest into systemd units
func appToSystemd(p *stage1commontypes.Pod, ra *schema.RuntimeApp, interactive bool, flavor string, privateUsers string) error {
func appToSystemd(p *stage1commontypes.Pod, ra *schema.RuntimeApp, interactive bool, flavor string, privateUsers string, rootFsIsReadOnly bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should really think about refactoring this function, it becomes bigger and bigger, maybe in "functional options" style.

Copy link
Contributor Author

@tmrts tmrts May 12, 2016

Choose a reason for hiding this comment

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

Please open a PR for functional options and assign it to me 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

done #2616

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@s-urbaniak Thank you :)

@jonboulle
Copy link
Contributor

This needs to be per-app, not per-pod, e.g. https://github.com/coreos/rkt/blob/623fc3140681aeff1f353717a4943e2538769c51/rkt/run.go#L96

@tmrts tmrts force-pushed the implement/read-only-rootfs branch from 8b8fb81 to 0f304fc Compare May 12, 2016 10:35
@tmrts tmrts changed the title Implement read-only rootfs user flag stage1: implement read-only rootfs May 12, 2016
@tmrts
Copy link
Contributor Author

tmrts commented May 12, 2016

Depends on appc/spec#603

@jonboulle PTAL

@@ -465,6 +465,10 @@ func appToSystemd(p *stage1commontypes.Pod, ra *schema.RuntimeApp, interactive b
unit.NewUnitOption("Service", "CapabilityBoundingSet", strings.Join(capabilitiesStr, " ")),
}

if ra.ReadOnlyRootFS {
opts = append(opts, unit.NewUnitOption("Service", "ReadOnlyDirectory", "/"))
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it ReadOnlyDirectories?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, spelling mistake.

I also wonder if we need to add ReadWriteDirectories= for the RW volumes when we have a read-only rootfs.

More tests to add in tests/rkt_volume_test.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

@iaguis
Copy link
Member

iaguis commented May 12, 2016

Shouldn't we expose a CLI option too?

@jonboulle
Copy link
Contributor

yeah we should

On Thu, May 12, 2016 at 2:59 PM, Iago López Galeiras <
notifications@github.com> wrote:

Shouldn't we expose a CLI option too?


You are receiving this because you were assigned.
Reply to this email directly or view it on GitHub
#2612 (comment)

@jonboulle
Copy link
Contributor

Basically we need appReadOnlyRootFS
https://github.com/coreos/rkt/blob/master/rkt/cli_apps.go#L309

On Thu, May 12, 2016 at 3:01 PM, Tamer TAS notifications@github.com wrote:

Shouldn't we expose a CLI option too?

cc @jonboulle https://github.com/jonboulle


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#2612 (comment)

@jonboulle
Copy link
Contributor

Actually, read only flag is NOT blocking for this, because rktnetes always generates pod manifests anyway.

@jonboulle
Copy link
Contributor

So we can do that in a follow-up.

Sorry about all the github spam, tra la la la

@alban
Copy link
Member

alban commented May 12, 2016

Does it work fine with volumes? E.g. a read-write "host" volume + this new rootfs-read-only option. Does the volume stay read-write as expected?

@iaguis
Copy link
Member

iaguis commented May 12, 2016

Does it work fine with volumes? E.g. a read-write "host" volume + this new rootfs-read-only option. Does the volume stay read-write as expected?

We probably need to add the target mountpoints to ReadWriteDirectories (if RW)...

@tmrts
Copy link
Contributor Author

tmrts commented May 12, 2016

@iaguis @alban I'll add RW volumes to ReadWriteDirectories

@tmrts tmrts force-pushed the implement/read-only-rootfs branch 2 times, most recently from 087d17d to 3fca517 Compare May 13, 2016 07:49
@tmrts tmrts force-pushed the implement/read-only-rootfs branch 2 times, most recently from 2301627 to 499da86 Compare May 13, 2016 08:25
@tmrts tmrts force-pushed the implement/read-only-rootfs branch from 499da86 to 9fb0614 Compare May 13, 2016 09:20
@@ -367,6 +598,32 @@ func TestPodManifest(t *testing.T) {
"",
},
{
// Simple read after write with volume mounted in a read-only rootfs, no apps in pod manifest.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this one. There is no mount point, so the volume is not mounted and the test writes directly in the read-only rootfs. Why does it pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ReadOnlyRootFS is not set 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind my previous comment, you're correct

@alban
Copy link
Member

alban commented May 13, 2016

Can we have a summary somewhere of the tests added?

Action Where rootfs RO? ACI manifest RO? pod manifest RO? Outcome expected
Read Rootfs RO - RO Success
Write+Read Empty volume RO RW RW Success
Stat Empty volume RO RW RW Success
Write+Read Host volume RO RW RW Success
Write+Read Host volume RO RO RW Fail
Write+Read Host volume RO RW RO Fail
Write+Read Host volume RO RW unspecified Success
?
?

| `--stage1-hash` | none | Image hash (ex. `--stage1-hash=sha512-dedce9f5ea50`) | A hash of a stage1 image. The image must exist in the store. |
| `--stage1-name` | none | Image name (ex. `--stage1-name=coreos.com/rkt/stage1-coreos`) | A name of a stage1 image. Will perform a discovery if the image is not in the store. |
| `--stage1-path` | none | Absolute or relative path | A path to a stage1 image. |
| `--stage1-url` | none | URL with protocol | A URL to a stage1 image. HTTP/HTTPS/File/Docker URLs are supported. |
Copy link
Member

Choose a reason for hiding this comment

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

If you sort this, you should also sort the same in Documentation/subcommands/prepare.md

Copy link
Member

Choose a reason for hiding this comment

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

This could be done in a follow-up PR if you prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sorted this because this PR was originally implementing runtime flags, I'll submit another PR for sorting docs

tmrts added 2 commits May 13, 2016 13:30
Using the Pod manifest `readOnlyRootFS` option mounts the rootfs of the app
as read-only using systemd-exec unit option `ReadOnlyDirectories`.

Uses `ReadWriteDirectories` systemd-exec unit option for mounting
read-write volumes.

Fixes rkt#2487
Tests shouldn't fail completely when a case fails
@iaguis
Copy link
Member

iaguis commented May 13, 2016

@tmrts has some connection problems, moving to #2624

@iaguis iaguis closed this May 13, 2016
@tmrts tmrts deleted the implement/read-only-rootfs branch May 14, 2016 06:38
@tmrts tmrts restored the implement/read-only-rootfs branch May 23, 2016 10:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants