Commit Graph

53 Commits

Author SHA1 Message Date
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
Alberto Mardegan
2efa777f8c kernel/fde: mock systemd-run in unit test
This test has been occasionally failing under spread:

```
FAIL: fde_test.go:492: fdeSuite.TestRevealErr

using shellcheck: ""
fde_test.go:508:
    c.Assert(err, ErrorMatches, `(?s)cannot run fde-reveal-key "reveal":
    -----
    failed
    service result: exit-code
    -----`)
... error string = "cannot run fde-reveal-key \"reveal\": exit status 1"
... regex string = "" +
...     "(?s)cannot run fde-reveal-key \"reveal\": \n" +
...     "-----\n" +
...     "failed\n" +
...     "service result: exit-code\n" +
...     "-----"

OOPS: 9 passed, 5 skipped, 1 FAILED
```

While we couldn't yet reproduce it locally and find what exactly
triggers it, it makes sense to exclude systemd-run from the picture by
mocking it. We now simply check that it was invoked with the right
parameters and that its output is captured correctly.
2021-09-20 09:18:42 +03:00
Michael Vogt
8229fcb8b9 kernel: fix typo/improve comment (thanks to Pawel) 2021-04-27 17:49:40 +02:00