Commit graph

728 commits

Author SHA1 Message Date
Florian Schüller
0f5db9a283 stages: fix some documentation typos to prepare for spellchecking 2024-09-04 12:17:58 +02:00
Ondřej Budai
2f84ba96c9 stages: add a new mkswap stage
A stage very similar to the existing mkfs ones (actually, I started from
the xfs one). It creates a swap area on a given device.
2024-09-02 15:27:32 +02:00
Achilleas Koutsou
1093b5eeb2 util/chroot: use subprocess.run() for all commands
For consistency, use subprocess.run() with check=True for the calls that
were previously using subprocess.check_call().

Update the affected tests to match.
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
3dbf389ebf util/chroot: add run() method to context class
Rename the ChrootProcDevSys class to just Chroot and add a run() method.
Calls now can be made using:

  with Chroot(root) as chroot:
      chroot.run(command)
2024-08-28 16:45:48 -07:00
Achilleas Koutsou
931e832944 test/dracut: update subprocess.run() call count 2024-08-28 16:45:48 -07:00
Michael Vogt
3b77eb3625 stages: workaround the two remaining autopep8 issues via noqa
Small followup for https://github.com/osbuild/osbuild/pull/1864

There were two issues from `autopep8` left, both can be just
silenced via the `# noqa` directive.
2024-08-26 23:19:17 +02:00
Paweł Poławski
db08c472f3 general: Fix linter issues across the codebase 2024-08-26 11:59:46 -07:00
Achilleas Koutsou
27e1e9f774 test/bootc_install_config: parse config for result
Different toml libraries write arrays differently, so we can't know
exactly what the file contents will look like.  Some will write an array
in a single line (toml) while others will break it into one element per
line (tomli_w).  Parse the file that's written by the stage so we can
compare the objects instead of the text contents directly.
2024-08-21 19:26:31 +02:00
Achilleas Koutsou
292d4ad0fe stages: replace toml imports with our util module 2024-08-21 19:26:31 +02:00
Achilleas Koutsou
69625505cf util/chroot: rename context class to ChrootProcDevSys
Rename the context class to better describe what it's doing.  It doesn't
run anything in a chroot, but it prepares the tree for it.
2024-08-21 18:50:05 +02:00
Achilleas Koutsou
8e41ec58a7 stages/update-crypto-policies: use Chroot context
Recently [1], the update-crypto-policies script added a check to verify
that the FIPS policy was automounted by reading the
/proc/self/mountinfo.  The script will fail if the proc filesystem isn't
available.

Use the new Chroot context to set up the environment for the command.

[1] 04ceadccfc
2024-08-21 18:50:05 +02:00
Achilleas Koutsou
9edda1d163 osbuild/util: new module: chroot
New chroot utility module that sets up a tree with the necessary virtual
filesystems needed for running commands in the root tree in a similar
environment as they would run in the build root.

This is needed for some stages, but may also be used for all chroot
calls to unify the setup and teardown of the root environment.

The Chroot context class was previously part of the org.osbuild.dracut
stage, which was the first stage to need this setup.
2024-08-21 18:50:05 +02:00
Tomáš Hozza
e1df8cea8f Stages/dracut: prepare environment for running dracut in chroot
dracut expects the environment, in which it is run, to have properly
mounted /proc, /dev and /sys. Otherwise, some of its modules don't work
properly. E.g. dracut fails to embed the CA cert bundle into the initram
disk, which means that HTTPS won't work in it. dracut also prints a lot
of errors and warnings about this, but we used to ignore them until now.

The buildroot environment in which the stage runs is OK, but we actually
run dracut using 'chroot', which is the core of the problem. The runtime
environment in such case lacks the necessary mounts.

Add a context manager for setting up and cleaning up all the necessary
mounts in the image FS tree when running dracut.

This change is related to:
https://bugzilla.redhat.com/show_bug.cgi?id=1962975

And the implementation has been inspired by the fix in lorax:
https://github.com/weldr/lorax/pull/1151

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-08-15 19:56:20 +02:00
Paweł Poławski
b516bdca93 Tests: Add unit tests for org.osbuild.gunzip stage 2024-08-02 08:48:06 +02:00
Gianluca Zuccarelli
3fa8ab8cbc stages/autotailor: fix stage schema
There was a small mistake in the schema since either one of
`new_profile` or `tailored_profile_id` is required. This commit fixes
this and updates the tests to check for this case.
2024-07-25 11:56:07 +02:00
Gianluca Zuccarelli
cca6668b42 test/oscap.autotailor: json profile id shadowing 2024-07-17 13:14:48 +02:00
Gianluca Zuccarelli
a87b1ba852 test/oscap: autotailor json schema validation
Add basic schema validation unit test for the JSON autotailor options.
2024-07-17 13:14:48 +02:00
Gianluca Zuccarelli
92bb161501 stages/oscap.autotailor: make profile id required
According to `autotailor(8)` arguments passed in via the cli take
precedence over the JSON tailoring file contents.

