Skip to content

Commit f0d0e06

Browse files
authored
Merge pull request #796 from Dstack-TEE/feat/shared-api-auth
feat(auth): protect VMM with shared API authentication
2 parents 49723e4 + 4d810bf commit f0d0e06

16 files changed

Lines changed: 614 additions & 542 deletions

File tree

dstack/Cargo.lock

Lines changed: 38 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dstack/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ members = [
6666
"crates/dstack-cli",
6767
"crates/dstackup",
6868
"crates/dstack-auth",
69+
"crates/api-auth",
6970
"crates/build-info",
7071
]
7172
resolver = "2"
@@ -79,6 +80,7 @@ dstack-kms-rpc = { path = "kms/rpc" }
7980
dstack-guest-agent-rpc = { path = "guest-agent/rpc" }
8081
dstack-vmm-rpc = { path = "vmm/rpc" }
8182
dstack-cli-core = { path = "crates/dstack-cli-core" }
83+
dstack-api-auth = { path = "crates/api-auth" }
8284
dstack-build-info = { path = "crates/build-info" }
8385
cc-eventlog = { path = "cc-eventlog" }
8486
supervisor = { path = "supervisor" }
@@ -144,6 +146,7 @@ flate2 = "1.1"
144146
borsh = { version = "1.5.7", default-features = false, features = ["derive"] }
145147
bon = { version = "3.4.0", default-features = false }
146148
base64 = "0.22.1"
149+
bcrypt = "0.17.1"
147150
hex = { version = "0.4.3", default-features = false }
148151
hex_fmt = "0.3.0"
149152
hex-literal = "1.0.0"

dstack/crates/api-auth/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: © 2026 Phala Network <dstack@phala.network>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
[package]
6+
name = "dstack-api-auth"
7+
version.workspace = true
8+
authors.workspace = true
9+
edition.workspace = true
10+
license.workspace = true
11+
12+
[dependencies]
13+
anyhow.workspace = true
14+
base64.workspace = true
15+
bcrypt.workspace = true
16+
rocket.workspace = true
17+
sha2.workspace = true
18+
subtle.workspace = true

dstack/crates/api-auth/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!--
2+
SPDX-FileCopyrightText: © 2026 Phala Network <dstack@phala.network>
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
# dstack-api-auth
8+
9+
Shared authentication primitives for dstack HTTP and RPC administration APIs.
10+
11+
HTTP integrations support:
12+
13+
- `Authorization: Bearer <token>`;
14+
- the shared `X-Admin-Token` header used by Gateway and VMM;
15+
- `Authorization: Basic ...` backed by a bcrypt Apache htpasswd file;
16+
- optional GET-only `?token=` links for the Gateway and VMM dashboards.
17+
18+
Generate a compatible password file with:
19+
20+
```bash
21+
htpasswd -B -c /etc/dstack/admin.htpasswd admin
22+
```
23+
24+
Gateway's existing token configuration and environment variables remain
25+
supported. VMM's existing `[auth] enabled` and `tokens` fields remain supported;
26+
when enabled, authentication now covers the complete externally listening
27+
Rocket server. The separate VMM host-vsock server is intentionally unaffected.
28+
29+
KMS continues to accept the existing SHA-256 `admin_token_hash` and protobuf
30+
request token. Its comparison uses the constant-time verifier from this crate;
31+
the public KMS application APIs are not placed behind operator HTTP Basic auth.

0 commit comments

Comments
 (0)