Commit Graph

23 Commits (1e8c7e7b85dad6f24ec554558a15048a8b29f0f4)

Author SHA1 Message Date
Dustin d117207bd2 Make more project config files optional
`build.packages`, `installonly.packages`, and `busybox.symlinks` are now
optional in the `$CONFIGDIR`.  If they do exist, they are combined with
the same files in the Aimee OS source.
2024-12-05 22:38:49 -06:00
Dustin 02c3a12c08 Support semanage.mods
Aimee OS variants can now supply a `semange.mods` file in their
configuration directories.  This file contains SELinux customizations,
in the format produced by `semanage export`.  Variants can use this
mechanism to set SELinux booleans, change user/login mappings, and other
SELinux policy customization.  At build time, the base `selinux.mods`
file in the source directory is combined with the variant's file, if it
exists, and the resultant customizations are applied in a single
transaction.
2023-03-30 09:23:44 -05:00
Dustin 5fef6f1665 Allow systemd-tmpfiles to manage all files
The `systemd_tmpfiles_manage_all` SELinux boolean allows
systemd-tmpfiles to manage any file, not just the (very small) subset
allowed by the default SELinux policy.  Since we're using
systemd-tmpfiles to create directories and subvolumes for our
applications, we need this setting enabled.
2023-03-30 09:03:45 -05:00
Dustin 089b19e412 Copy all files from /usr/${target} to /usr
It turns out there are actually several packages that install files to
$SYSROOT instead of $ROOT, not just udev rules.
2023-03-29 18:44:45 -05:00
Dustin 82e835e450 Handle absent udev rules dir
It seems the bug that caused udev rules to be installed in the wrong
location has been fixed.  As such, we need to make this corrective
action step conditional, only moving rules files if any are found in the
wrong place.
2023-03-21 19:43:47 -05:00
Dustin 6b262ca0fb Separate base packages from customizations
The `build.packages` and `install.packages` files in the CONFIGDIR now
only need to include *additional* packages to install.  The packages
*required* for Aimee OS are always installed, listed in the
corresponding files in the source directory.
2023-03-21 19:39:33 -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 31d8a98f64 build: Implement CONFIGDIR setting
In effort to support different builds of Aimee OS using the same
scripts, without necessarily having to fork this repository, the build
system now supports a `CONFIGDIR` setting.  When this variable is set,
files defining the target environment, such as the lists of packages to
install, the kernel configuration, the Portage configuration, etc. are
found in the path it specifes.

The reference build, for the Home Assistant Yellow board, is configured
in the `yellow` directory.  To build it, run:

```sh
CONFIGDIR=yellow ./vm-build.sh
```
2023-03-15 21:12:04 -05:00
Dustin e9b21b0ca0 Switch to "mcs" SELinux policy
We're going to want the ability for processes to have unique categories,
to enforce separation of container processes.  Gentoo's SELinux policy
supports both Multi-Category Security and Multi-Level Security modes,
although the latter does not seem to work out of the box.
2023-03-12 21:34:15 -05:00
Dustin a84df60b4a Reinstall packages for updates/changed USE flags
Packages which have been updated and/or had USE flag changes will now be
reinstalled in the destination root directory automatically.
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 47ecbeed19 build-rootfs: Reinstall rebuilt binaries
Binary packages that have been rebuilt since they were installed in the
destination root are now reinstalled automatically.
2023-03-12 12:50:05 -05:00
Dustin ec34ffe7d2 build-rootfs: Pre-generate tmpfiles
Some *tmpfiles.d(5)* entries specify paths in the immutable root
filesystem.  These need to be created at build time to prevent
*systemd-tmpfiles-setup.service* from failing at runtime.
2023-03-12 12:50:05 -05:00
Dustin 20b85fe8e2 Fix setting overlay directory timestamps
Using `tar` to copy files and directories from the overlay directory to
the destination root preserves their timestamps.  This is not really
desirable, particularly for directories, because it may result in the
destination paths appearing older than the build.  This is especially
problematic for `/usr`, since its timestamps are important for systemd
units that use `ConditionNeedsUpdate` settings.

