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
Copy file name to clipboardExpand all lines: kms/README.md
+62-3Lines changed: 62 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,9 @@ CVMs running in dstack support three boot modes:
33
33
## KMS Implementation
34
34
35
35
### Components
36
+
37
+
#### Ethereum/Base/Phala KMS
38
+
36
39
1.**dstack-kms**
37
40
- Main RPC service for app key requests
38
41
- Quote verification and boot info validation
@@ -56,11 +59,49 @@ CVMs running in dstack support three boot modes:
56
59
- Controls permissions for individual apps
57
60
- Maintains the allowed compose hashes for each app
58
61
62
+
#### NEAR KMS
63
+
64
+
1.**dstack-kms** (same as above)
65
+
- Can be configured to use NEAR auth API instead of Ethereum
66
+
67
+
2.**dstack-kms-auth-near**
68
+
- NEAR Protocol chain interface for permission checks
69
+
- Two-step validation (same as auth-eth):
70
+
1. KMS control contract check
71
+
2. App control contract check
72
+
- Handles hex → NEAR AccountId conversion
73
+
- See [auth-near README](auth-near/README.md) for details
74
+
75
+
3.**NEAR Authorization Contracts**
76
+
-`near-dstack-kms` (Rust contract)
77
+
- Maintains a registry for all Applications
78
+
- Maintains the allowed KMS Instance MRs
79
+
- Maintains the allowed OS Images
80
+
- Supports MPC-based root key derivation from NEAR MPC network
81
+
- Factory method `register_app()` for deploying app contracts
82
+
-`near-dstack-app` (Rust contract)
83
+
- Deployed as subaccounts: `{app_id}.{kms_contract_id}`
84
+
- Controls permissions for individual apps
85
+
- Maintains the allowed compose hashes and device IDs per app
86
+
87
+
4.**MPC Key Derivation** (NEAR-specific)
88
+
- KMS can derive deterministic root keys from NEAR MPC network
89
+
- Uses BLS12-381 cryptography for secure key derivation
90
+
- All KMS instances derive the same keys when using the same MPC domain
91
+
- Falls back to local key generation if MPC config is incomplete
92
+
59
93
### Deployment
60
-
The first two components are deployed as an dstack app on dstack in Local-Key-Provider mode.
94
+
95
+
The KMS components are deployed as a dstack app on dstack in Local-Key-Provider mode.
61
96
The docker compose file would look like [this](dstack-app/docker-compose.yaml).
62
97
63
-
The solidity contracts are deployed on an ethereum compatible chain.
98
+
**Authorization Contracts:**
99
+
-**Ethereum/Base/Phala**: Solidity contracts deployed on an Ethereum-compatible chain
100
+
-**NEAR**: Rust contracts deployed on NEAR Protocol (see [near-kms README](../near-kms/README.md))
101
+
102
+
**App Contract Deployment:**
103
+
-**Ethereum**: Use Hardhat tasks (`app:deploy`, `app:add-hash`) or factory method `deployAndRegisterApp()`
104
+
-**NEAR**: Use CLI commands (`bun run app:deploy`, `bun run app:add-hash`) or KMS contract's `register_app()` method
64
105
65
106
66
107
## Trustness
@@ -89,12 +130,25 @@ On startup, the KMS node will either:
89
130
- Onboard: Obtain root keys from an existing KMS instance
90
131
91
132
#### Bootstrapping
133
+
134
+
**Ethereum/Base/Phala KMS:**
92
135
During bootstrapping, the KMS node generates two root keys:
93
136
1. CA root key: Used to issue x509 certificates for Apps, enabling HTTPS traffic
94
137
2. K256 root key: Used to derive Ethereum-compatible keys for Apps
95
138
96
139
After generating the root keys, their public portions can be obtained along with the corresponding TDX quote and registered in the DstackKms contract.
97
140
141
+
**NEAR KMS with MPC:**
142
+
When configured with NEAR MPC, the KMS node derives deterministic root keys from the NEAR MPC network:
143
+
1. Generates ephemeral BLS12-381 G1 keypair
144
+
2. Calls MPC contract's `request_app_private_key()` with derivation path "kms-root-key"
145
+
3. Receives encrypted response and decrypts using ephemeral private key
146
+
4. Verifies MPC signature using BLS pairing
147
+
5. Derives 32-byte root key using HKDF
148
+
6. Converts root key to CA, tmp CA, RPC, and K256 keys using deterministic key derivation
149
+
150
+
All KMS instances using the same MPC domain will derive identical root keys, enabling seamless replication without key transfer. If MPC configuration is incomplete, the system automatically falls back to local key generation (same as Ethereum).
151
+
98
152
#### KMS Self Replication
99
153
When deploying a new KMS instance (`B`) using an existing instance (`A`), the process follows these steps:
100
154
@@ -117,9 +171,14 @@ Once onboarded, the KMS node begins listening for app key provisioning requests.
117
171
118
172
When a KMS node receives a key provisioning request, it:
119
173
1. Validates the TDX quote of the requesting App
120
-
2. Queries the DstackKms contract for provisioning allowance
174
+
2. Queries the authorization contract (DstackKms or near-dstack-kms) for provisioning allowance
121
175
3. If allowed, generates and sends the keys to the App
122
176
177
+
**NEAR-specific notes:**
178
+
- App contracts are deployed as subaccounts: `{app_id}.{kms_contract_id}`
179
+
- Compose hashes are stored as hex strings (without `0x` prefix)
180
+
- Use `auth-near` CLI commands for app deployment and compose hash management (see [auth-near README](auth-near/README.md#cli-commands))
0 commit comments