Skip to content

efi: allow other architectures in check_host_security and friends - #563

Closed
alexclewontin wants to merge 3 commits into
canonical:masterfrom
alexclewontin:check-host-security-unpin-amd64
Closed

efi: allow other architectures in check_host_security and friends#563
alexclewontin wants to merge 3 commits into
canonical:masterfrom
alexclewontin:check-host-security-unpin-amd64

Conversation

@alexclewontin

Copy link
Copy Markdown
Member

Checking host security today makes assumes in many ways secboot will only be used on amd64. This PR attempts to lay the groundwork to allow other architectures to leverage much of the same logic.

Big themes:

  • removing architecture-conditional compilation, to allow unit tests to be mocked and run on any host architecture
  • abstracting the mocked test environment (the "fixture") from the actual code under test. This accounts for the bulk of the PR, as a ton of a couple test files now sit inside loops over fixtures. The whitespace insensitive diff is much smaller.
  • adding switch/case statements to the business logic of checking host security, so that each architecture can implement its own ecosystem-aware checks (as even within amd64 there doesn't seem to be a platform agnostic way to handle this).

This is based on top of #562 and is part of an attempt to split up #560.

@frederic-hoerni

Copy link
Copy Markdown
Collaborator

Please rebase on master once PR#562 is merged.

@frederic-hoerni

Copy link
Copy Markdown
Collaborator

Does internal/efi/export_amd64_test.go need amd64 unpinning as well?

@alexclewontin

alexclewontin commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

Does internal/efi/export_amd64_test.go need amd64 unpinning as well?

It uses cpuidHasFeature and devcpuPath from internal/efi/default_env_amd64.go which can't be completely arch independent because it depends on github.com/canonical/cpuid which itself only builds on amd64.

Working on another commit that puts the thinnest possible layer around cpuid so that we can unpin the default env pieces.

@frederic-hoerni
frederic-hoerni self-requested a review September 3, 2026 06:36
Comment thread efi/preinstall/check_tpm_intel_test.go
Comment thread efi/preinstall/checks_fixture_test.go
Comment thread efi/preinstall/checks_fixture_test.go
Comment thread efi/preinstall/checks_fixture_test.go Outdated
Comment on lines +105 to +106
intelDevices := func(status []byte, withIOMMU bool) []internal_efi.SysfsDevice {
attrs := map[string][]byte{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Instead of embedding a func here, wouldn't it be more legible to have it as a plain regular named function? That would also be easier to document and let runChecksPlatformHostFixtures() focus on the list that it returns?

expectedWarningsMatch: `3 errors detected:
required := runChecksHostCapabilityValid | runChecksHostCapabilityFirmwareTPM
for _, fixture := range runChecksHostFixturesFor(c, required) {
c.Logf("running with host fixture %q", fixture.name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These are worth being displayed when tests are run (for identifying which host fixture raised an error, or for comparison of which host fixtures get tested from a version to another...).

They appear with -check.vv, but this option also activates other cumbersome log messages.

So, is there a way to give better visibility when running tests? And possibly ensure that Makefile and .github/workflows/test.yaml (or run-tests) take advantage of it.

@alexclewontin
alexclewontin force-pushed the check-host-security-unpin-amd64 branch from 3daef88 to 628c6df Compare September 3, 2026 16:49

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is not a rename, it's an addition of a file & the removal of a file but because both files are small and the license header dominates, it's something like 52% similar so detected as a rename

github.com/canonical/cpuid does not compile on non-x86 architectures,
which forced the AMD64 host environment to be split across a filename
gated default_env_amd64.go and a default_env_amd64_null.go stub. That
made the implementation invisible to the compiler, and untestable, on
every other architecture.

Confine that dependency to a new internal/cpuid package. It is a
deliberately thin wrapper, and the only place in the tree that is gated
by architecture at build time. It exposes VendorIdentificator, Family
and HasFeature, delegating to the upstream package on amd64 and
returning zero values elsewhere.

internal/efi is now architecture neutral: it carries no build
constraints, the AMD64 implementation collapses into default_env.go, and
AMD64() selects on a mockable runtimeGOARCH rather than a build tag.
This mirrors the runtime dispatch used elsewhere for host security
checks.

The CPUIDFeature* constants stay in internal/efi, so callers are
unchanged. Their drift guards against the upstream bit positions move to
internal/cpuid, which is now the only package able to see both.

The AMD64 tests lose their build constraints and drive the CPU identity
through new mock hooks instead of mutating upstream package variables,
so they run everywhere. TestNotAMD64Host no longer depends on the host
architecture, and therefore now runs on amd64 too.
Signed-off-by: Alex Lewontin <alex.lewontin@canonical.com>
@alexclewontin

Copy link
Copy Markdown
Member Author

Closing in favor of #565, which I can make a stacked PR :)

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.

2 participants