Skip to content

feat(auth-eth): let apps restrict the OS images they boot on - #1697

Open
kvinwang wants to merge 2 commits into
nextfrom
feat/app-os-image-allowlist
Open

kvinwang wants to merge 2 commits into
nextfrom
feat/app-os-image-allowlist

Conversation

@kvinwang

@kvinwang kvinwang commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Problem

The only OS-image control is the KMS-global allowlist (DstackKms.allowedOsImages). On the shared KMS it admits development images, dstack-0.6.1 (GHSA-c79w-3x5w-gmm5) and every older release, and an app owner cannot exclude any of them. IAppAuth.AppInfo already carries osImageHash into the app policy, but DstackApp ignores it, so an app's keys are released to any image the KMS owner admits. Related: #1293 (the KMS owner's only revocation lever is the global allowlist).

Fix

DstackApp gets its own OS image allowlist. The KMS checks its allowlist before forwarding to the app, so the effective policy is KMS ∩ app and the app list can only narrow it.

  • allowAnyOsImage() / setAllowAnyOsImage(bool): one switch over every app epoch, like allowAnyDevice / allowAnyTeeVariant. It is on by default, so existing and new apps keep today's behaviour.
  • add/removeOsImageHashAtEpoch(s) and allowedOsImagesAtEpoch: per-app-epoch rows, like compose hashes and devices, with the same writable-epoch rule and the _setAtEpochs range helper.
  • _authorizeApp rejects an unlisted image with OS image not allowed while the switch is off. The image is in AppInfo, so the legacy isAppAllowed enforces it too (unlike TEE variants).
  • Events: AllowAnyOsImageSet, EpochPolicyChanged("os-image", ...) for every row, and PolicyChanged for the switch and for row 0, as the KMS does for its OS images.
  • Storage is append-only: bool _osImagesRestricted (slot 11, zero = unrestricted, so upgraded proxies stay open) and mapping(uint256 => mapping(bytes32 => bool)) _osImagesByEpoch (slot 12). __gap goes from 42 to 40, so slots 0–10 and the end of the gap are unchanged. No reinitializer is needed. version() stays 2, as it did for the epoch, TEE-variant and launch-ticket additions.
  • IAppEpochManagement is unchanged: its ID 0x8c0524c4 shipped in 0.6.4 and tools detect apps by it. The new setters live on DstackApp only, like the launch-ticket setters.
  • Manage.s.sol: AddAppOsImage / RemoveAppOsImage take APP_EPOCH or a range. SetAllowAnyAppOsImage refuses an epoch, and all three refuse apps that predate app epochs. Query.s.sol GetAppSettings prints the switch.
  • dstack-auth (the replacement for the removed auth-simple) gets the same narrowing as an optional apps.<appId>.osImages. It has no per-app epochs, and leaving the field out keeps today's behaviour.
  • Docs: onchain-governance.md, app-key-epochs.md, dstack-auth-operations.md, auth-eth/script/README.md, CHANGELOG.

The auth-eth webhook (index.ts) already passes osImageHash through unchanged, so it needs no change.

Verification

In dstack/kms/auth-eth, with the submodules and @openzeppelin/upgrades-core set up as in CLAUDE.md:

  • forge build: compiles. DstackApp runtime size is 15,178 bytes (was 14,117).
  • forge clean && forge test --ffi: 122 passed, 0 failed, including the OZ upgrade validation of DstackApp against the released v0.5.9 and v0.6.0 layouts.
  • New tests:
    • The default admits any image.
    • Once restricted, an unlisted image is refused and a listed one admitted, on both authorizeApp and the legacy isAppAllowed.
    • App epoch rows are independent; the next row can be prepared before advancing; a range removal revokes the image everywhere.
    • Owner-only setters reject a zero hash.
    • Through DstackKms, an image only the app lists is still refused (OS image is not allowed).
    • A v0.5.9 proxy upgraded to this implementation keeps admitting any image until restricted.
    • The audit events reconstruct the state.
    • The Manage scripts.
  • forge inspect DstackApp storageLayout confirms slots 0–10 match next.
  • cargo test -p dstack-auth: 18 passed. cargo clippy -p dstack-auth -- -D warnings -D clippy::unwrap_used -D clippy::expect_used and cargo fmt --all --check are clean.

Follow-up

  • There is no way to list an app's allowed images on chain (it is a mapping, like compose hashes); indexers use EpochPolicyChanged.
  • deployAndRegisterApp / the initializers cannot set an initial OS image list. An owner who needs a restriction from the first boot should deploy without INITIAL_COMPOSE_HASH, restrict, then add the compose hash.

Signed-off-by: Kevin Wang <wy721@qq.com>
Signed-off-by: Kevin Wang <wy721@qq.com>

This branch has not been deployed

No deployments
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.

1 participant