Repository navigation
Conversation
f10294b to
0045133
Compare
LucasAPayne
left a comment
There was a problem hiding this comment.
Please add the snap functional tests to a CI workflow, as they are currently skipped when running the other functional tests. You could rename build-snap.yml to make its purpose clearer and add a job to that.
Besides that and a few small suggestions, it looks good to me overall. This will be a good addition to the snap, and the per-device config is a great idea!
| # NOTE: store and validate key before trying to encrypt disk | ||
| # Store the key before changing the device. |
There was a problem hiding this comment.
suggestion: consider reverting this comment. I think it was clearer before.
| try: | ||
| # Ask udev to create the UUID link used during boot. | ||
| dmcrypt.udevadm_rescan(block_device) | ||
| dmcrypt.udevadm_settle(block_uuid) | ||
| except subprocess.CalledProcessError as udev_error: | ||
| logger.warning( | ||
| 'udev processing for %s failed with error code: %s\n' | ||
| 'udev output: %s', | ||
| block_device, | ||
| udev_error.returncode, | ||
| udev_error.output, | ||
| ) |
There was a problem hiding this comment.
suggestion: try/except shouldn't be needed here. We know that the udev commands can't run in the snap, so we can use something like if not running_in_snap() instead of trying the udev functions and letting them fail and log a warning. If there is a chance these functions could fail when running as a normal installation, we can keep the try/except, but the snap could skip it.
There was a problem hiding this comment.
Updated, we now skip udev using running_in_snap(), kkept the try/except for normal installations, where udev commands could still fail
| def test_1_snap_refresh_preserves_enrollment(self): | ||
| """A snap refresh keeps the managed key and does not add a key.""" | ||
| keyslots_before = self._keyslot_count() | ||
| layers_before = sorted(self._layer_files()) |
There was a problem hiding this comment.
todo: remove numbers from test names in this file to match other tests
| # All function calls within try/catch raise a CalledProcessError | ||
| # if return code is non-zero | ||
| # This way if any of the calls fail, the key can be removed from vault |
There was a problem hiding this comment.
suggestion: consider adding this comment back. It gives some context for the rest of the function.
There was a problem hiding this comment.
This exact comment does not apply anymore but added a shorter comment explaining the key is removed if formatting fails
| :returns: str. Pebble layer YAML. | ||
| """ | ||
| command = ( | ||
| 'vaultlocker --retry {timeout} --config {config} ' |
There was a problem hiding this comment.
Should we have some sort of checks around spaces in the file name? That's gonna break is config has spaces.
There was a problem hiding this comment.
Wrapped in shlex.quote() and a test for this case, thank you!
| :param: label: Pebble layer label. | ||
| :returns: str. Layer file path. | ||
| """ | ||
| existing = _existing_layer_path(layers_dir, label) |
There was a problem hiding this comment.
I can see this having race conditions for people using the vaultlocker charm outside a charmed deployment.
This is purely architectural, and for the principle, but maybe a file lock managed by vaultlocker snap?
(since pebble will reject multiple identical prefixes)
There was a problem hiding this comment.
Maybe a little helper from the caller to _layer_path?
with open(lock_path, "a+b") as lock_file:
fcntl.flock(lock_file, fcntl.LOCK_EX)
layer_path = _layer_path(layers_dir, label)(lock_ex should wait until the lock is released)
This is purely from a correctness consideration.
There was a problem hiding this comment.
Updated, added a file lock around choosing the layer, writing the layer, and adding it to Pebble
|
|
||
| try: | ||
| subprocess.run( | ||
| [PEBBLE_BINARY, 'replan'], |
There was a problem hiding this comment.
This function states that this will schedule immediately a pebble service, but calling https://ubuntu.com/docs/pebble/reference/cli-commands/#replan only acts on the current registered plan.
You'll need to call add first to register the new layer and then replan.
https://ubuntu.com/docs/pebble/reference/cli-commands/#add
(on restart, this is correct, the plans would be reloaded by pebble so replan would actually work)
57aedf8 to
26daf29
Compare
gboutry
left a comment
There was a problem hiding this comment.
Either we ensure the config paths are always correctly escaped, or we just make simple validation rejecting invalid combination.
| services: | ||
| {service}: | ||
| override: replace | ||
| command: {command} |
There was a problem hiding this comment.
We should serialize this whole command as a yaml string. Just shlex quote
config_path does not make it actually valid.
Maybe I'm being pedantic, but maybe the easiest is just to refuse config path with space names in them? Rather that going on the rabbit hole of quoting everywhere.
There was a problem hiding this comment.
I'm thinking to go simpler and reject configuration paths containing whitespace in get_config. This will validate the path before encryption or enrollment starts and before it reaches the boot-unlock part.
I'll keep the shlex.quote for handling things like quotes and backslashes.
| with open(dropin_path, 'w') as dropin: | ||
| dropin.write( | ||
| '[Service]\n' | ||
| 'Environment=VAULTLOCKER_CONFIG={}\n'.format(config_path) |
There was a problem hiding this comment.
This is another place where the spacing might break.
26daf29 to
3da5cd8
Compare
Select systemd for classic deployments and Pebble for the confined snap. Preserve the configuration path that registered each device. Assisted-by: OpenCode (DeepSeek v4.1 Flash) Co-authored-by: Raven Kaur <raven.kaur@canonical.com> Co-authored-by: Lucas Payne <lucas.payne@canonical.com> Co-authored-by: Heather Lanigan <heather.lanigan@canonical.com> Signed-off-by: Billy Olsen <billy.olsen@canonical.com> Signed-off-by: Raven Kaur <raven.kaur@canonical.com>
Run boot unlocking through Pebble in the snap and retain systemd support for classic deployments. Open newly encrypted devices by path so confinement does not depend on an immediate udev link. Assisted-by: OpenCode (DeepSeek v4.1 Flash) Co-authored-by: Raven Kaur <raven.kaur@canonical.com> Co-authored-by: Lucas Payne <lucas.payne@canonical.com> Co-authored-by: Heather Lanigan <heather.lanigan@canonical.com> Signed-off-by: Billy Olsen <billy.olsen@canonical.com> Signed-off-by: Raven Kaur <raven.kaur@canonical.com>
3da5cd8 to
2ad07c3
Compare
|
I have also updated the pebble replan call to use I removed the try/except and with |
LucasAPayne
left a comment
There was a problem hiding this comment.
Thanks for the updates, Raven. LGTM
| LXD_STORAGE_VOLUME: vaultlocker-scratch | ||
| steps: | ||
| - name: Check out Git repository | ||
| uses: actions/checkout@v6 |
There was a problem hiding this comment.
todo: update to the current v7
There was a problem hiding this comment.
Updated to v7 for both. Thanks for catching this
| path: snap-artifact | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 |
There was a problem hiding this comment.
todo: update to the current v7
Exercise boot unlocking, Vault recovery, and enrollment persistence with a real snap in an LXD virtual machine. Skip the suite when its VM inputs are unavailable. Assisted-by: OpenCode (DeepSeek v4.1 Flash) Co-authored-by: Raven Kaur <raven.kaur@canonical.com> Co-authored-by: Lucas Payne <lucas.payne@canonical.com> Co-authored-by: Heather Lanigan <heather.lanigan@canonical.com> Signed-off-by: Billy Olsen <billy.olsen@canonical.com> Signed-off-by: Raven Kaur <raven.kaur@canonical.com>
2ad07c3 to
be2fb71
Compare
Summary
This PR adds automatic boot-time unlocking for both classic installations and the strictly confined snap.
Vaultlocker previously registered a host systemd service for every managed device. This does not work inside a strictly confined snap because the snap cannot create or manage host systemd units.
This change introduces separate boot-unlock backends:
The backend is selected automatically depending on whether Vaultlocker is running inside a snap.
Changes
Preserve the Vault configuration for each device
Boot unlocking must use the same Vaultlocker configuration that was used when the device was originally managed.
For classic installations, Vaultlocker now writes a per-device systemd drop-in containing the configuration path.
For the snap, the configuration path is stored in the device's Pebble layer and passed to the boot-time
decryptcommand.This allows separate Vaultlocker applications on the same machine to use their own Vault configuration.
Add Pebble boot unlocking
The snap now runs Pebble as a daemon and creates one Pebble service for each managed LUKS UUID.
The generated layers are stored under
$SNAP_COMMON/pebble/layers, allowing them to survive both host reboots and snap refreshes.Each service runs the equivalent of:
Failed unlock attempts are retried, allowing the device to remain locked while Vault is unavailable and unlock automatically once Vault becomes available again.
Registering the same device UUID again reuses its existing layer instead of creating another service.
Support device opening under strict confinement
After formatting or enrolling a device, Vaultlocker previously depended on udev making the LUKS UUID immediately discoverable before opening it.
A strictly confined snap cannot reliably trigger host udev processing. The udev operations are therefore best-effort, and Vaultlocker opens the newly managed device using the device path it already has.
The mapper name remains based on the LUKS UUID. Boot-time decryption continues using the UUID once the host has completed normal device discovery.
Add real VM functional tests
The new functional tests install the built snap in an Ubuntu 24.04 LXD VM, configure a real file-backed Vault service and operate on a dedicated LUKS block device.
They verify that:
The VM tests are skipped unless the required VM and snap environment variables are set.
Manual validation
Built the snap locally and ran the VM functional suite serially against a vm with a scratch block device with all tests passing.
The tests exercised the strict-confined snap, Vault server, luks device enroll operation, snap refresh and multiple VM reboots.
Full setup details are available at
vaultlocker/tests/functional/snap/README.rstto check locally.Assisted by: GPT 5.6 Sol
Jira: OPEN-4747