To ensure the timestamps are set correctly, we now use `rsync` to copy
the overlay, with the `-O` (`--omit-dir-times`) argument, to avoid
changing the timestamps of directories.  Additionally, we explicitly
update the timestamp of `/usr` to ensure that every new build triggers
the "needs update" condition.
2023-03-12 12:47:36 -05:00
Dustin 5f62193247 Use Portage config directly from src dir
Instead of copying the Portage configuration files to `/etc/portage` and
`/usr/${target}/etc/portage`, the build scripts now use the
configuration directories from the source directory.  This avoids issues
with changes (especially removal of files) getting propagated to the
actual configuration paths.
2023-03-12 12:47:36 -05:00
Dustin f2d6db5af1 Enable SELinux
Enabling SELinux on the target system needs build-time and run-time
configuration changes for ther kernel and userspace.  Additionally,
SELinux requires a policy that defines allowed operations.  Gentoo
provides a reasonable baseline for all of these changes, but some
modifications are required.

First and foremost, the Gentoo SELinux policy is missing several
necessary rules for systemd-based systems.  Notably, services that use
alternate namespaces will fail to start because the base policy does not
allow systemd components the necessary privileges, so these rules have
to be added.  Similarly, `systemd-journald` needs additional privileges
in order to be able to capture all metadata for processes generating
syslog messages.  Finally, additional rules are necessary in order to
allow systemd to create files and directories prior to launching
servies.

Besides patching the policy, we also do some hackery to avoid shipping
the Python runtime in SELinux-enabled builds.  Several SELinux-related
packages, including *libselinux* and *policycoreutils* have dependencies
on Python modules for some of their functionality.  Unfortunately, the
Python build system does NOT properly cross-compile native extension
modules, so this functionality is not available on the target system.
Fortunately, none of the features provided by these modules are actually
needed at runtime, so we can safely ignore them and thus omit the entire
Python runtime and all Python programs from the final image.

It is important to note that it is impossible to build an
SELinux-enabled image on a host that is itself SELinux-enabled.
Operations such as changing file labels are checked against the SELinux
policy in the running kernel, and may be denied if the target policy
differs significantly from the running policy.  The `setfiles` command
fails, for example, when run on a Fedora host.  As such, building an
SELinux-enabled system should be done in a virtual machine using a
kernel that does not have a loaded SELinux policy.  The `ocivm` script
can be used to create a suitable runtime from a container image.
2023-03-12 12:34:12 -05:00
Dustin dbc02a99a1 Simplify specifying packages to build/install
The Portage packages that need to be built and/or installed are now
specified in the `build.packages` and `install.packages` files,
respectively.  Similarly, packages to be installed on the host system
are specified in `host-tools.packages`.  Finally, the
`installonly.packages` file contains a list of packages that are
installed in the destination root, but not built in the sysroot
beforehand.

This allows `make` to better track when the package sets change.  It
will also make it easier to maintain different sets for different
variants in the future.
2023-03-08 11:12:00 -06:00
Dustin 5e4e37259e Fix overlay file ownerships
By default, `tar` copies file ownership UID/GID.  This works fine when
the build is running in a rootless container, since the source UID/GID
numbers are mapped to 0/0 inside the container.  In other scenarios,
though, such as building in a microvm with the source directory on a
shared filesystem, the original numbers are preserved.  We need to
explicitly state that the files must be owned by root.
2023-03-03 12:36:15 -06:00
Dustin f182a4329b Remove unused locales
This reduces the size of the (compressed) image by a few megabytes.
2023-02-14 19:51:27 -06:00
Dustin d4fdb36d45 Exclude more extraneous files from rootfs image 2023-02-14 00:30:32 -06:00
Dustin f32c6d37a4 build-rootfs: Avoid spurious boot errors
The *ldconfig.service* fails because `/etc` is not writable and thus
`/etc/ld.so.cache` cannot be generated.

The files specified in the `provision.d` *tmpfiles.d(5)* configuration
are unnecessary, and many of them cannot be created at runtime because
the root filesystem is immutable.
2023-02-13 23:24:36 -06:00
Dustin fef78afa31 build-rootfs: Create /lib and /lib64 symlinks 2023-02-13 23:24:36 -06:00
Dustin 025b7c6115 Initial commit 2023-02-13 23:24:36 -06:00