Commit Graph

15 Commits (caa303ba3d18f47571fd48704106357e7e49ec49)

Author SHA1 Message Date
Dustin 77f7e6d8cc init-storage: Create intermediate dirs in /etc
When creating writable paths in the `/etc` subvolume, the `setup_etc`
function needs to create intermediate directories before copying
existing files from the root filesystem.  Without this step, `cp` will
fail with a "no such file or directory" error, referring to the
destination path.
2023-03-30 09:31:12 -05:00
Dustin a87a7d6f3e init-storage: Resize data partition
If the data volume is a partition (rather than a whole disk device), the
`init-storage` script will now attempt to resize it to use all
unallocated space on the disk.  This only works if it is the last
partition on the disk.  This situation is common when writing the
`sdcard.img` file directly to a disk that is larger than 4 GiB.
2023-03-29 18:44:45 -05:00
Dustin 7293415b40 init-storage: Support custom writable paths in /etc
Custom builds of Aimee OS can now specify additional paths under `/etc`
that should be writable.  This is accomplished by populating a file
named `/etc/aimee-os/writable-etc` with a list of paths.  Each line must
indicate the type of file (regular file: `f`, directory: `d`) and the
*relative* path under `/etc`.
2023-03-21 19:44:43 -05:00
Dustin 5e8b69d659 factory-reset: Remove errant debug command
I added this `seq` command to make it easier to see output from
`factory-reset` on the serial console.  It's no longer necessary.
2023-03-15 21:48:44 -05:00
Dustin a4baa58563 Read /etc/fstab to determine data partition
Rather than hard-code the GPT partition label into the `init-storage`
and `factory-reset` scripts, these now determine the block device by
reading `/etc/fstab` and using the device specified for `/var`.
2023-03-15 21:48:44 -05:00
Dustin b38f48b72f Create subvolumes in init-storage
It turns out that we cannot use `systemd-tmpfiles` to create our Btrfs
subvolumes.  Since the directories we are interested in, specifically
`/var/log` and `/var/tmp` already exist in the rootfs image and are
therefore copied into the mutable filesystem, `systemd-tmpfiles` ignores
them.

To avoid having to explicitly specify the SELinux context for each
subvolume created on the persistent filesystem, `init-storage` now
executes `setfiles` to set the appropriate labels.
2023-03-15 21:45:30 -05:00
Dustin eb8f4c3b40 Make /etc/shadow writable
In order for users to be able to log in locally or via SSH without an
authorized key, they will need to have passwords set in `/etc/shadow`.
We do not really want to make all of `/etc` writable, so we will store
the actual `shadow` file on the persistent data volume, in a separate
Btrfs subvolume, and then bind-mount it at `/etc/shadow`.

While this makes `/etc/shadow` mutable, it does not actually let the
`passwd` program modify it.  This is because `passwd` creates lock files
and backup files in `/etc`.  We will ultimately need a wrapper to
"trick" `passwd` into modifying `/etc/shadow`, without making the whole
`/etc` directory mutable.
2023-03-15 21:17:18 -05:00
Dustin 292a4d2268 init-storage: Copy file contexts from rootfs
Apparently, BusyBox's `cp` does NOT copy SELinux contexts when the `-a`
argument is specified.  This differs from GNU coreutils's `cp`, and
explains why the files copied from the rootfs image to the persistent
storage volume were not being labelled correctly.  The `-c` argument is
required.

Now that files are labelled correctly when they are copied, the step to
run `restorecon` is no longer necessary.
2023-03-15 21:14:33 -05:00
Dustin cb7e0a5819 init-storage: Set SELinux context for /var
This label needs to be applied before the subvolume is mounted initially
to prevent AVC denials.
2023-03-12 12:53:16 -05:00
Dustin 9d507c74ae Create /var/log with systemd-tmpfiles
*systemd-tmpfiles* can create btrfs subvolumes with the `v` entry type.
Using this mechanism instead of the `init-storage` script will allow for
greater flexibility when adding other subvolumes later.

Unfortunately, the default configuration for *systemd-tmpfiles* already
includes an entry for `/var/log` with the `d` (directory) type.  Since
individual entries cannot be overridden, we need to modify this entry.
2023-03-12 12:53:16 -05:00
Dustin 274c592f5d Add factory reset feature
The `factory-reset` command provides a way to completely wipe the data
partition, thus erasing any local configuration and state.  The command
itself simply enables a special systemd service unit that is activated
during the shutdown process.  This unit runs a script, after all
filesystems, except rootfs, have been unmmounted.  It then erases the
signature of the filesystem on the data partition, so it will appear
blank the next time the system boots.  This will trigger the
`init-storage` process, to create a new filesystem on the partition.
2023-03-12 12:50:05 -05:00
Dustin 5939fb525c init-storage: Use a static path as mount point
There's no particular reason why the directory used as the temporary
mount point for the data volume needs to be random.  Using a static
name, on the other hand, makes it easier for the SELinux policy to
apply the correct type transition and ensure the directory is labelled
correctly.
2023-03-12 12:47:36 -05:00
Dustin 301589af22 Store SSH host keys in /var/lib/ssh
For some reason, when OverlayFS is mounted at `/etc/ssh`, SELinux
prevents access both `sshd` and `ssh-keygen` access to the files there.
The AVC denials indicate that (some part of) the process is running in
the `mount_t` domain, which is not allowed to read or write `sshd_key_t`
files.

To work around this issue, without granting `mount_t` overly-permissive
access, we now configure the SSH daemon to read host keys from the
persistent data volume directly, instead of "tricking" it with
OverlayFS.  The `ssh-keygen` tool does not read the `HostKey` options
from `sshd_config`, though, so it has to be explicitly instructed to
create keys in this alternate location.  By using a systemd template
unit with `ConditionPathExists`, we avoid regnerating the keys on every
boot, since the `ssh-keygen` command is only run if the file does not
already exist.
2023-03-12 12:47:36 -05:00
Dustin fe3cc25f6b fstab: Only overlay /etc/ssh
There's really no sense in creating a writable copy of the whole `/etc`
hierarchy at `/run/etc/rw`.  Instead, let's just mount overlays at the
paths we want to make writable (which for now is only `/etc/ssh`).
2023-02-14 21:05:54 -06:00
Dustin 025b7c6115 Initial commit 2023-02-13 23:24:36 -06:00