Repository navigation
feat(kms/auth-eth): delegate app authorization while KMS policy stays on chain #1648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,8 +53,9 @@ The Bun server sets `idleTimeout` to 255s (Bun's maximum). Bun's default of 10s | |
| - `KMS_CONTRACT_ADDR` - KMS contract address (default: 0x0000000000000000000000000000000000000000) | ||
| - `PORT` - server port (default: 3000) | ||
| - `ETH_CHAIN_ID` - reject every decision if the RPC reports a different chain ID (default: unset, no check) | ||
| - `ETH_BLOCK_TAG` - block policy is read at: `latest`, `safe` or `finalized` (default: `finalized`). each request resolves the tag to one block and reads all state there, except `GET /app/:appId`, which serves only the env public key RPCs and reads the app epoch at `latest`. the server resolves the tag once at startup and refuses to start if the RPC cannot serve it. a later tag delays every policy change, including emergency revocations, until that block is reached (about 13 minutes for `finalized` on Ethereum mainnet). use `finalized` on L1. set `latest` explicitly for an OP-stack chain read through the Helios light client, which tracks only the sequencer-signed unsafe head and serves neither `safe` nor `finalized`, and for local development chains such as Anvil, which finalizes 64 blocks behind its head. see [reorgs and the block tag](#reorgs-and-the-block-tag) before using `latest` or `safe` | ||
| - `ETH_BLOCK_TAG` - block policy is read at: `latest`, `safe` or `finalized` (default: `finalized`). each request resolves the tag to one block and reads all state there, except `GET /app/:appId` when `APP_AUTH_URL` is unset, which serves only the env public key RPCs and reads the app epoch at `latest`. the server resolves the tag once at startup and refuses to start if the RPC cannot serve it. a later tag delays every policy change, including emergency revocations, until that block is reached (about 13 minutes for `finalized` on Ethereum mainnet). use `finalized` on L1. set `latest` explicitly for an OP-stack chain read through the Helios light client, which tracks only the sequencer-signed unsafe head and serves neither `safe` nor `finalized`, and for local development chains such as Anvil, which finalizes 64 blocks behind its head. see [reorgs and the block tag](#reorgs-and-the-block-tag) before using `latest` or `safe` | ||
| - `ETH_FINALITY_CONFIRMATIONS` - read this many blocks further behind the block `ETH_BLOCK_TAG` resolves to (default: 0) | ||
| - `APP_AUTH_URL` - optional absolute http(s) URL of an app-authorization service (default: unset). when unset, `/authorizeApp` and `GET /app/:appId` are read from `DstackKms`. when set, those two routes are forwarded to this URL at the same path. the server refuses to start if the value is not an absolute http(s) URL without credentials, a query, or a fragment. a blank value is unset. see [delegated app authorization](#delegated-app-authorization) | ||
|
|
||
| ### Reorgs and the block tag | ||
|
|
||
|
|
@@ -240,6 +241,50 @@ remain available. | |
| and subject semantics. Bootstrap alone may authorize before root registration; | ||
| unknown operations are rejected. Legacy `/bootAuth/*` routes are unchanged. | ||
|
|
||
| #### Delegated app authorization | ||
|
|
||
| Set `APP_AUTH_URL` to keep KMS policy on `DstackKms` and let another service | ||
| decide app policy. This is for app identities that are not `DstackApp` | ||
| contracts. Leave it unset to keep the chain path; the default is unchanged. | ||
|
|
||
| When it is set: | ||
|
|
||
| - `POST /authorizeApp` forwards the request body byte for byte, including | ||
| fields this server does not interpret. `launchTicketHash` passes through, and | ||
| so does a future top-level `userConfigHash` (lowercase hex, no `0x` prefix, | ||
| app operations only). The delegate returns `authorized`, `rejectionReason`, | ||
| and `currentAppEpoch`. This server overwrites `gatewayAppId`, | ||
| `currentRootEpoch`, `currentRootEpochHash`, `latestRootEpoch`, and | ||
| `latestRootEpochHash` with values read from `DstackKms` at the request's | ||
| pinned block, the same block `GET /` uses. | ||
| - A `requestedRootEpoch` newer than the current root epoch is denied without | ||
| calling the delegate (`Requested root epoch is not active`). So is an app | ||
| request while no root epoch is registered (`Root epoch not registered`), and | ||
| a KMS operation posted to `/authorizeApp` (`Invalid authorization operation`). | ||
| - A delegate error, timeout (20s, under the KMS webhook timeout of 60s), | ||
| non-2xx response, or invalid JSON is a denial (`authorized: false`) that | ||
| still carries the chain root fields. The delegate's body is not copied into | ||
| `rejectionReason`. If the chain itself cannot be read, the route returns 503 | ||
| and does not call the delegate. | ||
| - `GET /app/:appId` is forwarded to the same path. The app id is checked before | ||
| it is placed in the URL. A delegate failure is 503; this server does not | ||
| invent epoch 0. The chain's `latest` read for this route applies only when | ||
| `APP_AUTH_URL` is unset. | ||
| - `POST /authorizeKms`, `GET /`, and `GET /sevSnpTcbRequirements` stay on chain. | ||
|
|
||
| `POST /bootAuth/app` also stays on chain. Only KMS builds before 0.6.4 call it | ||
| in production, and its response has no root-epoch fields to reconcile with a | ||
| delegate. A delegated deployment must be used with a KMS that calls | ||
| `/authorizeApp`. Do not point an older KMS at `APP_AUTH_URL`: its app boots | ||
| would still be judged by `DstackKms`. | ||
|
|
||
| Deployments of this mode that accept reorg risk should set | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gives no reason specific to the delegated mode. The delegated app path reads no per-app chain state, so |
||
| `ETH_BLOCK_TAG=latest`. The default remains `finalized`. See | ||
| [reorgs and the block tag](#reorgs-and-the-block-tag). | ||
|
|
||
| The delegate is not followed across redirects, and its responses are not | ||
| cached. | ||
|
|
||
| ## Contracts | ||
|
|
||
| ### Prerequisites | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
APP_AUTH_URLset, the key-release app epoch is the delegate'scurrentAppEpoch(epochs.app.unwrap_or(response.current_app_epoch)in the KMS), not a value read at the policy block, so "Key release still reads the policy block" holds only for the chain path.The simple backend's "operators must preserve its monotonicity" also needs a counterpart for the delegate. auth-eth only range-checks its epoch, and a delegate that goes back an epoch (a restore, a bug) makes env public-key lookups and default boots use a retired epoch's keys.
Two places outside the diff that this mode makes wrong:
dstack/kms/auth-eth/README.md:199-200:/authorizeApp"always drop[s]keyProviderInfo". The delegated path forwards the raw body,keyProviderInfoincluded, to an external URL.dstack/kms/README.md:340-343: "The Ethereum backends call the matchingDstackKmsmethod ... the app method applies registered app policy".