Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/app-key-epochs.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ without this capability remain at zero; failures of an advertised getter propaga
The Ethereum auth backends query the policy through the KMS contract. The simple
backend reads `apps[appId].currentAppEpoch` (default zero); operators must preserve
its monotonicity. Public encryption-key lookup uses `GET /app/:appId` to read this
value. auth-eth reads it at the `latest` block, so a new app gets its key at
once and an advanced epoch never hands out the retired key; key release
still reads the policy block, so an environment sealed to a just-advanced epoch
boots only once the advance reaches that block. Legacy boot authorization and
value. With `APP_AUTH_URL` unset, auth-eth reads it at the `latest` block, so a
new app gets its key at once and an advanced epoch never hands out the retired
key. When `APP_AUTH_URL` is set, that service answers `GET /app/:appId` and owns
the epoch's freshness. Key release still reads the policy block, so an

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.

With APP_AUTH_URL set, the key-release app epoch is the delegate's currentAppEpoch (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, keyProviderInfo included, to an external URL.
  • dstack/kms/README.md:340-343: "The Ethereum backends call the matching DstackKms method ... the app method applies registered app policy".

environment sealed to a just-advanced epoch boots only once the advance reaches
that block. Legacy boot authorization and
legacy environment public-key issuance are rejected once the app epoch is nonzero,
preventing old clients from silently continuing with epoch-zero keys.

Expand Down
4 changes: 4 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ previous epoch. `ETH_FINALITY_CONFIRMATIONS=N` hides reorgs shallower than N
blocks but delays every policy change, emergency revocations included, by N
blocks. See [reorgs and the block tag](../dstack/kms/auth-eth/README.md#reorgs-and-the-block-tag).

Optional `APP_AUTH_URL` leaves KMS policy on `DstackKms` and forwards
`/authorizeApp` and `GET /app/:appId` to another service. The default, leaving
it unset, is unchanged. See [delegated app authorization](../dstack/kms/auth-eth/README.md#delegated-app-authorization).

#### Getting OS Image Hash

The OS image hash is in the `digest.txt` file inside the guest image tarball:
Expand Down
2 changes: 1 addition & 1 deletion dstack/kms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ client can choose the `remote` that the logs and the key release audit record.
- Chain interface for permission checks
- Two-step validation:
1. KMS control contract check
2. App control contract check
2. App control contract check, or an external app-authorization service when `APP_AUTH_URL` is set ([delegated app authorization](auth-eth/README.md#delegated-app-authorization))

3. **Authorization Contracts** ([`auth-eth`](auth-eth/))
- `DstackKms.sol`
Expand Down
47 changes: 46 additions & 1 deletion dstack/kms/auth-eth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

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.

This gives no reason specific to the delegated mode. The delegated app path reads no per-app chain state, so latest gains it nothing, while what stays on chain (/authorizeKms, the root epochs and, with the fix above, the OS image and TEE variant checks) takes on the reorg exposure described in "reorgs and the block tag". Unless there is a reason I am missing, I would drop this paragraph.

`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
Expand Down
Loading
Loading