Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

WIP: Redeploy rootfs #107

Closed
wants to merge 3 commits into from
Closed

Conversation

cgwalters
Copy link
Member

This is a quick hack to add a 31ignition-ostree module that can take care of redeploying the rootfs between ignition-disks.service and ignition-mount.service.

We obviously only want to run this if the user has provided an Ignition config that replaces the root labeled filesystem. Doing so I think would require adding something like a separate ignition-parse.service stage that touches a stamp file /run/ignition-rootfs-replaced or so, and these services key off that?

I'm working on this because openshift/enhancements#15 needs it.

@cgwalters
Copy link
Member Author

OK this turns out to block on the SELinux/initramfs issue: #79 (comment)

Everything ends up unlabeled_t because mv/cp see policy isn't loaded, but we need to force them to preserve contexts.

Also annoying is that cp/mv don't exit on the first error. It's tempting to implement this in rpm-ostree (in Rust and not shell script) as something like rpm-ostree coreos-internals redeploy-rootfs.

@jlebon
Copy link
Member

jlebon commented Sep 18, 2019

More specifically, it blocks on https://lore.kernel.org/selinux/20190912133007.27545-1-jlebon@redhat.com/T/#u. The third paragraph in the commit message covers this exact use case. :)

Without that, we're basically stuck between two bad options (loading the policy in the initrd or doing some kind of clever hack so we can redeploy post-pivot but then we'd still have to reboot).

@darkmuggle
Copy link
Contributor

I'm working on this because openshift/enhancements#15 needs it.

To clarify: this will be useful, and I think we should include it, but the enhancement request does not need it. The enhancement request specifically states the root filesystem will be written in a null-cipher encrypted root filesystem, for the simple reason that Ignition is lacking support for setting up LUKS volumes.

Where I see this work being immediately relevant is that if a user does not want encryption, then the LUKS container can be replaced. Longer-term, once Ignition supports setting up LUKS, then we can have a default Ignition configuration for setting up LUKS and use this Dracut module to rewrite the filesystem.

@darkmuggle darkmuggle closed this Sep 18, 2019
@darkmuggle darkmuggle reopened this Sep 18, 2019
@darkmuggle
Copy link
Contributor

Sorry.... @cgwalters that was entirely an accidental closure.

@cgwalters
Copy link
Member Author

The enhancement request specifically states the root filesystem will be written in a null-cipher encrypted root filesystem, for the simple reason that Ignition is lacking support for setting up LUKS volumes.

Sure, but I don't like the idea of shipping that versus solving the full general problem. We already had to close PRs like coreos/coreos-installer#48 because we don't have this.

@cgwalters
Copy link
Member Author

@ajeddeloh When you get a few can you look over this from an architecture perspective? Particularly bits like:

How do we hook in a "post-parse pre-disks" Ignition hook for this to run?

Relatedly, do you think it's better if Ignition gained an optional ostree integration (and had this code, hence no direct hook necessary) or if (rpm-)ostree gained this code and we had the hook?

@ajeddeloh
Copy link
Contributor

In general I'm in favor of this and the post-parse-pre-disks hook. This is dependent on splitting parsing into it's own stage, but I've been wanting to do that anyway (this has also been called "stage 0"). I'm not sure how coupled to Ignition it ought to be. The simplest way would be to say "is there a filesystem in the config with "label": "root". It could give false positives in some cases but shouldn't give false negatives. That is simple enough we could do it with just jq, I think an Ignition stage would be excessive for that. If we end up needing something more complex we can also switch to an Ignition stage.

The only concern with false positives I have is it's a performance penalty. We could reduce it a fair bit by not blowing away the rootfs prematurely (looks like that might just be for testing in this pr?) and checking if there are ostree files already before redeploying. This still has the save penalty, but not the restore.

@cgwalters
Copy link
Member Author

I don't quite understand your suggestion; I was thinking of a ignition-fetch.service which ran a fetch stage which just wrote /run/ignition.json - from there we could parse it with jq as you say.

In general I'm in favor of this and the post-parse-pre-disks hook

When I was saying "hook" I was thinking of how we use systemd units today to separate things out. Were you thinking something more like a build-time option for Ignition that ran a specified binary? Or an /etc/ignition/post-fetch-hooks.d?

@ajeddeloh
Copy link
Contributor

I was thinking of a ignition-fetch.service which ran a fetch stage which just wrote /run/ignition.json - from there we could parse it with jq as you say.

When I was saying "hook" I was thinking of how we use systemd units today to separate things out.

That's exactly what I was thinking of, we're on the same page.

Were you thinking something more like a build-time option for Ignition that ran a specified binary?

Only if jq proves insufficient

Or an /etc/ignition/post-fetch-hooks.d?

Wouldn't be needed with a fetch stage (can use systemd units)

cgwalters added a commit to cgwalters/ignition that referenced this pull request Sep 24, 2019
This stage just triggers the internal code which fetches the
config and writes `/run/ignition.json`; from there it'd be picked
up by later stages the way it was implicitly before.

This is prep for adding support for redeploying the rootfs for
Fedora CoreOS; we need to have a separate process determine
whether the rootfs is being replaced, and if so do a save/restore
across `ignition-disks.service`.

See: coreos/ignition-dracut#107
cgwalters added a commit to cgwalters/ignition that referenced this pull request Sep 24, 2019
This stage just triggers the internal code which fetches the
config and writes `/run/ignition.json`; from there it'd be picked
up by later stages the way it was implicitly before.

This is prep for adding support for redeploying the rootfs for
Fedora CoreOS; we need to have a separate process determine
whether the rootfs is being replaced, and if so do a save/restore
across `ignition-disks.service`.

See: coreos/ignition-dracut#107
@cgwalters
Copy link
Member Author

cgwalters commented Sep 24, 2019

OK cool split that out into #110 and wrote some jq and code to try to conditionalize this.

Also here's the rootfs.fcct I've been testing out:

# Example of redeploying the rootfs as ext4
variant: fcos
version: 1.0.0
storage:
  filesystems:
    - device: /dev/disk/by-partlabel/root
      format: ext4
      wipe_filesystem: true
      label: root

@cgwalters cgwalters force-pushed the redeploy-rootfs branch 2 times, most recently from 5fcd392 to cd23232 Compare September 24, 2019 18:42
cgwalters added a commit to cgwalters/ignition that referenced this pull request Sep 24, 2019
This stage just triggers the internal code which fetches the
config and writes `/run/ignition.json`; from there it'd be picked
up by later stages the way it was implicitly before.

This is prep for adding support for redeploying the rootfs for
Fedora CoreOS; we need to have a separate process determine
whether the rootfs is being replaced, and if so do a save/restore
across `ignition-disks.service`.

See: coreos/ignition-dracut#107
I had this fix in my WIP ignition-ostree-rootfs stack, and apparently
missed putting it in the split-out change.

This service runs really really early on, it can't be `After=basic.target`.
I'm working on supporting reprovisioning the rootfs with Ignition
on OSTree based systems like Fedora CoreOS, and this will add
a lot of tricky logic that relates the two.

While we want to support Ignition independent of OSTree and vice
versa, it will be a lot cleaner if we centralize the dracut
logic in one place.

This adds a `31ignition-ostree` module that imports the code
from
https://github.com/coreos/fedora-coreos-config/tree/092f680a5c75324e3efcd5e50374a2c1b5d4b057/overlay.d/05core/usr/lib/dracut/modules.d/40coreos-var

Most notably, this is:

 1) A separate dracut module easily skippable
 2) The units use `ConditionKernelCommandline=ostree` so will be harmless even if included

The units imported here also do this:

```
ConditionPathExists=!/usr/sbin/coreos-mount-var
```

So this change can be safely merged, built and shipped as an RPM,
then we can drop the FCOS config bits and enable it later.

Tested both ways (inert and enabled).

And to clarify, the later ignition-ostree-rootfs stuff will land
in this same dracut module.
For redeploying the rootfs
@cgwalters
Copy link
Member Author

Moved to coreos/fedora-coreos-config#184

@cgwalters cgwalters closed this Sep 26, 2019
cgwalters added a commit to cgwalters/ignition that referenced this pull request Sep 26, 2019
This stage just triggers the internal code which fetches the
config and writes `/run/ignition.json`; from there it'd be picked
up by later stages the way it was implicitly before.

This is prep for adding support for redeploying the rootfs for
Fedora CoreOS; we need to have a separate process determine
whether the rootfs is being replaced, and if so do a save/restore
across `ignition-disks.service`.

See: coreos/ignition-dracut#107
(cherry picked from commit 8926f0f)
cgwalters added a commit to cgwalters/ignition that referenced this pull request Sep 27, 2019
This stage just triggers the internal code which fetches the
config and writes `/run/ignition.json`; from there it'd be picked
up by later stages the way it was implicitly before.

This is prep for adding support for redeploying the rootfs for
Fedora CoreOS; we need to have a separate process determine
whether the rootfs is being replaced, and if so do a save/restore
across `ignition-disks.service`.

See: coreos/ignition-dracut#107
(cherry picked from commit 8926f0f)
cgwalters added a commit to cgwalters/ignition that referenced this pull request Oct 1, 2019
This stage just triggers the internal code which fetches the
config and writes `/run/ignition.json`; from there it'd be picked
up by later stages the way it was implicitly before.

This is prep for adding support for redeploying the rootfs for
Fedora CoreOS; we need to have a separate process determine
whether the rootfs is being replaced, and if so do a save/restore
across `ignition-disks.service`.

See: coreos/ignition-dracut#107
(cherry picked from commit 8926f0f)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants