Commit Graph

55 Commits

Author SHA1 Message Date
Miguel Pires
d097436c1c many: fix formatting w/ gofmt 1.19
Go 1.19 includes some changes to gofmt which intend to make lists and
heading clearer when rendered (https://go.dev/doc/go1.19). This commit
is the result of running the new gofmt and manually fixing some of it.
This was necessary because the new gofmt assumed lines beginning w/ tabs
to start lists or examples. While this is often true in our codebase,
we occasionally also use tabs to indent the lines after a TODO or FIXME
prefix or in yaml (e.g., excerpts of a snap.yaml). This meant that a lot of the
reformatted comments were broken and had to be fixed manually.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-01-16 14:23:11 +01:00
Michael Vogt
8e140440a6 fde: run fde-reveal-key with DefaultDependencies=no
We hit an issue in initrd where the basic.target had an implicit
dependency on the snap-intiramfs-mounts unit. Part of
snap-initramfs-mounts is to use `systemd-run` to run `fde-reveal-key`,
without this `snap-initramfs-mounts` cannot complete. So this
situation lead to a deadlock and an unbootable system.

While this is getting fixed in initrd the fde-reveal-key code should
also be more robust and not hang like this. So this commits adds
`--property=DefaultDependencies=no` which will avoid that fde-reveal-key
needs basic.target to run.
2022-09-27 12:17:46 +02:00
Maciej Borzecki
38a2321cd2 systemd: add systemd.Run() wrapper for systemd-run
This commit adds a new `systemd.Run()` function that implements
a wrapper around `systemd-run`. This will be used to spawn
commands that use the `--keyring-mode=inherit` when interacting
with the kernel keyring.
2022-04-25 17:22:13 +02:00
Ian Johnson
f6f29475a4 kernel/fde: add EncryptedDeviceMapperName, DeviceSetupHookPartitionOffset
EncryptedDeviceMapperName is used to generate the name when installed a device
with ICE.

The DeviceSetupHookPartitionOffset is used to mount a mapper device of the
partition offset to create a header in the offset on the physical partition.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2022-03-21 18:45:06 -05:00
Ian Johnson
c215997f31 kernel/fde: add PartitionName to various structs
We need to specify the PartitionName for ICE decryption since it is currently
based on partition name as well as the mapper device provided in Device.

Also allow mocking the actual call to runFDEDeviceUnlockCommand from other 
packages without all the complexity of creating hook scripts and such, and add
some more debug logging.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2022-03-20 20:22:11 -05:00
Ian Johnson
876eeafcf3 kernel/fde/reveal_key.go: ensure Mock* function only used in tests
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2022-03-20 20:20:28 -05:00
Ian Johnson
5479938d81 kernel/fde/fde_test.go: use DeepEquals for a [][]string comparison
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2022-03-14 21:43:26 -05:00
Ian Johnson
f5aae206bb kernel/fde: adjust variable names in unit tests, check calls to hook in a test
Eliminate the confusion around whether we are mocking systemd-run here, because
we are not mocking systemd-run, we are mocking the hook which systemd-run
executes.

Also check calls to the hook in one of the unit tests which was not doing this.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2022-03-11 15:31:43 -06:00
Ian Johnson
c0694ad17b kernel/fde/device_unlock.go: add doc-comments
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2022-03-11 15:25:38 -06:00
Ian Johnson
ac539fa269 Merge branch 'master' into ice/fde-device-unlock
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2022-03-11 11:21:00 -06:00
Ian Johnson
372f7f4987 kernel/fde, osutil: rename functions, add doc-comments
Thanks to Samuele for the suggestions.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-11-22 09:19:23 -06:00
Ian Johnson
00969d1403 osutil/disks, kernel/fde: rename device mapper back resolver
Thanks to Maciej for the suggestion.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-11-16 15:42:31 -06:00
Ian Johnson
96141d32a0 kernel/fde: add DeviceUnlockKernelHookDeviceMapperHandler, use w/ disks pkg
Add two new functions, IsEncryptedDeviceMapperName to identify if a device
mapper node is with a device-unlock encrypted mapper name device, and
DeviceUnlockKernelHookDeviceMapperHandler to combine the identification with
the task of "un-mapping" the device mapper to the original source disk. Also
register this with the disks package so users of the disks package will get
this built-in when they also import the fde package.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2021-11-09 19:05:41 -06:00
Michael Vogt
b7b5cf2f5c fde: tweak/fix doc strings (thanks to Ian) 2021-10-07 09:43:03 +02:00
Michael Vogt
314af6e912 fde: remove (uneeded) sleep in tests (thanks to Ian) 2021-10-07 09:36:06 +02:00
Michael Vogt
b2c926d5cf Merge remote-tracking branch 'upstream/master' into ice/refactor-fde-minimal 2021-09-25 20:09:06 +02:00
Michael Vogt
79620fa48a fde: improve error handling and doc strings for methods 2021-09-24 10:02:54 +02:00
Michael Vogt
242cf1f86c Merge remote-tracking branch 'upstream/master' into ice/fde-device-unlock 2021-09-24 09:52:37 +02:00
Michael Vogt
c3ac482011 Merge pull request #10815 from mvo5/ice/has-device-unlock
fde: add HasDeviceUnlock() helper
2021-09-23 09:53:41 +02:00
Michael Vogt
73e43db495 fde: fix typos
Co-authored-by: Pawel Stolowski <stolowski@gmail.com>
2021-09-23 09:21:24 +02:00
Michael Vogt
074ef7e853 fde: add new device-setup support to fde-setup
This adds support for inline cryto hardware like Qualcomm ICE to
the fde-setup binary. A new `op:device-setup` is used
for this.
2021-09-22 13:45:23 +02:00
Michael Vogt
982e8fbf8e fde,devicestate: add new fde.CheckFeatures() and use in DeviceManager 2021-09-22 13:40:20 +02:00
Michael Vogt
0469f1cb91 fde: add new DeviceUnlock() call
Add support to run `fde-device-unlock` via the kernel/fde package.
2021-09-21 12:26:31 +02:00
Michael Vogt
44052edb05 fde: extract new runFDEinitramfsHelper() helper 2021-09-21 11:52:44 +02:00
Michael Vogt
d2e7e6b19f fde: add HasDeviceUnlock() helper
This method is used to determine if the fde-device-unlock helper is
available.
2021-09-21 09:41:41 +02:00