Skip to content

Commit 07989a0

Browse files
committed
fix(gateway): always restart hot mode on security-critical auth/secret config edits
Hot reload mode (gateway.reload.mode: "hot") kept the shipped warn-and-keep contract even when gateway.auth.*, auth.profiles.*/auth.order.*, or secrets.providers.* changed on disk, so a credential rotated in response to a leak stayed accepted by the running gateway until a manual restart. Hot mode now schedules a supervised restart for those security-critical prefixes while routine restart-required edits keep warn-and-keep; blanket auto-restart stays the hybrid mode's job. The decision is shared between the file watcher and the config.patch/config.apply RPC write path via resolveHotModeRestartDecision, so routine restart-required RPC writes in hot mode now return a requiresRestart notice instead of direct-restarting. secrets.providers.* is now classified restart-required in the reload planner so provider SecretRef rotations reach the carve-out.
1 parent 38df399 commit 07989a0

10 files changed

Lines changed: 377 additions & 29 deletions

‎docs/gateway/configuration-reference.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ See [Multiple Gateways](/gateway/multiple-gateways).
756756
- `mode`: controls how config edits are applied at runtime.
757757
- `"off"`: ignore live edits; changes require an explicit restart.
758758
- `"restart"`: always restart the gateway process on config change.
759-
- `"hot"`: apply changes in-process without restarting.
759+
- `"hot"`: apply hot-safe changes in-process and warn (without restarting) when a routine restart-required change lands. Security-critical changes (`gateway.auth.*` for the gateway access boundary, `auth.profiles.*`/`auth.order.*` for model-auth profile routing) always auto-restart so those changes cannot be silently deferred. Provider secret rotations under `secrets.providers.*` stay on the live path and apply without a restart. The same policy applies to file edits and to `config.patch`/`config.apply` writes over the gateway API. If you want automatic restart for all restart-required changes, use `"hybrid"`.
760760
- `"hybrid"` (default): try hot reload first; fall back to restart if required.
761761
- `debounceMs`: debounce window in ms before config changes are applied (non-negative integer; default: `300`).
762762
- `deferralTimeoutMs`: optional maximum time in ms to wait for in-flight operations before forcing a restart or channel hot reload. Omit it to use the default bounded wait (`300000`); set `0` to wait indefinitely and log periodic still-pending warnings.

‎docs/gateway/configuration.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,12 @@ for the checklist.
518518

519519
### Reload modes
520520

521-
| Mode | Behavior |
522-
| ---------------------- | --------------------------------------------------------------------------------------- |
523-
| **`hybrid`** (default) | Hot-applies safe changes instantly. Automatically restarts for critical ones. |
524-
| **`hot`** | Hot-applies safe changes only. Logs a warning when a restart is needed - you handle it. |
525-
| **`restart`** | Restarts the Gateway on any config change, safe or not. |
526-
| **`off`** | Disables file watching. Changes take effect on the next manual restart. |
521+
| Mode | Behavior |
522+
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
523+
| **`hybrid`** (default) | Hot-applies safe changes instantly. Automatically restarts for critical ones. |
524+
| **`hot`** | Hot-applies safe changes only. Logs a warning when a restart is needed; you handle it. Security-critical changes (`gateway.auth.*`, `auth.profiles.*`/`auth.order.*`) still auto-restart; `secrets.providers.*` rotations keep applying live. |
525+
| **`restart`** | Restarts the Gateway on any config change, safe or not. |
526+
| **`off`** | Disables file watching. Changes take effect on the next manual restart. |
527527

