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

overlay/boot-mount-generator: Mount /boot{,efi} read-only,nodev,nosuid #659

Merged
merged 1 commit into from
Jan 7, 2021

Conversation

cgwalters
Copy link
Member

@cgwalters cgwalters commented Oct 2, 2020

ostree has had support for leaving /boot mounted read-only
for a long time: ostreedev/ostree#1767
(And then later extended to /sysroot)

Particularly for CoreOS, only a few things should be touching
/boot, and we control all of them. Those projects should
create a new mount namespace and remount these partitions
writable just while they need it.

The main thing we're accomplishing here is making the system
more resilient against accidental damage from a sysadmin
root shell as well as configuration management tools like
Puppet/Ansible. None of those should be directly manipulating
files on these partitions, they should go through the API
of one of our projects (e.g. rpm-ostree kargs, bootupctl) etc.

While we're here, also andd nodev,nosuid because some
OS hardening scanners like to see this. IMO it's of minimal
value, but hey, might as well.

@cgwalters
Copy link
Member Author

Heh I forgot about #356 and just saw it - incorporated that too.

@cgwalters
Copy link
Member Author

This needs to resolve
#356 (comment)
and at least bootupd needs to learn to do the remounting dance.

@cgwalters
Copy link
Member Author

One thing this does break is that I think it would be nice if sysadmins could just vi /boot/loader/entries - having a standardized text format is part of the idea. But...eh. We want fcct sugar for kargs which would use rpm-ostree kargs probably anyways, and for OpenShift the MCO already uses rpm-ostree kargs today too.

@cgwalters cgwalters changed the title overlay/boot-mount-generator: Mount /boot and /boot/efi read-only overlay/boot-mount-generator: Mount /boot{,efi} read-only,nodev,nosuid Oct 2, 2020
@cgwalters
Copy link
Member Author

Also after this let's revisit #407

cgwalters added a commit to cgwalters/bootupd that referenced this pull request Oct 6, 2020
I was debugging a failure to write the statefile which
turned out to be me having
coreos/fedora-coreos-config#659
locally.

Anyways let's add some error context to aid future debugging.
cgwalters added a commit to cgwalters/bootupd that referenced this pull request Oct 6, 2020
I was debugging a failure to write the statefile which
turned out to be me having
coreos/fedora-coreos-config#659
locally.

Anyways let's add some error context to aid future debugging.
openshift-merge-robot pushed a commit to coreos/bootupd that referenced this pull request Oct 6, 2020
I was debugging a failure to write the statefile which
turned out to be me having
coreos/fedora-coreos-config#659
locally.

Anyways let's add some error context to aid future debugging.
kelvinfan001 added a commit to kelvinfan001/ignition that referenced this pull request Nov 13, 2020
coreos/fedora-coreos-config#659 attempts to
mount `/boot` read-only. Currently, the firstboot network dir in
`/boot` is cleaned up by a tmpfiles.d conf file. This may not be
possible once `/boot` is read-only, so we do the clean up here.
kelvinfan001 added a commit to kelvinfan001/fedora-coreos-config that referenced this pull request Nov 13, 2020
coreos#659 attempts to
mount `/boot` read-only. `15-coreos-firstboot-network.conf`'s job
should be handled by `ignition-firstboot-complete.service` which
remounts writable (privately/temporarily) `/boot` from the real root.
kelvinfan001 added a commit to kelvinfan001/fedora-coreos-config that referenced this pull request Nov 18, 2020
We would like to mount `/boot` read-only in the real root, so add a
new unit in 15coreos-network to temporarily mount /boot rw and clean
up firstboot networking configuration files late in the initramfs.
Remove the current 15-coreos-firstboot-network.conf since it would
not work once `/boot` is mounted ro.

xref coreos#659
kelvinfan001 added a commit to kelvinfan001/fedora-coreos-config that referenced this pull request Nov 18, 2020
We would like to mount `/boot` read-only in the real root, so add a
new unit in 15coreos-network to temporarily mount /boot rw and clean
up firstboot networking configuration files late in the initramfs.
Remove the current 15-coreos-firstboot-network.conf since it would
not work once `/boot` is mounted ro.

