Commit a72085b
authored
feat(login, helm): re-register on machine-id change and refresh session token (#1255)
## Problem
gpud persists its login identity — **machine id**, **session token**,
endpoint — in `/var/lib/gpud`, a node-scoped `hostPath` that survives
reboots. In the container/DaemonSet pattern that cache can outlive what
it describes, and gpud's "skip login if a machine id is already
persisted" fast path then runs the node on **stale** state:
1. **Stale machine id** — a node deleted from its node group and
rejoined binds a **NEW machine object** (new `machine-id` label) while
the OLD id is still on disk → gpud either silently skips login on the
stale id (runs under a mismatched identity, never joins) or fails with a
terse mismatch error.
2. **Stale session token** — the persisted session token can be
invalidated server-side (gpud-manager resets the BYOK session on every
login; the workspace session SAK can rotate) → skip-login reuses a dead
token → keepalive breaks.
This PR adds two opt-in flags (both **default `false`** in gpud for
backward-compatibility, both **default `true`** in the chart, matching
how the chart already enables container-pattern behaviors like
`rebootCommands`/`findmntCommands`). They wire into the **same**
skip/refresh fork in `login.Login`.
## 1. `--machine-id-overwrite`
When a supplied `--machine-id` differs from the persisted one:
- **false (default)** → reject with an actionable error (safe for
host/systemd).
- **true** → discard the persisted login identity (machine id + session
token, **metadata table only**) and re-register as the new machine.
Reboot/event history is **preserved**.
Unified in `login.reconcileMachineID`, which runs *before* the
skip/refresh fork so behavior is consistent whether or not node labels
changed. The now-redundant deeper guard (`stored machine ID … does not
match`) is removed (unreachable). The `--machine-id` flag docs now
describe this.
## 2. `--refresh-session-token`
When set, gpud **always re-logins on start** even with a persisted
machine id, instead of reusing the cached session token. The control
plane re-issues the (workspace-scoped) session token on every successful
login, so re-login reliably re-fetches a current one. Costs one extra
login round-trip per start; keeps the cached token from going stale.
> Verified against gpud-manager: `server/handler_login.go` returns
`sessionToken` on every success
(`loginExistingMachine`/`loginNewMachine`), sourced from the workspace
Secret via `tokenReader.GetToken(WorkspaceID, TokenPermissionSession)` —
and `clearStaleSessionIfBYOK` resets the BYOK session on every login, so
the server *expects* re-login.
A `TODO` is noted on both flags: once validated in production, make
always-refresh the default and retire the toggle.
## Helm
`gpud.machineIdOverwrite` (default `true`) and
`gpud.refreshSessionToken` (default `true`) →
`GPUD_MACHINE_ID_OVERWRITE` / `GPUD_REFRESH_SESSION_TOKEN` env → the
startup wrapper appends `--machine-id-overwrite` /
`--refresh-session-token`. Set either to `false` to restore the
strict/skip-login behavior.
## Backward compatibility
**Strict invariant preserved**: with both flags unset (`false`) and no
`--machine-id` supplied — i.e. every existing host/systemd install —
behavior is byte-for-byte identical. `reconcileMachineID` is a no-op
when there's no persisted id, no supplied id, or they match; and without
`--refresh-session-token` the skip-login fast path is unchanged.
## Testing
- `pkg/login/login_test.go` — `TestReconcileMachineID` (no-persisted /
empty-requested / match / mismatch-fail / mismatch-overwrite).
- `pkg/login/mock_login_test.go` — full `Login` flow:
`…MismatchedOverrideFails` (updated to the new error),
`TestLogin_MachineIDOverwriteReRegisters`, and
`TestLogin_RefreshSessionTokenRelogsIn` (forces relogin + re-persists
the token when a machine id is already assigned and labels are
unchanged; contrast with `TestLogin_MachineIDAlreadyAssigned`, which
skips).
- `go build ./...`, `go vet`, `go test -gcflags="all=-N -l"
./pkg/login/` all green.
- `helm lint` + render verified for both flags: default → env + flag
present; `--set …=false` → both omitted.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Signed-off-by: Gyuho Lee <gyuhol@nvidia.com>1 parent 4e754b1 commit a72085b
14 files changed
Lines changed: 844 additions & 143 deletions
File tree
- cmd/gpud
- command
- run
- up
- deployments/helm/gpud
- templates
- pkg/login
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
102 | 114 | | |
103 | 115 | | |
104 | 116 | | |
| |||
166 | 178 | | |
167 | 179 | | |
168 | 180 | | |
169 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
170 | 194 | | |
171 | 195 | | |
172 | 196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| |||
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
99 | 104 | | |
100 | 105 | | |
101 | 106 | | |
| |||
104 | 109 | | |
105 | 110 | | |
106 | 111 | | |
| 112 | + | |
107 | 113 | | |
108 | 114 | | |
109 | 115 | | |
| |||
375 | 381 | | |
376 | 382 | | |
377 | 383 | | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
| 384 | + | |
| 385 | + | |
406 | 386 | | |
407 | 387 | | |
408 | 388 | | |
| |||
456 | 436 | | |
457 | 437 | | |
458 | 438 | | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
459 | 499 | | |
460 | 500 | | |
461 | 501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
128 | 131 | | |
129 | 132 | | |
130 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
0 commit comments