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>
* 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>
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.
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>
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.
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.
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>
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>
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>
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>