Repository navigation
refactor(kms): rename AuthorizationResult.isAllowed to authorized - #1542
Merged
kvinwang merged 7 commits intoNov 9, 2026
Merged
Conversation
Signed-off-by: Kevin Wang <wy721@qq.com>
Signed-off-by: Kevin Wang <wy721@qq.com>
…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
force-pushed
the
refactor/authorization-result-authorized
branch
from
November 9, 2026 13:08
4f75612 to
5162574
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The new
authorizeKms/authorizeAppinterfaces returnAuthorizationResultwith anisAllowedfield. That is the same name the legacyisKmsAllowed/isAppAllowedtuple and/bootAuth/*BootResponseuse, so the two shapes are easy to mix up. On top of that:IAppEpochAuth.authorizeApp(AppInfo, uint256, bytes32)returned a tuple, not the shared result.currentAppEpoch()call, so the epoch and the decision came from two reads./authorizeKmsand/authorizeAppgot the legacy body back, or a non-JSON one.Fix
refactor(kms): rename AuthorizationResult.isAllowed to authorizedauthorized) and the docs.refactor(kms): forward AuthorizationRequest to app epoch policiesOptionalUint256,AuthorizationRequestandAuthorizationResultare now file-level structs inIAppEpochAuth.sol, with the same field order.DstackKmsuses them.IAppEpochAuth.authorizeApp(AuthorizationRequest) returns (AuthorizationResult), so the ERC-165 interface ID changes.DstackApp.authorizeAppvalidates the operation, rejects an app epoch above its current one, and fillsauthorized,rejectionReasonandcurrentAppEpoch.DstackKms.authorizeAppkeeps 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 setsgatewayAppId,currentRootEpochandcurrentRootEpochHash. It no longer callscurrentAppEpoch()on this path.IAppEpochAuth) policies keep theisAppAllowedbranch: app epoch zero only.fix(auth): return AuthorizationResult shape for rejected authorize requests/authorizeKmsand/authorizeAppnow use{authorized:false, rejectionReason, gatewayAppId:'', currentRootEpoch:0, currentRootEpochHash:0x00…, currentAppEpoch:0}. This covers invalid bodies, malformed JSON and oversized bodies.feat(auth): report the latest registered root epoch in authorization resultsAuthorizationResultgainslatestRootEpoch/latestRootEpochHash: the last registered epoch, which may be pending activation, and its chain hash. Both are zero when nothing is registered.DstackKmsfills them inauthorizeKmsandauthorizeApp, including after forwarding to the app policy.rootEpochsentry.MOCK_LATEST_ROOT_EPOCH/MOCK_LATEST_ROOT_EPOCH_HASHoverride it.openapi.jsonand the 400/413 bodies are updated to match.fix(kms): check onboarding handovers against the latest registered root epoch(Blocking Add example crypt-kv #10)Unchecked) and theEmptyregistry behave as before.These stay as they are on purpose:
isKmsAllowed/isAppAllowed, which still return(bool isAllowed, string reason). They keep the same checks in the same order./bootAuth/*andBootResponse.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 nocurrentAppEpoch()call; KMS checks running before forwarding; the legacy branch staying unchanged.forge fmt --check: clean.npx jest: 24 passed;tsc --noEmitclean.bun run test:run); oxlint clean.cargo test -p dstack-kms -p dstack-auth --all-features: 78 and 10 passed; clippy clean.