You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The KMS CVM includes an auth-api service that connects to your DstackKms contract. Configure it via environment variables in the KMS CVM:
49
62
@@ -56,7 +69,7 @@ Note: The auth-api uses `KMS_CONTRACT_ADDR`, while Hardhat tasks use `KMS_CONTRA
56
69
57
70
The auth-api validates boot requests against the smart contract. See [Deployment Guide](./deployment.md#2-deploy-kms-as-cvm) for complete setup instructions.
export NEAR_RPC_URL="https://free.rpc.fastnear.com"# optional, auto-detected if not set
230
+
```
231
+
232
+
### Configure KMS for NEAR Auth
233
+
234
+
The KMS CVM can be configured to use NEAR contracts in two ways:
235
+
236
+
**Option 1: Direct NEAR integration (recommended)**
237
+
238
+
Configure via TOML config file:
239
+
240
+
```toml
241
+
[core.auth_api]
242
+
type = "near"
243
+
244
+
[core.auth_api.near]
245
+
url = "http://auth-near:3000"# Optional: auth-near webhook service URL
246
+
rpc_url = "https://free.rpc.fastnear.com"
247
+
network_id = "testnet"
248
+
contract_id = "<kms-contract-account-id>"
249
+
mpc_contract_id = "<mpc-contract-id>"# Optional: for MPC key derivation
250
+
mpc_domain_id = 2# Optional: default is 2
251
+
```
252
+
253
+
**Option 2: Via webhook service**
254
+
255
+
Deploy the `auth-near` webhook service and configure KMS to use it:
256
+
257
+
```toml
258
+
[core.auth_api]
259
+
type = "webhook"
260
+
261
+
[core.auth_api.webhook]
262
+
url = "http://auth-near:3000"
263
+
```
264
+
265
+
The `auth-near` service validates boot requests against NEAR smart contracts. See [auth-near README](../kms/auth-near/README.md) for complete setup instructions.
266
+
267
+
### Whitelist OS Image
268
+
269
+
Add an OS image hash to the KMS contract's allowed list:
270
+
271
+
```bash
272
+
cd dstack/kms/auth-near
273
+
bun install
274
+
bun cli.ts add-os-image 0x<os-image-hash>
275
+
```
276
+
277
+
Output: `✅ OS image hash added successfully`
278
+
279
+
The `os_image_hash` is in the `digest.txt` file from the guest OS image build (see [Building Guest Images](./deployment.md#building-guest-images)).
280
+
281
+
**Remove an OS image:**
282
+
283
+
```bash
284
+
bun cli.ts remove-os-image 0x<os-image-hash>
285
+
```
286
+
287
+
### Register Gateway App
288
+
289
+
Deploy and register a gateway app contract:
290
+
291
+
```bash
292
+
bun cli.ts deploy <app-id><owner-id> \
293
+
--allow-any-device \
294
+
--compose-hash 0x<compose-hash> \
295
+
--deposit 30
296
+
```
297
+
298
+
Sample output:
299
+
300
+
```
301
+
✅ App contract deployed successfully!
302
+
App Account: <app-id>.<kms-contract-id>
303
+
Transaction: <transaction-hash>
304
+
```
305
+
306
+
Note the App Account ID (e.g., `gateway.kms.dstack.testnet`).
307
+
308
+
Set it as the gateway app:
309
+
310
+
```bash
311
+
near call <kms-contract-id> set_gateway_app_id \
312
+
'{"app_id": "<app-account-id>"}' \
313
+
--accountId <your-account-id> \
314
+
--deposit 1
315
+
```
316
+
317
+
Output: `Gateway App ID set successfully`
318
+
319
+
**Add compose hash to gateway:**
320
+
321
+
```bash
322
+
bun cli.ts add-hash <app-account-id> 0x<compose-hash>
323
+
```
324
+
325
+
### Register Apps On-Chain
326
+
327
+
For each app you want to deploy:
328
+
329
+
#### Create App
330
+
331
+
Deploy and register an app contract:
332
+
333
+
```bash
334
+
bun cli.ts deploy <app-id><owner-id> \
335
+
--allow-any-device \
336
+
--compose-hash 0x<compose-hash> \
337
+
--deposit 30
338
+
```
339
+
340
+
Note the App Account ID from the output (format: `<app-id>.<kms-contract-id>`).
0 commit comments