Skip to content

refactor(kms): rename AuthorizationResult.isAllowed to authorized - #1542

Merged
kvinwang merged 7 commits into
feat/kms-epochs-combinedfrom
refactor/authorization-result-authorized
Nov 9, 2026
Merged

kvinwang merged 7 commits into
feat/kms-epochs-combinedfrom
refactor/authorization-result-authorized

Conversation

@kvinwang

@kvinwang kvinwang commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The new authorizeKms / authorizeApp interfaces return AuthorizationResult with an isAllowed field. That is the same name the legacy isKmsAllowed / isAppAllowed tuple and /bootAuth/* BootResponse use, so the two shapes are easy to mix up. On top of that:

  • The app-level IAppEpochAuth.authorizeApp(AppInfo, uint256, bytes32) returned a tuple, not the shared result.
  • The KMS read the app epoch with a separate currentAppEpoch() call, so the epoch and the decision came from two reads.
  • Invalid requests to /authorizeKms and /authorizeApp got the legacy body back, or a non-JSON one.

Fix

  1. refactor(kms): rename AuthorizationResult.isAllowed to authorized

    • The field is renamed end to end: Solidity, auth-eth, auth-eth-bun, auth-simple, auth-mock, dstack-auth, dstack-kms (serde: authorized) and the docs.
  2. refactor(kms): forward AuthorizationRequest to app epoch policies

    • OptionalUint256, AuthorizationRequest and AuthorizationResult are now file-level structs in IAppEpochAuth.sol, with the same field order. DstackKms uses them.
    • The new signature is IAppEpochAuth.authorizeApp(AuthorizationRequest) returns (AuthorizationResult), so the ERC-165 interface ID changes.
    • DstackApp.authorizeApp validates the operation, rejects an app epoch above its current one, and fills authorized, rejectionReason and currentAppEpoch.
    • DstackKms.authorizeApp keeps the checks it owns: operation scope, root epoch registered, requested root epoch not beyond the current one, app registered, OS image at the selected root epoch, and contract deployed. It then forwards the request unchanged and sets gatewayAppId, currentRootEpoch and currentRootEpochHash. It no longer calls currentAppEpoch() on this path.
    • Legacy (non-IAppEpochAuth) policies keep the isAppAllowed branch: app epoch zero only.
  3. fix(auth): return AuthorizationResult shape for rejected authorize requests

    • In auth-eth and auth-eth-bun, 400 and 413 responses on /authorizeKms and /authorizeApp now use {authorized:false, rejectionReason, gatewayAppId:'', currentRootEpoch:0, currentRootEpochHash:0x00…, currentAppEpoch:0}. This covers invalid bodies, malformed JSON and oversized bodies.
  4. feat(auth): report the latest registered root epoch in authorization results

    • AuthorizationResult gains latestRootEpoch / latestRootEpochHash: the last registered epoch, which may be pending activation, and its chain hash. Both are zero when nothing is registered.
    • DstackKms fills them in authorizeKms and authorizeApp, including after forwarding to the app policy.
    • auth-simple and dstack-auth report the last configured rootEpochs entry.
    • auth-mock defaults to the current epoch; MOCK_LATEST_ROOT_EPOCH / MOCK_LATEST_ROOT_EPOCH_HASH override it.
    • The ABIs, schemas, openapi.json and the 400/413 bodies are updated to match.
  5. fix(kms): check onboarding handovers against the latest registered root epoch (Blocking Add example crypt-kv #10)

    • A plain join used to check only the current epoch's chain hash, so a pending tail the source held was imported unchecked.
    • The joiner now also checks the source against the latest registered epoch L. It refuses a source that holds epochs beyond L. When the source holds exactly L, L's chain hash must match, which binds the whole tail because chain hashes are cumulative. A source at or past the current epoch but behind L still joins.
    • Rotation additionally requires L == current, so the locally generated epoch cannot collide with an already registered one.
    • The dev backend (Unchecked) and the Empty registry behave as before.

These stay as they are on purpose:

  • Legacy isKmsAllowed / isAppAllowed, which still return (bool isAllowed, string reason). They keep the same checks in the same order.
  • /bootAuth/* and BootResponse.isAllowed, including their error bodies.

Tests

  • forge clean && forge test --ffi: 91 passed. This includes a pending registered epoch (latest != current) on both authorize paths. New tests cover: the app rejecting a wrong-scope operation and a future app epoch; the KMS forwarding the exact encoded request (vm.expectCall), overwriting KMS-owned fields and making no currentAppEpoch() call; KMS checks running before forwarding; the legacy branch staying unchanged.
  • forge fmt --check: clean.
  • auth-eth npx jest: 24 passed; tsc --noEmit clean.
  • auth-eth-bun 51, auth-simple 34, auth-mock 15 passed (bun run test:run); oxlint clean.
  • cargo test -p dstack-kms -p dstack-auth --all-features: 78 and 10 passed; clippy clean.

…quests

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

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

Signed-off-by: Kevin Wang <wy721@qq.com>
A source holding epochs past the current one but fewer than the latest
registered epoch passed the join check: only the latest chain hash
binds the tail, so those epochs went unchecked. Require such a source
to hold exactly the latest registered epoch.

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

Rebased onto #1539, whose tests still used the old shapes: qualified
DstackKms.AuthorizationRequest/Result types, the isAllowed field, the
three-argument DstackApp.authorizeApp, and backend answers without the
latest root epoch fields. Move them to the shared types, `authorized`,
the authorizeAt helper and complete answers.

test_AuthorizeAppOwnsOperationScopeAndAppEpoch now prepares row 0 with
the *AtEpoch setters: since #1539 the epoch-less setters also write the
next row, so the current row would no longer be empty after advancing.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang force-pushed the refactor/authorization-result-authorized branch from 4f75612 to 5162574 Compare November 9, 2026 13:08
@kvinwang
kvinwang merged commit be23bf1 into feat/kms-epochs-combined Nov 9, 2026
3 checks passed
@kvinwang
kvinwang deleted the refactor/authorization-result-authorized branch November 9, 2026 13:36
kvinwang added a commit that referenced this pull request Nov 9, 2026
Rebased onto #1542: the decoding test's provider mock needs getBlock now
that authorization requests resolve the block tag, and the block-pinning
test returns the two latest root epoch fields the result now carries.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 9, 2026
…tation

DiskMigration now models the two-keyslot migration of #1539 (luksAddKey,
token bound to its keyslot, luksKillSlot) instead of luksHeaderRestore, and
lets the KMS rotate at any point of a boot. All invariants hold for epochs
0-3; the torn-restore script and the configs for the replaced scheme go.

KmsRotation checks the latest registered epoch's chain hash on handover, as
onboard_service.rs does since #1542, so HandoverAgreesWithRegistry now holds
and joins the main config.

EnvUpdate gains FailClosed for the guest of #1546, which holds with a lossy
host API; the lossy config keeps the earlier guest as a counterexample.

The README records the mutations each model catches.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 9, 2026
…acts

Follow the interface of #1542: AuthorizationRequest and AuthorizationResult
live in IAppEpochAuth.sol, `isAllowed` is `authorized`, and DstackApp's
authorizeApp takes the request.

Update the properties that the review intentionally changed:
- *AtEpoch setters may prepare the next app epoch, and revert past it;
- the legacy isAppAllowed refuses at a nonzero app epoch, and at epoch 0
  decides at epoch 0 even with the next row prepared;
- epoch-less KMS setters write every row from the current epoch to the
  latest one;
- the legacy isKmsAllowed decides at root epoch 0.

Each changed property was mutation-tested against the matching bug.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 9, 2026
…acts

Follow the interface of #1542: AuthorizationRequest and AuthorizationResult
live in IAppEpochAuth.sol, `isAllowed` is `authorized`, and DstackApp's
authorizeApp takes the request.

Update the properties that the review intentionally changed:
- *AtEpoch setters may prepare the next app epoch, and revert past it;
- the legacy isAppAllowed refuses at a nonzero app epoch, and at epoch 0
  decides at epoch 0 even with the next row prepared;
- epoch-less KMS setters write every row from the current epoch to the
  latest one;
- the legacy isKmsAllowed decides at root epoch 0.

Each changed property was mutation-tested against the matching bug.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 9, 2026
…tation

DiskMigration now models the two-keyslot migration of #1539 (luksAddKey,
token bound to its keyslot, luksKillSlot) instead of luksHeaderRestore, and
lets the KMS rotate at any point of a boot. All invariants hold for epochs
0-3; the torn-restore script and the configs for the replaced scheme go.

KmsRotation checks the latest registered epoch's chain hash on handover, as
onboard_service.rs does since #1542, so HandoverAgreesWithRegistry now holds
and joins the main config.

EnvUpdate gains FailClosed for the guest of #1546, which holds with a lossy
host API; the lossy config keeps the earlier guest as a counterexample.

The README records the mutations each model catches.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 9, 2026
…acts

Follow the interface of #1542: AuthorizationRequest and AuthorizationResult
live in IAppEpochAuth.sol, `isAllowed` is `authorized`, and DstackApp's
authorizeApp takes the request.

Update the properties that the review intentionally changed:
- *AtEpoch setters may prepare the next app epoch, and revert past it;
- the legacy isAppAllowed refuses at a nonzero app epoch, and at epoch 0
  decides at epoch 0 even with the next row prepared;
- epoch-less KMS setters write every row from the current epoch to the
  latest one;
- the legacy isKmsAllowed decides at root epoch 0.

Each changed property was mutation-tested against the matching bug.

Signed-off-by: Kevin Wang <wy721@qq.com>
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