528528
```json5
529529
{

‎docs/gateway/index.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ Gateway startup uses the same effective port and bind when it seeds local Contro
110110

111111
### Hot reload modes
112112

113-
| `gateway.reload.mode` | Behavior |
114-
| --------------------- | ------------------------------------------ |
115-
| `off` | No config reload |
116-
| `hot` | Apply only hot-safe changes |
117-
| `restart` | Restart on reload-required changes |
118-
| `hybrid` (default) | Hot-apply when safe, restart when required |
113+
| `gateway.reload.mode` | Behavior |
114+
| --------------------- | ----------------------------------------------------------------------------------------------------------- |
115+
| `off` | No config reload |
116+
| `hot` | Hot-apply safe changes; warn on restart-required (security-critical auth changes still auto-restart; provider secret rotations apply live) |
117+
| `restart` | Restart on reload-required changes |
118+
| `hybrid` (default) | Hot-apply when safe, restart when required |
119119

120120
## Operator command set
121121

‎src/config/schema.help.runtime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export const RUNTIME_FIELD_HELP: Record<string, string> = {
245245
"gateway.http.endpoints.chatCompletions.images.timeoutMs":
246246
"Timeout in milliseconds for `image_url` URL fetches (default: 10000).",
247247
"gateway.reload.mode":
248-
'Controls how config edits are applied: "off" ignores live edits, "restart" always restarts, "hot" applies in-process, and "hybrid" tries hot then restarts if required. Keep "hybrid" for safest routine updates.',
248+
'Controls how config edits are applied: "off" ignores live edits, "restart" always restarts, "hot" applies hot-safe changes in-process and warns when a routine restart-required change lands (security-critical changes under gateway.auth.* and auth.profiles.*/auth.order.* always auto-restart), and "hybrid" tries hot then restarts if required. Keep "hybrid" for safest routine updates.',
249249
"gateway.nodes.browser.mode":
250250
'Node browser routing ("auto" = pick single connected browser node, "manual" = require node param, "off" = disable).',
251251
"gateway.nodes.browser.node": "Pin browser routing to a specific node id or name (optional).",

‎src/gateway/config-reload-plan.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ const BASE_RELOAD_RULES_TAIL: ReloadRule[] = [
134134
{ prefix: "session", kind: "none" },
135135
{ prefix: "talk", kind: "none" },
136136
{ prefix: "skills", kind: "none" },
137+
// `secrets.*` (including provider SecretRef storage) stays no-op: rotated
138+
// values activate through the committed snapshot's live SecretRef
139+
// resolution, so credential rotation must never force a gateway bounce.
140+
// ClawSweeper P1 #89517 review contract.
137141
{ prefix: "secrets", kind: "none" },
138142
{ prefix: "plugins", kind: "hot", actions: ["reload-plugins", "dispose-mcp-runtimes"] },
139143
{ prefix: "tui", kind: "none" },

‎src/gateway/config-reload-settings.ts‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,60 @@
11
// Gateway reload settings resolver.
2-
// Normalizes reload mode and debounce config for watcher/reload handlers.
2+
// Normalizes reload mode and debounce config for watcher/reload handlers, and
3+
// owns the shared hot-mode restart policy for restart-required config changes.
34
import type { GatewayReloadMode } from "../config/types.gateway.js";
45
import type { OpenClawConfig } from "../config/types.openclaw.js";
56

7+
/**
8+
* Path prefixes whose restart-required edits must never be deferred by the
9+
* hot-mode warn-and-keep contract. A live runtime that keeps the old token
10+
* after `gateway.auth.token` rotates is a credential-rotation-bypass risk:
11+
* the operator rotates on disk to respond to a leak, but the gateway
12+
* continues to accept the compromised token until manual restart.
13+
*
14+
* - `gateway.auth.*` covers the gateway access boundary itself (token,
15+
* password, trusted-proxy headers).
16+
* - `auth.profiles.*` / `auth.order.*` cover model-auth profile routing at
17+
* the config root. Doctor batch repairs rename stale profiles (for example
18+
* `auth.profiles.openai-codex:*` -> `auth.profiles.openai:*`) alongside
19+
* model routes; deferring the rename leaves the runtime authenticating
20+
* through profiles that no longer exist on disk.
21+
* - `secrets.*` is deliberately excluded: provider SecretRef rotation is a
22+
* supported live operation (the committed snapshot resolves the rotated
23+
* ref without a restart), so escalating it here would replace live
24+
* credential rotation with an avoidable gateway bounce (ClawSweeper P1
25+
* #89517).
26+
*
27+
* The set is intentionally conservative; non-auth restart-required reasons
28+
* keep the shipped warn-and-keep contract. Operators who want blanket
29+
* auto-restart for restart-required edits use `gateway.reload.mode: "hybrid"`.
30+
*/
31+
// `secrets.*` is deliberately absent: provider secret rotation applies live
32+
// through snapshot SecretRef resolution and must not trigger a restart.
33+
const SECURITY_CRITICAL_RESTART_PREFIXES = ["gateway.auth", "auth.profiles", "auth.order"] as const;
34+
35+
function isSecurityCriticalRestartReason(reason: string): boolean {
36+
return SECURITY_CRITICAL_RESTART_PREFIXES.some(
37+
(prefix) => reason === prefix || reason.startsWith(`${prefix}.`),
38+
);
39+
}
40+
41+
type HotModeRestartDecision = "security-critical" | "warn-and-keep";
42+
43+
/**
44+
* Shared hot-mode policy for restart-required config changes. The file
45+
* watcher (config-reload.ts) and the config.patch/config.apply RPC write path
46+
* (server-methods/config-write-flow.ts) both route through this decision so
47+
* the two write surfaces cannot diverge on when hot mode escalates a
48+
* restart-required change into an actual restart.
49+
*/
50+
export function resolveHotModeRestartDecision(
51+
restartReasons: readonly string[],
52+
): HotModeRestartDecision {
53+
return restartReasons.some(isSecurityCriticalRestartReason)
54+
? "security-critical"
55+
: "warn-and-keep";
56+
}
57+
658
type GatewayReloadSettings = {
759
mode: GatewayReloadMode;
860
debounceMs: number;

0 commit comments

Comments
 (0)