@@ -172,12 +172,23 @@ Start VMM:
172172
173173### 2. Deploy KMS as CVM
174174
175- > ** TODO:** This section needs a proper rewrite covering auth server configuration. The current instructions are incomplete.
175+ Production KMS requires three components running together:
176+ - ** KMS** : The key management service inside a CVM
177+ - ** auth-api** : Webhook server that validates requests against smart contracts
178+ - ** Ethereum RPC** : Access to the blockchain (via light client or external RPC)
176179
177- Production KMS deployment requires:
178- - KMS running inside a CVM
179- - Auth server for authorization (webhook mode, not dev mode)
180- - OS image whitelisting
180+ #### Prerequisites: Deploy DstackKms Contract
181+
182+ Before deploying KMS, you need a DstackKms contract on an Ethereum-compatible network:
183+
184+ ``` bash
185+ cd dstack/kms/auth-eth
186+ npm install
187+ npx hardhat compile
188+ PRIVATE_KEY=< your-key> npx hardhat kms:deploy --with-app-impl --network < network>
189+ ```
190+
191+ Note the deployed contract address (e.g., ` 0xFE6C45aE66344CAEF5E5D7e2cbD476286D651875 ` ).
181192
182193#### Deploy KMS CVM
183194
@@ -189,13 +200,29 @@ cd dstack/kms/dstack-app/
189200Edit the generated ` .env ` file:
190201
191202``` bash
203+ # VMM connection
192204VMM_RPC=unix:../../vmm-data/vmm.sock
205+
206+ # Network configuration
193207KMS_RPC_ADDR=0.0.0.0:9201
194208GUEST_AGENT_ADDR=127.0.0.1:9205
195- GIT_REV=HEAD
209+
210+ # Auth server configuration (required for production)
211+ KMS_CONTRACT_ADDR=0xFE6C45aE66344CAEF5E5D7e2cbD476286D651875
212+ ETH_RPC_URL=https://rpc.phala.network
213+
214+ # OS image verification
196215OS_IMAGE=dstack-0.5.5
216+ IMAGE_DOWNLOAD_URL=https://github.com/Dstack-TEE/meta-dstack/releases/download/v{version}/dstack-{version}.tar.gz
217+
218+ # Build reference
219+ GIT_REV=HEAD
197220```
198221
222+ The compose file (` docker-compose.yaml ` ) includes:
223+ - ** auth-api** : Connects to the smart contract via ` ETH_RPC_URL `
224+ - ** kms** : Configured with webhook auth mode pointing to auth-api
225+
199226Run the script again to deploy:
200227
201228``` bash
@@ -224,25 +251,41 @@ The KMS will display its public key and TDX quote:
224251
225252![ KMS Bootstrap Result] ( assets/kms-bootstrap-result.png )
226253
227- #### Configure Auth Server
228-
229- > ** TODO:** Document auth server setup for production KMS.
230-
231254#### Whitelist OS Image
232255
233- The OS image hash must be whitelisted before apps can run. This is required for both offchain and onchain governance.
256+ The OS image hash must be whitelisted in the DstackKms contract before apps can run:
257+
258+ ``` bash
259+ cd dstack/kms/auth-eth
260+ npx hardhat kms:add-image --network < network> 0x< os-image-hash>
261+ ```
234262
235- > ** TODO: ** Document OS image whitelisting for offchain auth server .
263+ The ` os_image_hash ` is in the ` digest.txt ` file from the [ meta-dstack release ] ( https://github.com/Dstack-TEE/meta-dstack/releases ) .
236264
237- For on-chain governance , see [ On-Chain Governance] ( ./onchain-governance.md ) .
265+ For detailed smart contract operations , see [ On-Chain Governance] ( ./onchain-governance.md ) .
238266
239267---
240268
241269### 3. Deploy Gateway as CVM
242270
243- > ** TODO: ** This section is incomplete. Gateway registration with auth server needs to be documented .
271+ The Gateway must be registered as an app in the DstackKms contract before deployment .
244272
245- Deploy the Gateway CVM:
273+ #### Register Gateway App
274+
275+ ``` bash
276+ cd dstack/kms/auth-eth
277+ npx hardhat kms:create-app --network < network> --allow-any-device
278+ ```
279+
280+ Note the App ID from output (e.g., ` 0x32467b43BFa67273FC7dDda0999Ee9A12F2AaA08 ` ).
281+
282+ Set it as the gateway app in the KMS contract:
283+
284+ ``` bash
285+ npx hardhat kms:set-gateway --network < network> < app-id>
286+ ```
287+
288+ #### Deploy Gateway CVM
246289
247290``` bash
248291cd dstack/gateway/dstack-app/
@@ -252,32 +295,55 @@ cd dstack/gateway/dstack-app/
252295Edit ` .env ` :
253296
254297``` bash
298+ # VMM connection
255299VMM_RPC=unix:../../vmm-data/vmm.sock
300+
301+ # Cloudflare (for DNS-01 ACME challenge)
256302CF_API_TOKEN=your_cloudflare_api_token
303+
304+ # Domain configuration
257305SRV_DOMAIN=example.com
258306PUBLIC_IP=$( curl -s ifconfig.me)
259- ACME_STAGING=yes
307+
308+ # Gateway app ID (from registration above)
309+ GATEWAY_APP_ID=0x32467b43BFa67273FC7dDda0999Ee9A12F2AaA08
310+
311+ # Gateway URLs
312+ MY_URL=https://gateway.example.com:9202
313+ BOOTNODE_URL=https://gateway.example.com:9202
314+
315+ # Other settings
316+ ACME_STAGING=no # Set to 'yes' for testing
260317OS_IMAGE=dstack-0.5.5
261318```
262319
263- Deploy :
320+ Run the script again - it will show the compose hash :
264321
265322``` bash
266323./deploy-to-vmm.sh
267- # Press 'y' to confirm
324+ # Output: Compose hash: 0x700a50336df7c07c82457b116e144f526c29f6d8...
325+ ```
326+
327+ ** Before pressing 'y'** , whitelist the compose hash:
328+
329+ ``` bash
330+ cd ../../kms/auth-eth
331+ npx hardhat app:add-hash --network < network> --app-id < gateway-app-id> 0x< compose-hash>
268332```
269333
270- Update ` vmm.toml ` with KMS and Gateway URLs:
334+ Then return and confirm deployment.
335+
336+ #### Update VMM Configuration
337+
338+ After Gateway is running, update ` vmm.toml ` with KMS and Gateway URLs:
271339
272340``` toml
273341[cvm ]
274342kms_urls = [" https://kms.example.com:9201" ]
275343gateway_urls = [" https://gateway.example.com:9202" ]
276344```
277345
278- Restart dstack-vmm.
279-
280- > ** TODO:** Document Gateway registration with offchain auth server.
346+ Restart dstack-vmm to apply changes.
281347
282348---
283349
@@ -349,9 +415,22 @@ gateway_urls = ["https://gateway.example.com:9202"]
349415
350416After setup, deploy apps via the VMM dashboard or CLI.
351417
352- > ** TODO:** Document app registration with offchain auth server.
418+ ### Register App
419+
420+ Each app needs to be registered in the DstackKms contract:
421+
422+ ``` bash
423+ cd dstack/kms/auth-eth
424+ npx hardhat kms:create-app --network < network> --allow-any-device
425+ ```
426+
427+ Note the App ID from output. Then whitelist your compose hash:
428+
429+ ``` bash
430+ npx hardhat app:add-hash --network < network> --app-id < app-id> 0x< compose-hash>
431+ ```
353432
354- For on-chain governed apps , see [ On-Chain Governance] ( ./onchain-governance.md ) .
433+ For detailed smart contract operations , see [ On-Chain Governance] ( ./onchain-governance.md ) .
355434
356435### Deploy via UI
357436
@@ -360,7 +439,7 @@ Open `http://localhost:9080`:
360439![ App Deploy] ( assets/app-deploy.png )
361440
362441- Select the OS image
363- - Enter the App ID (from auth server registration)
442+ - Enter the App ID (from registration above )
364443- Upload your ` docker-compose.yaml `
365444
366445After startup, click ** Dashboard** to view:
0 commit comments