xref coreos#659
kelvinfan001 added a commit to kelvinfan001/fedora-coreos-config that referenced this pull request Nov 18, 2020
We would like to mount `/boot` read-only in the real root, so add a
new unit in 15coreos-network to temporarily mount /boot rw and clean
up firstboot networking configuration files late in the initramfs.
Remove the current 15-coreos-firstboot-network.conf since it would
not work once `/boot` is mounted ro.

xref coreos#659
kelvinfan001 added a commit to kelvinfan001/fedora-coreos-config that referenced this pull request Nov 19, 2020
We would like to mount `/boot` read-only in the real root, so add a
new unit in 15coreos-network to temporarily mount /boot rw and clean
up firstboot networking configuration files late in the initramfs.
Remove the current 15-coreos-firstboot-network.conf since it would
not work once `/boot` is mounted ro.

xref coreos#659
kelvinfan001 added a commit to kelvinfan001/fedora-coreos-config that referenced this pull request Nov 19, 2020
We would like to mount `/boot` read-only in the real root,
so remove the current 15-coreos-firstboot-network.conf since
it would not work once `/boot` is mounted ro. Drop a stamp
file instead so that `coreos-boot-edit.service` would notice
and perform the clean up later in the initramfs.

xref coreos#659
kelvinfan001 added a commit that referenced this pull request Nov 23, 2020
We would like to mount `/boot` read-only in the real root,
so remove the current 15-coreos-firstboot-network.conf since
it would not work once `/boot` is mounted ro. Drop a stamp
file instead so that `coreos-boot-edit.service` would notice
and perform the clean up later in the initramfs.

xref #659
@kelvinfan001
Copy link
Member

@cgwalters With the updates to how copy-firstboot-network is done and also the patch in bootupd to ensure /boot and /boot/efi writable, is this ready to be merged once the next release of bootupd is out?

kelvinfan001 added a commit to kelvinfan001/fedora-coreos-config that referenced this pull request Dec 14, 2020
We would like to mount `/boot` read-only in the real root,
so remove the current 15-coreos-firstboot-network.conf since
it would not work once `/boot` is mounted ro. Drop a stamp
file instead so that `coreos-boot-edit.service` would notice
and perform the clean up later in the initramfs.

xref coreos#659
@kelvinfan001 kelvinfan001 force-pushed the boot-ro branch 2 times, most recently from 09e5e48 to 7b576a3 Compare January 6, 2021 16:23
@kelvinfan001 kelvinfan001 marked this pull request as ready for review January 6, 2021 16:23
@kelvinfan001 kelvinfan001 requested a review from jlebon January 6, 2021 16:24
@jlebon
Copy link
Member

jlebon commented Jan 6, 2021

This is remounting /boot/efi, which we stopped mounting in #794 as per coreos/fedora-coreos-tracker#694.

@jlebon
Copy link
Member

jlebon commented Jan 6, 2021

Ahh OK, is this related to openshift/os#480 (comment) ? I.e. are we backtracking for the time being and going back to mounting /boot/efi by default until bootupd learns to mount it itself?

@kelvinfan001
Copy link
Member

kelvinfan001 commented Jan 6, 2021

@jlebon Actually that was my bad, the latest release of bootupd should be able to handle a not-mounted EFI and a read-only /boot. I simply rebased this PR on the latest testing-devel. We should indeed remove the EFI mount section from this PR.
All this PR should be doing now is mounting /boot as RO and adding nodev,nosuid.

are we backtracking for the time being and going back to mounting /boot/efi by default until bootupd learns to mount it itself?

I think https://github.com/coreos/bootupd/releases/tag/v0.2.5 should mean we don't need to backtrack.

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

Commit title still references efi and also andd -> add in the commit message.

