Repository navigation
vaultmgr: recover a wrong vault key mode - #6451
Conversation
54aedc2 to
e94c7c4
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #6451 +/- ##
==========================================
+ Coverage 26.51% 26.95% +0.44%
==========================================
Files 519 532 +13
Lines 95765 97700 +1935
==========================================
+ Hits 25393 26336 +943
- Misses 68396 69172 +776
- Partials 1976 2192 +216 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@claude review |
|
Claude finished @rene's task in 4m 49s —— View job Review complete
I reviewed the recovery logic end to end (
One low-priority observation posted inline on the wipe-and-recreate path ( No blocking issues. |
8cb672a to
6eb1e37
Compare
|
@eriknordmark , you have one conflict to fix.... |
|
I think there is issue with how the retry happens:
and a second issue:
|
|
In addition, I suggest dropping the inferring, fetch the TPM key once, try the recorded mode, fall back to the other one on failure regardless of where the mode came from, and persist the winner whenever it differs from what is on disk. We can even drop the config bookkeeping if we make the recovery using both key the only path. |
df2a217 to
c0a3ed7
Compare
|
@shjala Both cases are real, and the second one is in this PR's own code — Taken your suggestion, which fixes both: the inference is gone, the retry is unconditional, and the resolved mode is persisted whenever it disagrees with what is on disk.
I kept the config bookkeeping rather than making recovery the only path: without it every boot on a pre-7.10.0 device pays a failed unseal and a failed fscrypt unlock before the working derivation, and the log then reads like a seal problem on every boot. The e2e test's fault changed to match — it now records the wrong derivation instead of deleting the record, because a device with no record starts from TPM-key-only and would open a TPM-key-only vault on the first try, exercising nothing. That is your boot-2 scenario directly. Also rebased on master. |
|
Ran Negative control on an EVE without this change (same test source, only the image differs) — FAIL, at The second-boot assertions carry their own positive control: ZFS variant not run. |
c0a3ed7 to
3869550
Compare
Integration branch on master with the conversion chain (lf-edge#6530, lf-edge#6063, fork#6) and the robustness set (lf-edge#6442, lf-edge#6406, lf-edge#6478, lf-edge#6505, lf-edge#6451, lf-edge#6590, lf-edge#6599). Records the tips each piece was replayed from, where two PRs collide and which side won, the branch-local adapters that no PR carries, and the storage-resizer content pin. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Integration branch on master with the conversion chain plus the fault-injection stress harness (lf-edge#6530, lf-edge#6063, fork#6, fork#7) and the robustness set (lf-edge#6442, lf-edge#6406, lf-edge#6478, lf-edge#6505, lf-edge#6451, lf-edge#6590, lf-edge#6599). Records the tips each piece was replayed from, where two PRs collide and which side won, the branch-local adapters that no PR carries, and the chaos storage-resizer content pin. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Claude finished @rene's task in 2m 16s —— View job Review complete
I reviewed the recovery logic end to end. The two problems @shjala raised are addressed: inference is gone ( Two minor points, both posted inline (non-blocking):
No blocking issues. |
3869550 to
865a313
Compare
A kvm->EVE-k vault migration copies the carried-over filesystem vault into a staging zvol sized to the pool's free space. Every failure after that zvol was created returned without destroying it, so the partial copy stayed on the pool. On EVE-k the next boot's migration attempt cleared it, but a device that falls back to EVE-kvm inherits a zvol holding up to all the space the pool had free, and EVE-kvm has no migration code that would ever reclaim it. A copy that runs out of room part-way therefore left the pool full for the flavor the device fell back to. The migration now discards the staging zvol on every failure before the swap, and puts the pre-migration vault back if the second rename of the swap fails, so the vault is never left absent for a fallback boot to find. The empty etcd zvol is created after the free-space checks rather than before them, so a migration declined for lack of space leaves nothing behind either. The storage calls the migration and the recovery make now go through an interface, which lets the tests drive both against an in-memory pool and fail any single operation; they otherwise need a real ZFS pool and a power cut. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Recovering an interrupted kvm->EVE-k vault migration decided purely on which datasets were present: with the vault absent and a staging zvol in place, that zvol was renamed into place as the vault. Nothing recorded whether its copy had finished, so a staging zvol left by a failed migration was indistinguishable from one whose swap lost power between the two renames. That is reachable without a power cut. A failed migration is reported as a vault that cannot be unlocked, so the device waits for a key from the controller; receiving none, and with cleanup still permitted, vaultmgr destroys the vault and sets up a fresh one — which arrives at recovery with no vault and a leftover staging zvol, and adopts its partial copy as the device's vault. The migration now records the staging dataset on /persist once its copy is complete, and recovery promotes a staging zvol only when that record names it; otherwise the leftover is discarded and, where the pre-migration vault is still parked under its backup name, restored so the migration can be retried. Removing the vault takes its migration datasets with it, so nothing is left for a fresh vault to adopt. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Record what the kvm->EVE-k vault migration leaves behind and when, so the reason a staging zvol is only sometimes promoted to the vault is readable without the code: the swap record that distinguishes a complete copy from a partial one, the restore of the pre-migration vault when the swap cannot finish, and the fact that a staging zvol occupies only the space written to it. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The one failure the unit tests cannot reach is power loss inside the rename swap. Faking the storage operations can make any step return an error, but only losing the machine at that instant says whether ZFS's rename and the swap record's fsync really survive it -- which is the property the recovery path is built on. Add a fault point that parks the migration in that window instead of failing it, so a test can cut power from outside at a known moment. It is compiled in only under FAULT_INJECTION=y, wrapping the storage operations; production builds get an identity wrapper and consult no marker. The marker lives on /persist because the migration runs on the first EVE-k boot, which /tmp does not survive, and because file presence under /config is measured into PCR14, which seals the vault. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H2fNrog4UH7mbhrHVGkLN3
A device that falls back to EVE-kvm inside the migration's rename swap comes back with no vault at persist/vault -- it has been renamed aside -- so EVE-kvm creates a fresh, empty one. The contents then exist only in the parked pre-migration vault and the completed staging copy. Recovery treated any vault in place as authoritative and destroyed both, turning a state that still holds the data into a permanent loss. Recovery now discards leftovers only when the vault in place is the migrated zvol. A filesystem vault beside migration datasets is not the one the swap was producing, so the datasets are kept and the swap record left alone, since it is what says the swap never completed. An unreadable dataset type takes the keeping side. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H2fNrog4UH7mbhrHVGkLN3
Keeping the migration datasets in recovery only closed one of two doors. The migration's own entry cleanup drops them before copying, on the premise that the vault it is about to migrate is the one they came from. After a fallback to EVE-kvm inside the swap window that premise is false: the vault in place is the fresh one kvm created, so the migration would destroy the parked original and the completed copy and then migrate an empty vault over the top. Both callers now ask the same question -- is a pre-migration vault parked while the vault in place is not the migrated zvol -- and the migration declines rather than proceeding. Recovery's condition narrows to match: a staging zvol with no parked backup is debris from an attempt that never reached the swap, and stays droppable, so a device that merely failed a copy still retries normally. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H2fNrog4UH7mbhrHVGkLN3
The swap parks the pre-migration vault under <vault>.old so that losing power between the two renames cannot leave the vault absent. Nothing removed it on the path where it matters most: a device that reverts to EVE-kvm keeps both that dataset and the completed copy, EVE-kvm runs no vault migration code, and the space stays held for as long as the device lives. Marking the partition active is the point where that fallback stops being worth anything -- the device is not going back to the other flavor -- so recovery now discards both datasets from then on, and the migration stops declining to run over them. vaultmgr reads the partition state once at startup and hands it to the handler: a committed partition cannot become uncommitted, and one that commits later is picked up on the next boot, which is when leftovers matter again. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H2fNrog4UH7mbhrHVGkLN3
The vault swap runs while a device upgrades to EVE-k, so the boot that lands inside its window is as often the EVE-kvm fallback that follows a failed upgrade as an EVE-k retry. EVE-kvm reached that boot with persist/vault absent, read it as a fresh install and created an empty vault, stranding every blob in the datasets the swap had parked and leaving the device running on a vault with a new key. Recovery now runs on both flavors, before either may decide the vault is missing. What the two flavors do differs, because EVE-kvm cannot mount a zvol: it puts the parked filesystem vault back and leaves the copy to the next EVE-k attempt, where EVE-k promotes the completed copy instead. A vault already in place beside a parked one is likewise never the migrated vault on EVE-kvm, so it keeps both datasets whatever the partition state says rather than reclaiming the pool space over the only surviving copy of the contents. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A device converted from EVE-kvm runs the ZFS vault migration and its recovery whether or not it has a TPM, and both ask whether the running partition has been marked active before they let go of the pre-migration vault and the staging copy. That answer was read only on the TPM path, so on a no-TPM device it stayed false for the life of the boot: the datasets were never released once the update committed, and a device that fell back to EVE-kvm inside the swap window and acquired an empty vault refused to migrate over it forever, leaving the contents in datasets nothing would reclaim. Read it for every device and leave the TPM key mode to the TPM path. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The migration creates the EVE-k etcd zvol on its way to the vault swap, and a failure after that point left it on the pool. It is bounded by the configured etcd size rather than free space, so it is milder than the staging zvol, but it has the same ending: a device that falls back to EVE-kvm runs no migration code and never reclaims it. The failure cleanup now takes it along with the staging zvol, and only when this attempt created it -- an etcd zvol already on the pool is the device's etcd storage, not migration debris. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A device whose recorded vault key derivation does not match its vault locks itself out permanently. The two derivations are the TPM key alone and that key merged with a build-time constant (pre-7.10.0), and the record is one bit in a persistent pubsub publication. An unlock with the wrong one fails the way a broken seal fails -- the TPM unseal succeeds and only fscrypt or `zfs load-key` refuses -- so the controller-key fallback re-seals, fails identically, and the device parks in maintenance mode with its data unreachable. The record can be wrong in two ways. A device that lost the publication to an e2fsck repair of a torn /persist guessed the derivation from whether the vault existed -- an answer that names the merged form for every existing vault, wrong for anything installed since 7.10.0 -- and persisted the guess before anything tried it. And the vault recreate path, reached when no key can open the vault and the controller has none either, keys its replacement with the TPM key alone whatever the destroyed vault used. Stop treating the record as authoritative. A failed unlock is retried against the other derivation, and the one that opened the vault is persisted whenever it disagrees with what is on disk. That costs one extra unseal on a device that is locked out anyway, and a key that does not match the vault changes nothing on disk. The derivation VaultStatus reports follows the same resolution. Each attempt derives a different key, so staging the key is a scope the caller holds around everything that reads the staging file rather than a step inside the key load: `zfs load-key` for the etcd zvol, and the encrypted zvol creates that a carried-over kvm vault's migration performs, both run inside it. With no record at all, the first attempt is the TPM key alone, which is how every vault created since 7.10.0 is keyed; the retry covers the older ones. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Cover the three decisions the key mode turns on: which derivation is tried first, which one is reported after an unlock resolved it, and when a resolved one replaces the record. The recorded mode is read back off an in-memory publication, so the assertion is on what a later boot would find rather than on a call having happened. Every test was checked against a mutation of the code it covers -- the retry dropped, the store-back dropped, the record left alone when it disagrees, the TPM guard removed -- and fails on its own assertions in each case. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Drive the recovery end to end on a real device: record the merged derivation for a vault created with the TPM key alone, reboot, and require the vault to come back open on the local TPM seal. The fault is a wrong bit rather than a missing file because a device with no record at all starts from the TPM key alone and opens such a vault on the first attempt. Evidence comes from the device's own /persist/newlog, since vaultmgr logs this during early boot and those records reach the controller long after the test would have to assert on them. A marker written into the vault beforehand separates the original vault being opened from an empty one created in its place, and the unlock method separates the local seal from the controller-key and recreate paths, which also end with a device reporting an open vault. One variant per /persist filesystem: ext4 and ZFS are separate vault handlers with separate unlock paths. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
865a313 to
1000210
Compare
Description
A device whose recorded vault key derivation does not match its vault locks
itself out permanently, and nothing on the device recovers it.
/persist/status/vaultmgr/VaultConfigrecords one bit: whether the vault keyis the TPM key alone, or that key merged with a build-time constant (the
pre-7.10.0 form). The mode is sticky — an existing
fscryptprotector or ZFSkey cannot be re-derived from a different key — so a wrong bit means the key
EVE builds is not the key the vault accepts. The failure does not look like
what it is:
fscryptrefuses, so it reads as a brokenseal (
Vault key unavailable,mismatchingPCRs=[]);MaintenanceModeReasonVaultLockedUp;Two paths put a wrong bit there.
A
/persistrepair./persistis mutable and can come back from a bootonly partially intact: a power loss or reset mid-write leaves a filesystem
e2fsckthen repairs, and that repair is free to clear directory entries. Mostconsumers of
/persistsurvive that — pubsub state is rebuilt, caches arerefetched,
onboot.shdiscards several trees outright.VaultConfigdid not.With nothing to read, the mode was derived from whether
/persist/vaultexists, which for an existing vault always answers "merged" — wrong for every
device installed since 7.10.0 — and the guess was written out before anything
tried to unlock with it. One reboot turned a recoverable state into a permanent
one, and a device in that state stays there across an upgrade, because the file
it reads back looks like a record rather than a guess.
A vault recreate. The
RemoveDefaultVault()+SetupDefaultVault()fallback keys its replacement with the TPM key alone, whatever the destroyed
vault used, leaving whatever was recorded describing a vault that no longer
exists.
What changes
The recorded mode becomes the derivation to try first rather than a fact:
(
resolveKeyMode,pkg/pillar/vault/keymode.go), whatever the first one camefrom. This is safe — a key that does not match changes nothing on disk, and
stageKeyshreds it — and it is the only thing that separates a wrong modefrom a genuinely unopenable vault, since both surface identically. When
neither derivation works the error names both rather than blaming either.
what is on disk, so the recreate path rewrites a stale record instead of
leaving it.
every vault created since 7.10.0 is keyed. The filesystem probe that used to
guess is gone, and so is
HandlerOptions.TpmKeyOnlyModeInferred— nothingneeds to know where a mode came from any more.
VaultStatus.KeyDerivationfollows the same resolution.ZFS retries just the key load, not the mount — a mount failure is not a key
problem.
The config bookkeeping stays rather than making the two-derivation probe the
only path: without a record, every boot on a pre-7.10.0 device pays a failed
unseal and a failed
fscryptunlock before reaching the working derivation,and its log then reads like a seal problem on every boot.
Note on blast radius, since it is easy to over-read: the cost of a wrong mode
is a locked vault, not a wipe. The recreate path needs an empty
EncryptedVaultKeyFromControllerand the/persist/status/allow-vault-cleansentinel, whichDisallowVaultCleanup()removes at the first content tree/volume or successful attest escrow — so it is
unreachable for any device with data to lose, exactly as designed.
Why the old key scheme has to stay
Collapsing the two derivations — assuming
TpmKeyOnly=trueand deleting thisclass of problem rather than making it recoverable — is not available. A small
but non-zero percentage of deployed production devices still unlock a vault
created with the merged key, which shows up in their logs as
Calling mergeKeys. Dropping support for the old scheme would leave exactly thosedevices unable to open their vault.
PR dependencies
Depends on #6530, and is branched on top of it: the diff and the checks below
cover both until that one merges.
Both change the block in
vaultmgr.gothat buildsHandlerOptions, fromopposite directions -- #6530 hoists it out of the
tpmEnabledbranch so adevice without a TPM still reports its partition state, this one replaces the
key-mode probe feeding it. Resolved here rather than at merge time, since the
two ways of getting it wrong both compile: dropping
CurrentPartitionCommitted, and puttingSetHandlerOptionsback inside thetpmEnabledbranch. The vault recreate path reads the options back and changesonly the key mode, so it cannot drop a field it does not know about.
How to test and validate this PR
Automated.
pkg/pillar/vault/keymode_test.gocovers the decision logic: aworking mode costs no second attempt, a wrong one is retried whatever its
provenance, the mode that opened the vault is the one reported and stored back,
a double failure reports both errors, and an unresolved mode leaves the options
untouched so a caller cannot persist one on the strength of a failed unlock.
pkg/pillar/cmd/vaultmgr/keymode_test.gocovers the branch feeding it: arecorded mode is what gets tried first, TPM-key-only is the answer without one,
the resolved mode replaces a record that disagrees, and nothing is recorded
without a TPM.
Negative controls, both exercised: with the retry removed from
resolveKeyMode,TestResolveKeyModeRetriesARecordedMode,TestResolveKeyModeRecoversFromAWrongPreferenceandTestResolveUnlockRecordsTheModeThatWorkedfail on their own assertions; withrecordVaultKeyModerestored to writing only when nothing is recorded,TestRecordVaultKeyModeOverwritesAStaleModefails on its.On a device.
evetest/tests/security/vault_keymode_test.go(
TestVaultKeyModeRecovery, one variant per/persistfilesystem) injects thefault and checks the recovery end to end: it overwrites the recorded mode with
the merged derivation, reboots through the controller, and requires the device's
own
/persist/newlogto show that mode failing and the other one opening thevault. A marker written into the vault beforehand separates a recovered vault
from a recreated empty one,
VaultStatus.UnlockMethodhas to be the local TPMseal rather than the controller-key fallback, the corrected mode has to be
persisted, and a second reboot has to open the vault on it with no retry.
The fault records a wrong bit rather than removing the file because a device
with no record starts from the TPM key alone and opens such a vault on the first
attempt, exercising nothing.
The test settles the vault seal before injecting anything. A device seals on its
first boot, before onboarding writes the per-device
/configfiles thatmeasure-config records into PCR14, so boot 2 always unlocks over the controller
key with
mismatchingPCRs=[14]; injecting the fault there would measure thatre-seal rather than this change. Those settle boots double as the regression
check on the ordinary path — the record matches, and nothing retries.
The expected device-side sequence is:
ZFS is the same sequence through the other handler, where the wrong derivation
fails as
exit status 255fromzfs load-keyinstead ofexit status 1fromfscrypt.
The ext4 variant passes on amd64 (740s), and the same test on an EVE without
this change fails at
the vault must be unlocked after the wrong key mode was recordedwith the vault reportingDATASEC_AT_REST_ERROR-- the field symptomthis fixes. The ZFS variant has not been run.
Changelog notes
A device whose stored vault key-derivation mode did not match its vault — after
a filesystem repair of a partially corrupted
/persist, or after the vault wasrecreated — could no longer unlock the vault and stayed in maintenance mode. It
now recovers on its own and corrects the stored mode.
PR Backports
Not proposed for backport.
Checklist
and
TestVaultKeyModeRecoveryon ext4 with a negative control. Not the ZFSvariant.
stablelabel, since this isnot being backported.
🤖 Generated with Claude Code