1
0
mirror of https://github.com/coreos/ignition.git synced 2026-02-06 09:47:17 +01:00
Commit Graph

407 Commits

Author SHA1 Message Date
Nikita Dubrovskii
008fe5a160 luks: fix occasional cex.key file removal
1df2238519 broke CEX:
```
[   30.496802] ignition-ostree-growfs[1118]: + cryptsetup resize root --key-file /etc/luks/cex.key
[   30.501834] ignition-ostree-growfs[1257]: Failed to open key file.
```

Issue: https://github.com/coreos/rhel-coreos-config/issues/76
2025-10-10 10:37:46 +02:00
Tiago Bueno
2d04de325c Fix device mapper partitioning
When run ignition on a device mapper, ie, multipath, it fails because
the function blockDevHeld returns true as the block device
contains holders. A block device with holders do not necessary means
the block device is in use (like mounted).
The function blockDevInUse will not check if it is a device mapper
and if so, do not check for blockDevHeld.

Signed-off-by: Tiago Bueno <tiago.bueno@gmail.com>
2025-10-01 16:46:06 -03:00
yasminvalim
dcee9cfd29 internal/exec/stages/disks/luks: Wrap inner loop to trigger defer
Wrap the inner loop code in an anonymous function to make sure that
defer calls are triggered for each iteration of the loop and join all
errors as needed.

Diff best viewed with whitespace changes hidden.
2025-08-07 12:37:44 +02:00
yasminvalim
1df2238519 internal/exec/stages/disks/luks: Log previously ignored errors
Those errors are unlikely to happen and neither is fatal nor a bug as
the file is written in a temporary folder in the initramfs that is
removed before moving to the real root.

Thus log them and ignore them for as we don't want to start failing on
those if we did not before.

Fixes lint:
```
Error return value of `keyFile.Close` is not checked (errcheck)
Error return value of `os.Remove` is not checked (errcheck)
```
2025-08-07 12:37:44 +02:00
yasminvalim
199404a78b internal/exec/util/user_group_lookup_test: Log errors
Log errors in test code.

Fixes lint:
```
Error return value of `os.RemoveAll` is not checked (errcheck)
Error return value of `os.RemoveAll` is not checked (errcheck)
```
2025-08-07 12:37:44 +02:00
yasminvalim
688e502aa1 internal/exec/util: Ignore cleanup/close errors
Keep the current behavior as we likely don't have test verifying that
and we don't want to start failing on things that were passing before.

Fixes lint:
```
internal/exec/util/file.go:210:17: Error return value of `tmp.Close` is not checked (errcheck)
internal/exec/util/file.go:219:17: Error return value of `os.Remove` is not checked (errcheck)
internal/exec/util/file.go:247:25: Error return value of `targetFile.Close` is not checked (errcheck)
internal/exec/util/file.go:302:17: Error return value of `dfd.Close` is not checked (errcheck)
internal/exec/util/passwd.go:178:10: Error return value of `f.Close` is not checked (errcheck)
internal/exec/util/selinux.go:45:19: Error return value of `file.Close` is not checked (errcheck)
internal/exec/util/unit.go:195:18: Error return value of `file.Close` is not checked (errcheck)
```
2025-08-07 12:37:44 +02:00
yasminvalim
f5f563eed7 internal/exec/engine: Ignore close() error
At this point, the file has been created without error, so the execution
can continue and the logic will not change if we ignore this error.
Failure here seams unlikely.

Fixes lint:
```
Error return value of `f.Close` is not checked (errcheck)
```
2025-08-07 12:37:44 +02:00
yasminvalim
e78e5bec4e Remove embedded field "Node" from selector
Fixes lint:
```
QF1008: could remove embedded field "Node" from selector (staticcheck)
```
2025-08-05 20:14:55 +02:00
yasminvalim
13f473d96d *: Strip Logger
Fixes lint:
```
QF1008: could remove embedded field "Logger" from selector (staticcheck)
```
2025-08-05 20:14:55 +02:00
yasminvalim
6af0c4a3b1 *: Error message should start uncapitalized 2025-08-05 20:14:55 +02:00
Timothée Ravier
6b22612155 Revert "fix: Handle unchecked error returns across the codebase and other linter issues"
Too many changes in a single commit. Will be split to make it easier to
review.