LGTM otherwise!

Comment on lines 80 to 81
boot_mount_options=ro,nodev,nosuid
mk_mount /boot boot "${boot_mount_options}"
Copy link
Member

Choose a reason for hiding this comment

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

Minor/optional: meh, I'd just inline these. It made sense before because we were re-using it for the EFI mount as well.

ostree has had support for leaving `/boot` mounted read-only
for a long time: ostreedev/ostree#1767
(And then later extended to `/sysroot`)

Particularly for CoreOS, only a few things should be touching
`/boot`, and we control all of them.  Those projects should
create a new mount namespace and remount these partitions
writable just while they need it.

The main thing we're accomplishing here is making the system
more resilient against accidental damage from a sysadmin
root shell as well as configuration management tools like
Puppet/Ansible.  None of those should be directly manipulating
files on these partitions, they should go through the API
of one of our projects (e.g. `rpm-ostree kargs`, `bootupctl`) etc.

While we're here, also add `nodev,nosuid` because some
OS hardening scanners like to see this.  IMO it's of minimal
value, but hey, might as well.
@kelvinfan001 kelvinfan001 merged commit 1de21ff into coreos:testing-devel Jan 7, 2021
cgwalters added a commit to cgwalters/ostree that referenced this pull request Jan 9, 2021
The recent change in coreos/fedora-coreos-config#659
broke some of our tests that do `mount -o remount,rw /sysroot` but
leave `/boot` read-only.

We had code for having `/boot` read-only before `/sysroot` but
in practice we had a file descriptor for `/sysroot` that we opened
before the remount that would happen later on.

Clean things up here so that in the library, we also remount
`/boot` at the same time we remount `/sysroot` if either are readonly.

Second, adapt the client side code to check for either being
readonly to enable the mount namespace.  Now honestly we could
almost certainly just set this unconditionally - the original
client code here is just being excessively conservative.  But
I'd like to make that cleanup independently of this fix.
cgwalters added a commit to cgwalters/ostree that referenced this pull request Jan 9, 2021
The recent change in coreos/fedora-coreos-config#659
broke some of our tests that do `mount -o remount,rw /sysroot` but
leave `/boot` read-only.

We had code for having `/boot` read-only before `/sysroot` but
in practice we had a file descriptor for `/sysroot` that we opened
before the remount that would happen later on.

Clean things up here so that in the library, we also remount
`/boot` at the same time we remount `/sysroot` if either are readonly.

Delete the legacy code for remounting `/boot` rw if we're not in
a mount namespace.  I am fairly confident most users are either
using the `ostree` CLI, or they're using the mount namespace.
cgwalters added a commit to cgwalters/ostree that referenced this pull request Jan 9, 2021
The recent change in coreos/fedora-coreos-config#659
broke some of our tests that do `mount -o remount,rw /sysroot` but
leave `/boot` read-only.

We had code for having `/boot` read-only before `/sysroot` but
in practice we had a file descriptor for `/sysroot` that we opened
before the remount that would happen later on.

Clean things up here so that in the library, we also remount
`/boot` at the same time we remount `/sysroot` if either are readonly.

Delete the legacy code for remounting `/boot` rw if we're not in
a mount namespace.  I am fairly confident most users are either
using the `ostree` CLI, or they're using the mount namespace.
cgwalters added a commit to cgwalters/ostree that referenced this pull request Jan 10, 2021
The recent change in coreos/fedora-coreos-config#659
broke some of our tests that do `mount -o remount,rw /sysroot` but
leave `/boot` read-only.

We had code for having `/boot` read-only before `/sysroot` but
in practice we had a file descriptor for `/sysroot` that we opened
before the remount that would happen later on.

Clean things up here so that in the library, we also remount
`/boot` at the same time we remount `/sysroot` if either are readonly.

Delete the legacy code for remounting `/boot` rw if we're not in
a mount namespace.  I am fairly confident most users are either
using the `ostree` CLI, or they're using the mount namespace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants