Skip to content
Merged
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
and the VMM web UI set them, and the VMM rejects malformed `int` and
`float` specs at deployment. See
[Environment value specs](docs/security/cvm-boundaries.md#environment-value-specs).
- **The KMS auth-eth server can require several RPC providers to agree.**
`ETH_RPC_URLS` with `ETH_RPC_QUORUM=n/m` answers a read only with what n of
the m endpoints return alike, and `ETH_MAX_BLOCK_AGE`, required with several
endpoints, rejects a stale block.
`dstack-app/deploy-to-vmm.sh` reads the endpoints from `rpc.json` and keeps
API keys out of the measured compose file. See [Multiple RPC providers](dstack/kms/auth-eth/README.md#multiple-rpc-providers).

### Security

Expand Down Expand Up @@ -48,6 +54,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
in `allowed_envs`. An `allowed_envs` entry that contains a `:` must now be
a valid `NAME: spec`; such an entry used to be a name no variable could
have, and now stops the boot.
- **The KMS auth-eth server pins contract reads to a block hash.** Each
request reads the block it resolved by hash (EIP-1898) rather than by number,
so the RPC endpoint must accept a block hash in `eth_call`, which the server
checks at startup. HTTP redirects from the endpoint are refused. The server
no longer falls back to `http://localhost:8545`: it exits unless
`ETH_RPC_URL` or `ETH_RPC_URLS` is set.
- A failing `init_script` is reported to the VMM as a boot error.
- **Go SDK module moves to `github.com/Dstack-TEE/dstack/sdk/go/dstack`.**
`go get` now targets the module rooted at the `dstack` package, so pkg.go.dev
lists it under its product name instead of "go". The `dstack` package import
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/troubleshooting-kms-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Then regenerate the app-compose.json and redeploy:
{"error": "error decoding response body: missing field `status` at line 1 column ..."}
```

**Root Cause:** auth-eth is reachable (port 9200 is correct), but it cannot read the contract. Without `ETH_RPC_URL` and `KMS_CONTRACT_ADDR`, auth-eth defaults to `http://localhost:8545` (nothing there) and the zero address, and returns `{status: 'error', ...}` instead of the expected `{status: 'ok', ...}` response. If the RPC is unreachable at startup, auth-eth exits instead, and GetMeta reports "Connection refused".
**Root Cause:** auth-eth is reachable (port 9200 is correct), but it cannot read the contract. Without `KMS_CONTRACT_ADDR`, auth-eth defaults to the zero address and returns `{status: 'error', ...}` instead of the expected `{status: 'ok', ...}` response. If `ETH_RPC_URL` is missing or the RPC is unreachable at startup, auth-eth exits instead, and GetMeta reports "Connection refused".

**Solution:** Ensure your docker-compose.yaml includes both Ethereum configuration variables:

Expand Down
64 changes: 59 additions & 5 deletions dstack/kms/auth-eth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,63 @@ The Bun server sets `idleTimeout` to 255s (Bun's maximum). Bun's default of 10s

### Environment variables

- `ETH_RPC_URL` - ethereum RPC endpoint (default: http://localhost:8545)
- `ETH_RPC_URL` - ethereum RPC endpoint (required unless `ETH_RPC_URLS` is set)
- `ETH_RPC_URLS` - several RPC endpoints separated by whitespace, in place of `ETH_RPC_URL`. see [multiple RPC providers](#multiple-rpc-providers)
- `ETH_RPC_QUORUM` - `n/m`: every read must be answered alike by n of the m endpoints in `ETH_RPC_URLS`; m must be their count and n more than half of it (required with `ETH_RPC_URLS`)
- `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`, which serves only the env public key RPCs and reads the app epoch at `latest`, or `ETH_FINALITY_CONFIRMATIONS` blocks behind it (at least one) when the providers do not agree on the newest block. the server resolves the tag and reads at that block's hash once at startup, and refuses to start if the RPC cannot serve either. 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)
- `ETH_MAX_BLOCK_AGE` - reject every decision if the block read is older than this many seconds by the server clock (default: unset, no check; required with more than one RPC endpoint). it bounds how far providers that withhold new blocks can hold policy back; leave room for `ETH_BLOCK_TAG`, as `finalized` on Ethereum mainnet is already about 13 minutes old

### Multiple RPC providers

With one endpoint, whoever runs it decides what the KMS reads. `ETH_RPC_URLS`
and `ETH_RPC_QUORUM=n/m` make n providers have to agree instead:

```yaml
environment:
ETH_RPC_URLS: |
https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}
https://mainnet.infura.io/v3/${INFURA_KEY}
https://ethereum-rpc.publicnode.com
ETH_RPC_QUORUM: 2/3
ETH_MAX_BLOCK_AGE: 1800
```

Each request resolves `ETH_BLOCK_TAG` to the highest block n providers have
reached, less `ETH_FINALITY_CONFIRMATIONS`, and takes that block's hash from n
providers that agree on it. Every contract read is then pinned to the hash and
answered only with a result n providers return alike. A provider that fails,
times out or reverts casts no vote, and without n votes the request fails
closed. `ETH_RPC_URL` alone is the same path with `1/1`.

- **Choosing n/m.** Forging a read takes n colluding providers and stopping
the server takes m-n+1, so `2/3` or `3/5` tolerates one or two outages while
`n/n` stops on the first. n must be more than half of m, as otherwise two
groups of providers could each return a different answer. With `latest`, set `ETH_FINALITY_CONFIRMATIONS` to
1 or 2 so that providers a block apart still agree.
- **Stale blocks.** The same m-n+1 providers, by lagging or by reporting an
old block, make the server read an earlier state of the chain, in which a
revoked policy is still in force. Only `ETH_MAX_BLOCK_AGE` bounds this, so
the server refuses to start with several endpoints and no such limit. The
bounds are proved in `formal/DstackFormal/Kms/RpcQuorum.lean`.
- **Choosing providers.** Use endpoints whose origin serves one chain and
nothing a customer controls. A provider that selects a chain or a
user-defined fork by path or by key lets whoever supplies the key decide what
that endpoint answers. Origins must be distinct, but two that resell the same
upstream are still one provider.
- **API keys.** The endpoint list and the quorum belong in the measured
compose file; the keys do not. `m` is stated apart from the list so that a
key cannot add an endpoint, and a key must not be able to leave its place in
the URL: in a dstack CVM, give it an `allowed_envs` spec such as
`ALCHEMY_KEY: /[A-Za-z0-9_-]{1,128}/` and deliver it through `.user-config`,
as `dstack-app/deploy-to-vmm.sh` does from the specs in its `rpc.json`. Only
the origin of an endpoint is ever logged or served by `GET /`. Redirects are
refused.
- **Cost.** Every request costs m times the RPC calls, and a provider that
hangs holds each request up for the 10-second RPC timeout.

### Reorgs and the block tag

Expand Down Expand Up @@ -146,9 +197,12 @@ health check and system information

`authApiInfo` is a JSON-encoded object the KMS forwards verbatim through its
unauthenticated `GetMeta` RPC, so it carries public data only:
`kmsContractAddr`, `chainId`, `appImplementation`, `ethRpcUrl`, `blockTag`
(`ETH_BLOCK_TAG`), `finalityConfirmations` (`ETH_FINALITY_CONFIRMATIONS`) and
`policyBlockNumber` (the block the policy was read at).
`kmsContractAddr`, `chainId`, `appImplementation`, `ethRpcUrl` (the origins of
the endpoints, joined by commas), `ethRpcUrls` (the same origins as an array),
`rpcQuorum` (`ETH_RPC_QUORUM`), `blockTag`
(`ETH_BLOCK_TAG`), `finalityConfirmations` (`ETH_FINALITY_CONFIRMATIONS`),
`maxBlockAge` (`ETH_MAX_BLOCK_AGE`, when set) and `policyBlockNumber` (the
block the policy was read at).

#### POST /bootAuth/app
application boot authentication
Expand Down
Loading
Loading