45 Commits

Author SHA1 Message Date
Valentin David
8fc5be2ad7 kernel/fde: simplify invocation of fde-reveal-key 2024-02-16 08:56:49 +01:00
Miguel Pires
29c9752d66 many: s/ioutil.WriteFile/os.WriteFile (#13217)
Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-09-26 11:38:46 +01:00
Michael Vogt
ec484217a2 many: remove all device-setup fde-setup code (#12618)
* many: remove all `device-setup` fde-setup code

When we initially worked on the inline-cryto-engine (ICE) code we
had a design based on the fde-setup hook that would return a
`device-setup` feature as a hint that ICE should be used. It
turned out this design was impractical and we moved to a much
better approach that got merged in
https://github.com/snapcore/snapd/pull/12589
and relies on support for ICE in the kernel and cryptsetup.

With that new approach all the code that was supporting the
`device-setup` approach can be removed now.

* daemon: consider again the fde-setup hook case

* client: consider the ICE encryption type

* osu/disks,kernel: remove device-unlock support as well

---------

Co-authored-by: Samuele Pedroni <pedronis@lucediurna.net>
2023-04-05 18:03:03 +02:00
Sergio Cazzolato
19c123f2b3 Fix TestDeviceUnlockErr test in debian-sid and ubuntu 23.04 (#12656)
The unit test is failing in those systems with the following error:

fde_test.go:625:
c.Assert(err, ErrorMatches, `cannot run fde-device-unlock
"device-unlock":
    -----
    output-only-used-for-errors
    service result: exit-code
    -----`)
... error string = "cannot run fde-device-unlock \"device-unlock\": exit
status 1"
... regex string = "" +
...     "cannot run fde-device-unlock \"device-unlock\": \n" +
...     "-----\n" +
...     "output-only-used-for-errors\n" +
...     "service result: exit-code\n" +
...     "-----"

This is happens not 100% of the executions on those systems. It is
causes because the error message is not saved before the script exits
with 1. To deal with this race I added a short sleep in the test script
that is used to mock the fde-device-unlock to make sure the error
message is captured.
2023-03-17 14:51:00 -03:00
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