Skip to content

evetpm: never treat a TPM error as no disk key - #6691

Merged
eriknordmark merged 2 commits into
lf-edge:masterfrom
eriknordmark:evetpm-tpm-error-keeps-key
Oct 9, 2026
Merged

eriknordmark merged 2 commits into
lf-edge:masterfrom
eriknordmark:evetpm-tpm-error-keeps-key

Conversation

@eriknordmark

@eriknordmark eriknordmark commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Soak and stress testing tripped on this once, and it caused much confusion because a new key was generated.

When the vault key is fetched, a TPM error while checking whether a sealed disk key exists is read as "no key present", so EVE generates and seals a fresh key over the one the vault is encrypted with. Anything encrypted with the old key can then not be opened by any key. The check now tells an undefined NV index apart from a TPM error, retries the error twice with a log line per attempt, and fails the fetch rather than generating a key if the error persists. An index that is defined but never written still counts as absent.

How to test and validate this PR

Covered by the evetpm unit tests that run against swtpm in CI (tests/tpm/prep-and-test.sh). A proxy between EVE and the TPM simulator fails the presence check while every other command, sealing included, keeps working:

  • TestFetchSealedVaultKeyRetriesTPMError: a transient failure must return the sealed key. Without the fix this test fails, logging "neither legacy nor sealed disk key present, generating a fresh key".
  • TestFetchSealedVaultKeyFailsOnPersistentTPMError: a persistent failure must return an error and leave the sealed key in place.
  • TestDiskKeyPresentFailsOnTPMError: a TPM that cannot be opened is reported as an error, not as an absent key.

Changelog notes

A transient TPM error at boot no longer replaces the vault's disk key with a new one.

PR Backports

The same presence check is in all four LTS branches.

Checklist

  • I've provided a proper description

  • I've added the proper documentation

  • I've tested my PR on amd64 device

  • I've tested my PR on arm64 device

  • I've written the test verification instructions

  • I've set the proper labels to this PR

  • I've checked the boxes above, or I've provided a good reason why I didn't
    check them.

🤖 Generated with Claude Code

eriknordmark and others added 2 commits October 1, 2026 11:49
When the vault key is fetched, a TPM error while checking for the sealed
disk key was read as "no key present", so EVE generated and sealed a
fresh key over the existing one. Data encrypted with the old key, such as
a reused etcd zvol after a kvm-to-k vault migration redo, then could not
be opened by any key. The check now distinguishes an undefined NV index
from a TPM error, retries the error twice with a log line per attempt,
and fails the fetch rather than generating a key if it persists. An index
that is defined but never written still counts as absent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: eriknordmark <erik@zededa.com>
Fetching the vault key must not take a TPM error for an absent key, or
it seals a fresh key over the one the vault is encrypted with. The tests
put a proxy between EVE and the TPM simulator that fails the disk-key
presence check while every other command, sealing included, keeps
working. A transient failure must yield the sealed key, and a persistent
one an error with the sealed key left in place. Against the earlier
presence check, the transient case replaces the key.

The proxy answers TPM_RC_NV_UNAVAILABLE rather than TPM_RC_RETRY because
go-tpm retries TPM_RC_RETRY itself and never returns it to the caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: eriknordmark <erik@zededa.com>
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.47%. Comparing base (515ca2c) to head (2aa84b0).
⚠️ Report is 21 commits behind head on master.

Files with missing lines Patch % Lines
pkg/pillar/evetpm/tpm.go 76.66% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6691      +/-   ##
==========================================
+ Coverage   27.17%   27.47%   +0.30%     
==========================================
  Files         524      534      +10     
  Lines       95907    97642    +1735     
==========================================
+ Hits        26059    26829     +770     
- Misses      67769    68542     +773     
- Partials     2079     2271     +192     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shjala

shjala commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

As it stands, LGTM.

But given the title "never treat a TPM error as no disk key", I suggest fixing these two places too, either in this PR or upcoming one:

  1. FetchSealedVaultKey() calls FetchVaultKey() when SHA-256 PCR support is unavailable, then FetchVaultKey() treats any readDiskKey() error as permission to generate and write a replacement key.
  2. pcrBankSHA256EnabledHelper() returns false on TPM-open or PCR-read errors.

@rene rene left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kicking off tests....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants