Repository navigation
feat(kms/auth-eth): require n of m RPC providers to agree - #1650
Conversation
d415922 to
ff4df4e
Compare
ff4df4e to
82cf1d1
Compare
6810e58 to
9f9cc22
Compare
Leechael
left a comment
There was a problem hiding this comment.
Reviewed 9f9cc22 (the two commits of this PR; the branch also carries b67c22d, the pre-rewrite #1654, so it needs a re-sync once that lands).
I ran quorumTransport / EthereumBackend with real viem against local stub JSON-RPC servers (honest, lagging, lying, erroring, hanging), 2/3 unless noted. The safety side holds in everything I tried:
| Scenario | Result |
|---|---|
one provider answers allowed=true on eth_call, two say revoked |
denied |
| one provider reports a much higher finalized block on its own fork | the honest block is used, denied |
| three providers on three forks | fails closed |
| one provider hangs | allowed, about 10 s later (the tag step waits for every provider; KMS's webhook timeout is 60 s, so this is slow, not a denial) |
| one provider without EIP-1898 | allowed, it casts no vote |
| 1/1, endpoint answers with a 302 | refused, the redirect target gets no request |
Three things on the availability / configuration side, inline:
getAppEpochalways resolveslatestwith 0 confirmations, the one combination the README says to avoid, so one faulty provider can fail it whatever the operator configured.- The startup probe does not make a hash-pinned
eth_call, so an endpoint that cannot serve EIP-1898 starts cleanly and then fails every request. ETH_RPC_QUORUMaccepts n <= m/2, where a single provider can decide the answer.
Nit on deploy-to-vmm.sh: init_rpc_json only writes rpc.json when it is missing, so after the first run a changed ETH_RPC_URL in .env is ignored without a message. A warning when both exist and differ would do.
e73bba2 to
3301a94
Compare
|
Thanks for the review. All three inline points are fixed in 83a2575, and the Two more fixes from testing in a CVM: |
ETH_RPC_URLS with ETH_RPC_QUORUM=n/m answers a read only with what n of the m endpoints return alike. Each request resolves the block tag to the highest block n providers have reached, agrees on that block's hash, and pins every eth_call to it (EIP-1898), so ETH_RPC_URL alone now takes the same path as 1/1. ETH_MAX_BLOCK_AGE rejects a block older than the given number of seconds. RPC URLs can carry API keys, so only their origins are logged or served, and m is stated apart from the list so that a value interpolated into one URL cannot add an endpoint. Signed-off-by: Kevin Wang <wy721@qq.com>
deploy-to-vmm.sh takes ETH_RPC_URLS and ETH_RPC_QUORUM. An API key
written as ${NAME} in a URL stays out of the measured compose file: the
key goes under env in the user config, an init_script copies the named
keys into the env file, and an allowed_envs spec keeps each to one path
segment.
Signed-off-by: Kevin Wang <wy721@qq.com>
ETH_RPC_QUORUM now needs n > m/2: with less, one provider (1/3) or one of two groups could decide a read, which the uniqueness proof rules out. The startup probe also makes an eth_call at the resolved block hash, so an endpoint without EIP-1898 fails the start instead of every request. getAppEpoch read at latest with no confirmations, where one provider reporting a head the others lack leaves no quorum. It now falls back to the confirmation depth, or one block. Signed-off-by: Kevin Wang <wy721@qq.com>
The script went on and exited 0 after vmm-cli failed. It also warns when ETH_RPC_URL in .env differs from an existing rpc.json, which takes precedence. Signed-off-by: Kevin Wang <wy721@qq.com>
The VMM showed only the init-script boot progress; the reason was in the serial log alone. Signed-off-by: Kevin Wang <wy721@qq.com>
3301a94 to
72bbb54
Compare
Stacked on #1649, with #1654 merged in for
vmm-cli compose --init-script; review the last two commits.Problem
auth-eth reads policy through one RPC endpoint, so whoever runs that endpoint decides what the KMS authorizes.
Fix
eth_chainId,eth_getBlockByNumberandeth_call, and refuses any other method.eth_callto the hash (EIP-1898,requireCanonical).ETH_RPC_URLalone takes the same path as1/1, the server no longer falls back tohttp://localhost:8545when neither variable is set, andGET /app/:appIdresolveslatestthe same way.ETH_MAX_BLOCK_AGE. Rejects a block older than the given number of seconds. It is the only bound on m-n+1 providers that lag or report an old block, which make the server read an earlier state, so the server refuses to start with several endpoints and no such limit;deploy-to-vmm.shchecks the same before deploying.formal/DstackFormal/Kms/RpcQuorum.leanproves, for fewer than n faulty providers, that an agreed answer is the honest one and that a tag resolves to a block no higher than an honest provider has reached; no lower takes n honest answers, andm/mlets one provider hold it back arbitrarily.GET /.mis stated apart from the list, so a value interpolated into one URL cannot add an endpoint. Redirects are refused.deploy-to-vmm.shreads the public part fromrpc.json, so the validation regex of each key is the deployer's to set:{ "quorum": "2/3", "endpoints": [ "https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}", "https://mainnet.infura.io/v3/${INFURA_KEY}", "https://ethereum-rpc.publicnode.com" ], "keys": { "ALCHEMY_KEY": "/[A-Za-z0-9_-]{32}/", "INFURA_KEY": "/[0-9a-f]{32}/" } }endpointsandquorumfill the compose file andkeysbecomesallowed_envsthroughvmm-cli compose --env-spec; a${NAME}without a spec is an error. The key values come from.envand stay out of the measured compose file: they go underenvin the user config, apart from the fields dstack defines, andvmm-cli compose --init-script(feat(vmm-cli)!: add compose --init-script, make update take a rendered compose #1654) sets theinit_scripttodstack-util import-env ALCHEMY_KEY INFURA_KEY(feat(dstack-util): validate env values against specs in allowed_envs #1649), which copies them into the env file and refuses a missing key or one that breaks its spec. A guest older than 0.6.7 has noimport-envand stops at theinit_script. An existing.envwithETH_RPC_URLdeploys as before: the first run writes it torpc.jsonas1/1.A failed request now logs the reason with the provider's origin (
no 2 of 3 RPCs agree on eth_call (https://…: HTTP request failed.)), and the startup probe reportscannot resolve ETH_BLOCK_TAG=…with that reason instead of calling every failure an unsupported tag.GET /reportsethRpcUrlas the origins joined by commas and addsethRpcUrls(the origins as an array),rpcQuorumandmaxBlockAgetoauthApiInfo.Rendered example
deploy-to-vmm.shwith therpc.jsonabove andETH_MAX_BLOCK_AGE=1800in.envrenders thisdocker-compose.yaml(theauth-apiservice;${ALCHEMY_KEY}and${INFURA_KEY}stay literal until the guest substitutes them):and this
.app-compose.json, which holds no key value:{ "manifest_version": 2, "name": "kms", "runner": "docker-compose", "docker_compose_file": "<the docker-compose.yaml above>", "kms_enabled": false, "gateway_enabled": false, "local_key_provider_enabled": true, "key_provider_id": "", "public_logs": true, "public_sysinfo": true, "allowed_envs": [ "ALCHEMY_KEY: /[A-Za-z0-9_-]{32}/", "INFURA_KEY: /[0-9a-f]{32}/" ], "no_instance_id": true, "secure_time": true, "init_script": "dstack-util import-env ALCHEMY_KEY INFURA_KEY\n" }The key values travel in the unmeasured
.user-config:{"env": {"ALCHEMY_KEY": "<key>", "INFURA_KEY": "<key>"}}Behavior changes for existing deployments
eth_call. Not checked against Helios.eth_getBlockByNumbercall.Not included
Verification
bun run check(67 tests);lake buildinformal.agreeandreached, three local Anvil nodes (one chain, two forks of it),ETH_BLOCK_TAG=latest,2/3: all agree; one node two blocks ahead on its own fork; one node down; two live nodes on different forks at the same height (fails closed);ETH_MAX_BLOCK_AGEexceeded (fails closed); no key in any log.deploy-to-vmm.shwith fake keys, the realvmm-cli composeand a stubbedvmm-cli deploy(defaultrpc.json,2/3with two keys, a key without a value, a${NAME}without a spec, invalid JSON). Ran the generatedinit_scriptunderset -eand thenexec-with-env --composewith a debugdstack-utilfrom feat(dstack-util): validate env values against specs in allowed_envs #1649: valid keys reach the app; a malformed key, a missing key and a missing user config stop atimport-env; adstack-utilwithoutimport-envstops there too. Not booted in a CVM.