Repository navigation
Conversation
0cf28e3 to
57a3bf7
Compare
57a3bf7 to
fc3efac
Compare
Read the cluster ID from Vault's seal status and reject missing, empty, non-string, or non-object responses with an error. 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>
13e2808 to
2b31f00
Compare
| _login_to_vault(client, config) | ||
| try: | ||
| _verify_cluster_identity(client, args.config) | ||
| except exceptions.ClusterIdentityMismatchError as mismatch_error: | ||
| if fail_on_cluster_mismatch: | ||
| raise | ||
| logger.warning('Cluster identity mismatch: %s', mismatch_error) |
There was a problem hiding this comment.
suggestion: According to the hvac docs, read_seal_status() reads from an unauthenticated endpoint, so the login should not be necessary since that's what _verify_cluster_identity() calls. If login is needed for other actions, it can be moved after verifying the cluster's identity.
There was a problem hiding this comment.
So on the first run we create the cluster id pin. If we verify the cluster before authenticating, we could end up pinning a vault that we were never able to authenticate to. If login fails, we should not pin a Vault that these credentials could not access. I will add a comment to clarify this order.
| class ClusterIdentityMismatchError(ClusterIdentityError): | ||
| """The connected Vault cluster does not match the saved cluster.""" | ||
|
|
||
| def __init__(self, expected, actual): | ||
| super().__init__( | ||
| "Vault cluster identity mismatch: pinned cluster_id={}, " | ||
| "observed cluster_id={}".format(expected, actual) | ||
| ) |
There was a problem hiding this comment.
todo: A user may not be aware of the sidecar file used to verify the cluster ID. We should add remediation steps to this message. For example: "If this change is expected, remove {pin_path} and re-run."
There was a problem hiding this comment.
todo: In addition to suggesting how to correct the issue in this message, we should also add some documentation (in the README for now) of steps to take when migrating Vault.
There was a problem hiding this comment.
I don't think we should suggest removing the pin. A mismatch can mean the original Vault still holds keys for devices we already manage. If we remove the pin, new operations could start using a different Vault without those keys being migrated. Vault migration is currently out of scope but it may be worth documenting this in the README.
There was a problem hiding this comment.
That makes sense, thanks. My primary concern was having some way to advertise that the pin file exists and what it's for.
| _luks_format.assert_not_called() | ||
| _boot_unlock.register.assert_not_called() |
There was a problem hiding this comment.
question: Why are these functions being asserted to not be called? They seem unrelated to decryption, but I'm unsure if I'm missing something or if there are some extraneous asserts in some of the tests.
There was a problem hiding this comment.
Thanks for catching, these assertions are stale, I will remove them
| def test_cluster_mismatch_warns_and_attempts_decrypts( | ||
| self, _luks_open, _luks_format, _boot_unlock, | ||
| _udevadm_rescan, _udevadm_settle): |
There was a problem hiding this comment.
nit: Remove the extra "s" at the end of _decrypts
2b31f00 to
ba32eef
Compare
| After authentication, vaultlocker saves the Vault cluster ID in ``<config-path>.cluster_id``. | ||
| If the ID later changes, ``encrypt`` and ``enroll`` operations will fail with an error. | ||
| ``decrypt`` will log a warning and try to find the key in the observed Vault cluster. If | ||
| that Vault does not have the key, vaultlocker cannot unlock the device. | ||
|
|
||
| If the change is unexpected, check the Vault url and restore the connection to | ||
| the original cluster. Deleting the pin does not move existing keys. | ||
| Vaultlocker does not support automatically migrating keys between clusters. | ||
|
|
hemanthnakkina
left a comment
There was a problem hiding this comment.
minor nit on readme, otherwise LGTM
| that a CIDR based ACL is in use to only allow permitted systems within the | ||
| Data Center to login and retrieve secrets from Vault. | ||
|
|
||
| After authentication, vaultlocker saves the Vault cluster ID in ``<config-path>.cluster_id``. |
There was a problem hiding this comment.
<config-path>.cluster-id hyphen instead of underscore
hmlanigan
left a comment
There was a problem hiding this comment.
Looks good once the small change is made.
Create one cluster pin beside each configuration file on first use. Authenticate with AppRole then verify the pin before starting a device operation. Assisted-by: OpenCode (DeepSeek v4.1 Flash) Co-authored-by: Billy Olsen <billy.olsen@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>
Require 90% line and branch coverage for production modules while excluding the test packages. 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>
ba32eef to
063d320
Compare
Summary
After a successful AppRole login, Vaultlocker reads the cluster ID. On the first run, it saves the ID beside the configuration file. On later runs, it compares the current ID with the saved one.
If the IDs differ,
encryptandenrollstop before changing a device or storing a key.decryptlogs a warning and tries to unlock using the vault connection if it finds a key. This also applies to boot-time unlocking.Why
A Vault URL can change or point to a different cluster. New device keys should not be stored there while existing keys may still be in the original cluster.
Decrypting uses an existing key. If that key is available and unlocks the device, a cluster ID change should not prevent boot-time unlocking.
Changes
<config-path>.cluster-id.encryptandenrollwhen the cluster ID differs from the saved ID.decrypton a mismatch.