Make the `new_profile` a required field for the json tailoring too and
pass it as an option to the `autotailor` command. This approach has some
trade-offs. It allows us to maintain the explicitness of the manifest
that is consumed by `osbuild`. The downside is that it will override the
profile id that is set by the user in the JSON tailoring file.
2024-07-17 13:14:48 +02:00
Gianluca Zuccarelli
2a28acbc85 stages/oscap.autotailor: rename new_profile
Rename the `new_profile` option to `tailoring_profile_id` for clarity.
This also ensures that the change is backwards compatible by falling
back to the `new_profile` option if that was set instead of the
`tailoring_profile` id option.
2024-07-17 13:14:48 +02:00
Gianluca Zuccarelli
24c26e7787 stages/oscap.remediation: small import adjustment
This is a small adjustment to how the `osbuild.util.mnt.mount` fuction
is imported. While adding unit tests, the tests failed when trying to
patch the function, this commit fixes the issue.
2024-07-11 12:26:13 +02:00
Gianluca Zuccarelli
a1beb4d295 stages/oscap.remediation: setup env helper
Add a small helper function to setup the mountpoints and symlink for the
stage. This will help in making the stage easier to test.
2024-07-11 12:26:13 +02:00
Nikita Dubrovskii
cb978d3c72 stages: add stage for creating dm-verity partitions
Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
2024-07-03 16:54:32 +02:00
Gianluca Zuccarelli
5ec5c892bf stages/oscap.autotailor: add json import unit test
Add a small unit test for the json tailoring file import.
2024-05-31 19:51:46 +01:00
Gianluca Zuccarelli
4db6d4c1b4 stages/oscap.autotailor: add json tailoring
With the `oscap-utils-1.3.10` release, the `autotailor` command now
supports importing a JSON tailoring file[1] that is then converted to the
XML tailoring file which is consumed by the `oscap` command in the
remediation stage.

[1] https://github.com/ComplianceAsCode/schemas/blob/main/tailoring/schema.json
2024-05-31 19:51:46 +01:00
Andre Marianiello
4dbf8e2d59 stages(users): add additional tests for force_password_reset 2024-05-20 14:13:56 -07:00
Michael Vogt
af7485b406 stages(users): add small unit test that passwd is called correctly 2024-05-20 14:13:56 -07:00
Andre Marianiello
b722bef9cb stages/org.osbuild.users: Add force password reset option
Add the force_password_reset field to the users option in the
org.osbuild.users stage. This option forces the user to change their
password on first login.
2024-05-20 14:13:56 -07:00
Achilleas Koutsou
88974ab052 stages/systemd.unit.create: validation function
Cleaner and makes the linter happy (too-many-branches).
2024-05-17 14:26:14 +02:00
Achilleas Koutsou
e92b683e11 test/systemd_unit_create: mount unit type creation 2024-05-17 14:26:14 +02:00
Achilleas Koutsou
f085714a7e test/systemd_unit_create: filename-config validation 2024-05-17 14:26:14 +02:00
Achilleas Koutsou
425ba46f50 test/systemd_unit_create: Mount schema validation 2024-05-17 14:26:14 +02:00
Achilleas Koutsou
5d57f84d4d stages/systemd.unit.create: validate filename sections
Based on the filename, different sections of the unit configuration are
valid.  Service (.service) units require a [Service] section and mount
(.mount) units requires a [Mount] section.

