Skip to content

Commit 31aa185

Browse files
authored
Merge pull request #804 from Dstack-TEE/gateway-admin-auth-token
Rename gateway core.admin.admin_token to auth_token (alias-compatible)
2 parents a41f495 + 2e935f6 commit 31aa185

9 files changed

Lines changed: 33 additions & 14 deletions

File tree

dstack/gateway/docs/cluster-deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Important:
289289

290290
### 2.7 Verify Cluster Sync
291291

292-
The admin API requires a bearer token (see `core.admin.admin_token` in `gateway.toml`,
292+
The admin API requires a bearer token (see `core.admin.auth_token` in `gateway.toml`,
293293
or the `ADMIN_API_TOKEN` env injected by `deploy-to-vmm.sh`). Export it once:
294294

295295
```bash

dstack/gateway/dstack-app/builder/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ sync_connections_interval = "${SYNC_CONNECTIONS_INTERVAL:-30s}"
9595
enabled = true
9696
address = "${ADMIN_LISTEN_ADDR:-0.0.0.0}"
9797
port = ${ADMIN_LISTEN_PORT:-8001}
98-
admin_token = "${ADMIN_API_TOKEN}"
98+
auth_token = "${ADMIN_API_TOKEN}"
9999
100100
[core.wg]
101101
public_key = "$PUBLIC_KEY"

dstack/gateway/gateway.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ address = "127.0.0.1:8011"
2828
# be supplied via the `DSTACK_GATEWAY_ADMIN_TOKEN` or `ADMIN_API_TOKEN` env
2929
# vars. Clients send it as `Authorization: Bearer <token>`, `X-Admin-Token`,
3030
# or (GET only, for dashboard links) `?token=...`. Required unless
31-
# `insecure_no_auth = true`.
32-
admin_token = ""
31+
# `insecure_no_auth = true`. (The legacy key `admin_token` is still accepted.)
32+
auth_token = ""
3333
# Optional Apache htpasswd file for HTTP Basic authentication.
3434
htpasswd_file = ""
3535
# Development/testing escape hatch only. Never enable this on an admin

dstack/gateway/src/admin_auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ impl AdminAuthFairing {
2323
http_config(),
2424
)));
2525
}
26-
let token = if !config.admin_token.is_empty() {
27-
config.admin_token.trim().to_owned()
26+
let token = if !config.auth_token.is_empty() {
27+
config.auth_token.trim().to_owned()
2828
} else {
2929
std::env::var(ENV_ADMIN_TOKEN)
3030
.or_else(|_| std::env::var(ENV_ADMIN_TOKEN_COMPAT))
@@ -34,8 +34,8 @@ impl AdminAuthFairing {
3434
};
3535
if token.is_empty() && config.htpasswd_file.as_os_str().is_empty() {
3636
bail!(
37-
"admin API is enabled but neither admin_token nor htpasswd_file is configured; \
38-
set core.admin.admin_token, {ENV_ADMIN_TOKEN}, {ENV_ADMIN_TOKEN_COMPAT}, \
37+
"admin API is enabled but neither auth_token nor htpasswd_file is configured; \
38+
set core.admin.auth_token, {ENV_ADMIN_TOKEN}, {ENV_ADMIN_TOKEN_COMPAT}, \
3939
core.admin.htpasswd_file, or insecure_no_auth = true (testing only)"
4040
);
4141
}

dstack/gateway/src/config.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,10 @@ pub struct AdminConfig {
296296
/// Shared secret required to call any admin endpoint (RPC + dashboard).
297297
/// Can also be supplied via `DSTACK_GATEWAY_ADMIN_TOKEN` / `ADMIN_API_TOKEN`
298298
/// env vars. Required unless `insecure_no_auth = true`.
299-
#[serde(default)]
300-
pub admin_token: String,
299+
///
300+
/// Accepts the legacy `admin_token` key for backward compatibility.
301+
#[serde(default, alias = "admin_token")]
302+
pub auth_token: String,
301303
/// Optional Apache htpasswd file. Enables standard HTTP Basic auth while
302304
/// preserving token authentication for existing clients.
303305
#[serde(default)]
@@ -354,8 +356,25 @@ pub fn setup_wireguard(config: &WgConfig) -> Result<()> {
354356
#[cfg(test)]
355357
mod tests {
356358
use super::*;
359+
use rocket::figment::providers::{Format, Toml};
357360
use std::str::FromStr;
358361

362+
#[test]
363+
fn admin_auth_token_reads_new_and_legacy_keys() {
364+
// new key
365+
let cfg: AdminConfig =
366+
Figment::from(Toml::string("enabled = true\nauth_token = \"new\"\n"))
367+
.extract()
368+
.unwrap();
369+
assert_eq!(cfg.auth_token, "new");
370+
// legacy `admin_token` key still deserializes via the serde alias
371+
let cfg: AdminConfig =
372+
Figment::from(Toml::string("enabled = true\nadmin_token = \"legacy\"\n"))
373+
.extract()
374+
.unwrap();
375+
assert_eq!(cfg.auth_token, "legacy");
376+
}
377+
359378
#[test]
360379
fn test_validate() {
361380
// Valid configuration

dstack/gateway/test-run/e2e/configs/gateway-1.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rpc_domain = "gateway-1"
1919
enabled = true
2020
port = 9016
2121
address = "0.0.0.0"
22-
admin_token = "e2e-admin-token"
22+
auth_token = "e2e-admin-token"
2323

2424
[core.debug]
2525
insecure_enable_debug_rpc = true

dstack/gateway/test-run/e2e/configs/gateway-2.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rpc_domain = "gateway-2"
1919
enabled = true
2020
port = 9016
2121
address = "0.0.0.0"
22-
admin_token = "e2e-admin-token"
22+
auth_token = "e2e-admin-token"
2323

2424
[core.debug]
2525
insecure_enable_debug_rpc = true

dstack/gateway/test-run/e2e/configs/gateway-3.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rpc_domain = "gateway-3"
1919
enabled = true
2020
port = 9016
2121
address = "0.0.0.0"
22-
admin_token = "e2e-admin-token"
22+
auth_token = "e2e-admin-token"
2323

2424
[core.debug]
2525
insecure_enable_debug_rpc = true

dstack/gateway/test-run/e2e/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ GATEWAY_PROXIES="gateway-1:9014 gateway-2:9014 gateway-3:9014"
2222
GATEWAY_DEBUG_URLS="http://gateway-1:9015 http://gateway-2:9015 http://gateway-3:9015"
2323
GATEWAY_ADMIN="http://gateway-1:9016"
2424

25-
# Must match `admin_token` in configs/gateway-*.toml
25+
# Must match `auth_token` in configs/gateway-*.toml
2626
ADMIN_TOKEN="e2e-admin-token"
2727
ADMIN_AUTH_HEADER="Authorization: Bearer ${ADMIN_TOKEN}"
2828

0 commit comments

Comments
 (0)