This reverts commit de452c404c.
2025-08-04 17:08:18 +02:00
yasminvalim
de452c404c fix: Handle unchecked error returns across the codebase and other linter issues
The linter found staticcheck and errorcheck issues.  Deferred statements now  use join  to combine any new error with an existing one, preventing error information from being lost. Other minor error checks, like for printing text  and flushing data have also been addressed.
2025-07-28 19:12:25 -03:00
Steven Presti
496804e02e internal/exec/util/file: Set ownership first, then mode
From https://man7.org/linux/man-pages/man2/lchown.2.html:

> When the owner or group of an executable file is changed by an
> unprivileged user, the S_ISUID and S_ISGID mode bits are cleared.
> POSIX does not specify whether this also should happen when root
> does the chown(); the Linux behavior depends on the kernel version,
> and since Linux 2.2.13, root is treated like other users.

Fixes: #2042
2025-05-05 13:12:58 -04:00
Timothée Ravier
f3556808e4 tests/validator: Use ToFileMode to convert mode to FileMode 2025-05-01 11:50:42 -04:00
Timothée Ravier
b4cabdf73d Revert "tests/validator: Use ToFileMode to convert mode to FileMode"
This reverts commit 6dee4e5595.
2025-04-23 17:23:20 +02:00
Timothée Ravier
ed238b2ecd Revert "internal/exec/util/file: Set ownership first, then mode"
This reverts commit c17d14e31a.
2025-04-23 17:23:19 +02:00
Timothée Ravier
a3b16a7a30 Revert "WIP: debug"
This reverts commit 9ea1c4816f.
2025-04-23 17:23:18 +02:00
Timothée Ravier
9ea1c4816f WIP: debug 2025-04-23 17:08:28 +02:00
Steven Presti
c17d14e31a internal/exec/util/file: Set ownership first, then mode
From https://man7.org/linux/man-pages/man2/lchown.2.html:

> When the owner or group of an executable file is changed by an
> unprivileged user, the S_ISUID and S_ISGID mode bits are cleared.
> POSIX does not specify whether this also should happen when root
> does the chown(); the Linux behavior depends on the kernel version,
> and since Linux 2.2.13, root is treated like other users.

Fixes: #2042
2025-04-23 17:06:53 +02:00
Timothée Ravier
6dee4e5595 tests/validator: Use ToFileMode to convert mode to FileMode 2025-04-23 16:58:55 +02:00
FeRD (Frank Dana)
116f0b82f7 engine: Add fmt string to Logger.PushPrefix call
The Vet in Go 1.24 will add a new check to the printf analyzer that
"reports a diagnostic for calls of the form `fmt.Printf(s)`, where
`s` is a non-constant format string, with no other arguments.
Such calls are nearly always a mistake as the value of `s` may contain
the `%` symbol; use `fmt.Print` instead."
2025-01-19 08:22:18 -05:00
Kevin Cui
0b340f08a7 exec/engine: log to journal only when available
Alpine Linux does not include systemd’s journal, which causes Ignition
to emit warnings when attempting to log.  This PR introduces a check to
determine if the journal is available on the current distribution, and
skips logging to the journal when it is not present.

Signed-off-by: Kevin Cui <bh@bugs.cc>
2024-11-07 13:05:10 +08:00
Madhu Pillai
c6c52924cf *: update to v3_6_experimental spec 2024-10-14 15:33:52 +02:00
Steven Presti
47b8dee93f linting: update src to comply with new linting version
With the newer version of the linter some code has been flagged.
Add code changes where possible and ignores when needed.
2024-10-11 11:18:18 -04:00
pkucode
547291cd15 chore: fix function name
Signed-off-by: pkucode <cssjtu@163.com>
2024-08-07 18:13:14 +08:00
Kai Lueke
c2cc56cd02 sgdisk: Run partx after partition changes
The sgdisk tool does not update the kernel partition table with BLKPG in
contrast to other similar tools but only uses BLKRRPART which fails as
soon as one partition of the disk is mounted.
Update the kernel partition table with partx when we know that a
partition of the disk is in use.
2024-06-28 14:49:05 +09:00
Kai Lueke
8916185e56 disks: Refuse to modify disks/partitions in use
When a partition or the whole disk is in use, sgdisk should not execute
the destructive operation.
Add a check that errors out when a disk in use or a partition in use is
to be destroyed.
2024-06-28 14:47:06 +09:00
Madhu Pillai
d078c9fe79 Support LUKS encryption using IBM CEX secure keys on s390x
Extend the `luks` schema to support a new `cex` key. When enabled, the
volume key of the LUKS device uses a secure key generated using a CEX
card. The keyfile to unlock the volume is not considered confidential.

Closes: #1693