It might be possible to validate this in the schema but it would
probably require a major rewrite and could get complicated.  For now,
validate it in the stage code itself.
2024-05-17 14:26:14 +02:00
Achilleas Koutsou
835b49d052 stages/systemd.unit.create: update schema to support [Mount] 2024-05-17 14:26:14 +02:00
Achilleas Koutsou
a42b797787 test/systemd_unit_create: add Before value
Add test value for Before.
2024-05-14 11:17:02 +02:00
Achilleas Koutsou
361614c202 stage/systemd.unit.create: add Before option
Support the Before option in the Unit section of the unit file.
2024-05-14 11:17:02 +02:00
Paweł Poławski
cae97bb73a Tests: Add unit tests for org.osbuild.mkfs.fat stage 2024-05-14 09:34:40 +02:00
Achilleas Koutsou
86f3459eef stages: add unit test for bootc.install.config stage 2024-05-06 14:09:47 +02:00
Achilleas Koutsou
e94aef7dce stages: new bootc.install.config stage
New stage for writing a bootc-install-config with all the options
currently supported.  See bootc-install-config(5).
2024-05-06 14:09:47 +02:00
Michael Vogt
11d41ab5a2 stages: remove test_schema_supports_bootc_style_mounts tests
With PR#1727 merged there is no need to test for individual stages
if they support the bootc style mounting in their schema. All
stages now support devices/mounts now. So let's remove this
redundant code.
2024-05-03 11:26:22 +02:00
Ondřej Budai
5da9a2fb63 stages/kickstart: add support for the dir transport
Also, let's adjust the test.
2024-05-03 11:13:44 +02:00
Ondřej Budai
1b5b015fef stages/skopeo: Fix the remove-signatures option
It's defined on the options level, not on the destination level.
A previous commit added a test for this.
2024-05-01 00:23:02 +02:00
Ondřej Budai
2e771692a7 stages/test: Check that remove_signatures is passed to skopeo-copy
Quite a dirty test, but it will get the job done.
2024-05-01 00:23:02 +02:00
Michael Vogt
d50857e5aa stages: fix test values for "images" inputs
The "images" inputs in the tests were bad test values and only worked
"by accident" [0]. Thanks to Achilleas for discovering this!

This commit fixes this.

[0] https://github.com/osbuild/osbuild/pull/1752#discussion_r1580891435
2024-04-29 14:11:44 +02:00
Michael Vogt
bd8f361851 stages: tweak the skopeo copy test
Small tweaks to the skopeo copy stage integration test to split
the tests into their own test-cases.
2024-04-29 14:11:44 +02:00
Florian Schüller
fc6dc1ea8b stages/org.osbuild.skopeo: support for "--remove-signatures" 2024-04-26 15:51:00 +02:00
Florian Schüller
7de7838534 stages/org.osbuild.skopeo: support for dir and oci-archive 2024-04-26 15:51:00 +02:00
Achilleas Koutsou
901fa24905 stages/systemd: add -- before unit names
Units can start with a -, for example, -.mount.  Trying to enable,
disable, or mask a service like that fails with

  systemctl: invalid option -- '.'
  Hint: to specify units starting with a dash, use "--":
        systemctl [OPTIONS...] COMMAND -- -.mount ...

Adding -- to all 'systemctl' calls lets us specify unit files that start
with -.
2024-04-23 19:59:44 +02:00
Tomáš Hozza
13c098cfdd Stages/SELinux: force auto-relabel of full contexts
Previously, the SELinux stage would not force full contexts reset when
forcing auto-relabel on first boot. As a result, all files remained
`unconfined_u` after the auto-relabeling on first boot and only the type
part was reset.

We really need to mimic the behavior of `fixfiles -F onboot` command,
which creates the `/.autorelabel` file with "-F" in it.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2024-04-22 16:33:59 +02:00
Michael Vogt
2f18beba17 stages: allow bootloader --append via kickstart
This commit allows use to append kernel commandline options via
the kickstart file. This is useful for e.g. the bootc installer
where we support customizing this via blueprints.
2024-04-19 13:14:14 +02:00
Achilleas Koutsou
f255fba09f stage/systemd.unit.create: move systemd-analyze verify to tests
Verifying the systemd unit also checks if any referred systemd units
(Wants, Requires, After) exist and if all commands in Exec exist and are
executable.  Without '--root', the systemd-analyze verify command is
testing this against files in the build root, which isn't valid.

Units and binaries might not exist in the build root when referenced in
the image root tree, making the unit fail when when it's valid.
Conversely, the verification can succeed by finding executables in the
build root that don't exist in the image root tree when it should be
failing.

When verifying user units, systemd expects runtime directories.

All of this makes it quite difficult to verify systemd units properly
when building an image.  The call is useful for making sure the unit is
structured properly, but the user unit verification setup is difficult
to accomplish in a general way while building.

Remove the systemd-analyze verify step from the stage.  Move it to the
unit test so that we have some assurance that our unit file structure is
correct and things work as expected.  Create referenced unit files and
commands to make the unit valid.
2024-04-18 17:20:57 +02:00