Co-authored-by: Jonathan Lebon <jonathan@jlebon.com>
2024-05-13 12:25:21 -04:00
Jonathan Lebon
162d1a6a33 stages/files: filter out non-existent paths before relabeling
The code that handles systemd unit enablement via preset will no op if
disabling a systemd unit that is already disabled, which means that we
wouldn't create a preset file in that case. But we did mark the preset
file as needing relabeling unconditionally. Since `setfiles` errors out
if you pass it a path that doesn't exist, this would break boot.

Fix this by filtering out all entries that don't exist right before we
call `setfiles`. Another approach would've been to only mark the file
for relabeling if we actually did write the file, but this is more
complex than it seems because the relabeling logic needs to know what
is the first component in the path that had to be created. So we'd need
logic both before and after file creation.

This isn't user-reported; we hit this in a CI test.
2024-01-16 11:33:52 -05:00
Jonathan Lebon
5717a50047 stages/disks: retry sgdisk --zap-all invocation
When `wipeTable` is enabled, we run `sgdisk --zap-all`. But if the table
was corrupted in the first place, `sgdisk` will exit with code 2 which
then breaks boot.

As a workaround, Ignition used to retry the invocation but the context
around it was lost in #544 and #1149 and the retry was removed and
the error-checking was added.

So this patch effectively re-applies 94c98bcb ("sgdisk: retry zap-all
operation on failure"), but now with a comment and a test to make sure
we don't regress again.

Closes: https://github.com/coreos/fedora-coreos-tracker/issues/1596
2023-10-25 13:07:27 -04:00
Kai Lueke
3f78465cf9 internal/exec/stages/disks: prevent races with udev
The "udevadm settle" command used to wait for udev to process the disk
changes and recreate the entries under /dev was still prone to races
where udev didn't get notified yet of the final event to wait for.
This caused the boot with a btrfs root filesystem created by Ignition
to fail almost every time on certain hardware.

Issue tagged events and wait for them to be processed by udev. This is
actually meanigful in all stages not only for the other parts of the
initramfs which may be surprised by sudden device nodes disappearing
shortly like the case was with systemd's fsck service but also for the
inter-stage dependencies which currently are using the waiter for
systemd device units but that doesn't really prevent from races with
udev device node recreation. Thus, these changes are complementary to
the existing waiter which mainly has the purpose to wait for unmodified
devices. For newly created RAIDs we can wait for the new node to be
available as udev will not recreate it.
2023-09-29 11:33:50 -04:00
Adam0Brien
9b73b92fcd internal/exec: don't relabel a mountpoint that already exists
When mounting filesystems, Ignition was relabeling the mountpoint
directory even if it previously existed.
This isn't necessary, and fails if the mountpoint is on a read-only
filesystem, such as /usr/share/oem on Flatcar.
Relabel the mountpoint only if we create it.
Fixes: https://github.com/coreos/ignition/issues/1452
2023-06-28 11:58:33 +01:00
Steven Presti
13ecdf10c8 internal/exec/util: check if unit exists before disabling
Ignition depends on `systemctl disable` for disabling units. Currently
if the unit does not exist `systemctl disable` exits 1; however, before
systemd 252 `systemctl disable` exits 0 if `--root` is specified. Since
Ignition depends on systemctl's exit code the new behavior caused a
regression, causing the unit.remove.symlinks blackbox test to fail with:

    removing enablement symlink(s) for "enoent.service": cannot remove symlink(s) for enoent.service: exit status 1: "Failed to disable unit, unit enoent.service does not exist.\n"

Before disabling a unit, use `systemctl is-enabled` to verify that the
unit exists and is enabled.

Fixes coreos https://github.com/coreos/ignition/issues/1614
2023-05-09 13:39:35 -04:00
Benjamin Gilbert
01c869650d platform: allow provider fetch to save files to write from files stage
The Hyper-V provider will need to write out state for hv_kvp_daemon.
Add a way for provider fetch functions to return []types.File which
will be saved in State and written out during files stage.  Also add a
utility function a provider can use to create a types.File.

Since this functionality should not be used by most providers, avoid
adding an extra argument or return value to every fetch function.  Instead,
define an alternative fetch function that will be used if declared in
the registration.
2023-04-11 08:28:19 -04:00
Benjamin Gilbert
b5ee217aaa platform: drop function pointer indirection for fetch method
We no longer need to provide direct access to the fetch function pointer.
2023-03-29 14:55:05 -04:00
Benjamin Gilbert
0ea0657309 providers: add Config wrapper structs for cmdline and system providers
The cmdline and system providers shouldn't be registered with the registry
because we don't want to allow looking them up by name; they're
special-cased in Engine.  However, we can still provide Config wrapper
structs for them to simplify their use in Engine.
2023-03-29 14:55:05 -04:00
Benjamin Gilbert
247713b73a internal: empty out providers base package
Most of the type definitions serve no purpose, and the rest of the contents
can be moved into the platforms package.
2023-03-29 14:55:05 -04:00
Benjamin Gilbert
4ad83687e0 platform: avoid needless function pointer indirection in methods
The platform Config.NewFetcherFunc() and Config.InitFunc() wrappers are
unnecessarily zero-argument accessors that return a function pointer.
Have them call the underlying function directly, like the newer methods.

Note that Config.FetchFunc() still needs to return a function pointer.
2023-03-27 20:47:44 -04:00
Benjamin Gilbert
0e2b63c9d5 *: update to v3_5_experimental spec 2023-02-20 03:09:50 -05:00
Steven Presti
da6c29bdd2 Merge pull request #1544 from prestist/tang-offline-provisoning
Tang offline provisoning
2023-02-18 16:15:05 -05:00
Steven Presti
b772e19557 config/v3_4_exp: add Tang offline provisioning support
Expand schema for 3_4_exp with an advertisement field to allow for
Ignition to support Tang offline provisioning by passing the supplied
advertisement field during first boot's device bind. Fixes #1474
2023-02-18 13:07:09 -05:00
Benjamin Gilbert
e5657c7ea0 stages/disks: fail when attempting to reuse a LUKS1 volume
Ignition has never supported LUKS1, so we can't ever try to reuse a
LUKS1 volume created by Ignition.  However, a LUKS1 volume may have been
created outside of Ignition, in which case we would conclude that the
volume was not LUKS and clobber it, causing data loss.  Detect this case
and fail instead.
2023-02-14 01:11:20 -05:00
Benjamin Gilbert
acc24d4fff stages/disks: don't log error if cryptsetup isLuks exits non-zero
If the partition wasn't previously formatted as a LUKS volume, cryptsetup
is supposed to exit non-zero; that's why we're calling it.  The resulting
log message was always spurious, but is now more visible since Ignition
errors are shown by c-l-h-m.
2023-02-14 00:47:19 -05:00
Benjamin Gilbert
47d34fd048 Support persisting arbitrary LUKS open options during luksOpen
There are other options that can be stored in the LUKS header with
--persistent, including notably --perf-no_read_workqueue and
--perf-no_write_workqueue, which can improve performance.  We usually
provide options arrays to support advanced features, so add one here.

Since this is an escape hatch feature, we don't try to implement full
option matching in the volume reuse semantics; we just update any reused
volume to use the currently specified open options.
2023-02-03 13:40:49 -05:00
Benjamin Gilbert
e782590b59 Add schema field to enable discard on LUKS devices
Discard improves performance and longevity on SSDs and space utilization
on thinly-provisioned SAN devices, but also leaks information.  It's an
open-time option, not a create-time one, so it can't be enabled via the
options field.  Add a spec field to enable it.

For https://github.com/coreos/fedora-coreos-tracker/issues/1392.
2023-02-03 13:40:49 -05:00
Benjamin Gilbert
81ce363847 disks: add helper function to calculate luksOpen arguments
We invoke `cryptsetup luksOpen` in two places.
2023-01-28 01:40:04 -05:00
Steven Presti
ddc873f303 fetch-offline: add recognition for ClevisCustom's NeedsNetwork field
Resolves #1473, add a check for attributes that trigger networking
to be inclusive of `ClevisCustom`'s `NeedNetwork` field.
2022-12-06 19:15:46 -05:00
Steven Presti
c26304c572 fetch-offline-test: restructure tests for clear scope
After poking around the existing tests it was evident that the
accumulative style of testing used on the `fetch-offline` code caused
some confusing results due to its overlapping nature. To address this
the test structure has been pivoted to a more direct approach.
2022-12-06 16:03:53 -05:00
Benjamin Gilbert
7814b85b5a Replace io/ioutil
It was deprecated in Go 1.16 and its functions moved elsewhere.
2022-08-09 19:04:31 -04:00
marmijo
47f06c2b68 exec/files: sort unit preset in alphabetical order
The lines of the 20-ignition.preset file were being written in arbitrary
order.  This shouldn't affect its semantics, but could cause ignition-apply
to produce different filesystem trees from identical configs, breaking
reproducible container builds.  Sort the list of units before writing it
out.

Fixes https://github.com/coreos/ignition/issues/1339
2022-06-03 14:35:09 -04:00