self-hosted activation: kanidm auth 500s (account lockout) after a second mid-founding switch-to-configuration bounces kanidm.service again #636
Labels
No labels
agent-blocked
agent-working
autopilot
bug
deferred
deploy-pending
enhancement
landing-pr
model-haiku
model-opus
model-sonnet
needs-design
needs-info
needs-triage
no-triage
out-of-scope
priority
ready-for-agent
ready-for-human
ready-for-session
rehearsal-183
snapshot-pending
standing-drive
wayfinder:grilling
wayfinder:map
wayfinder:prototype
wayfinder:research
wayfinder:task
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Blocks
Reference
Matou/idss#636
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Failure
Red leg
activation:activation faulted: founding: mint the credential-enrolment token at seeding: fleetwire: mint the credential-enrolment token: kanidm: auth cred: unexpected status 500(run20260821T070234Z, signature4c82deb1e678).This is a NEW variant of the #635 race (
STATUS.md:17-35, fixed ina9e72feb): #635 taughtfleetwire.Enrolment.MintToken(internal/fleetwire/enrolment.go:169-203) to retry a clean kanidm denial (kanidm.ErrAuthDenied,internal/kanidm/auth.go:26) up to 30x/2s while kanidm settles after founding's authority flip. That retry loop IS firing here and IS the correct code — but this drive shows the settle window can contain a second kanidm bounce, and the loop's denials curdle into an unhandled 500 partway through.Evidence (droplet-journal.txt)
kanidmd[1059]starts 07:07:51,handle_admin_recover_accountforidm_admin+admin(lines ~563-568), later logs in fine.switch-to-configuration switchruns at 07:10:10-11 from a different nix store path (.../rfzw9wgalykkz7v7xb04jl03zdmwv1dr-nixos-system-gateway-...vs the first switch's.../8sz0lzi5z39i5yn7ya48xi3inqd4836h-..., lines 1441-1471 and 1465). This stopskanidm.service("Stopped kanidm identity management daemon", line 1471-1473) and restarts it askanidmd[5046]at 07:10:12.kanidmd[5046]re-runshandle_admin_recover_accountforidm_adminandadminat 07:10:13 (lines 1550-1556) — a FRESH, different generated secret — and the on-box provisioning process itself logs in successfully with it immediately after (lines 1557-1568, "Auth result: Success(Token)").founding.seed.go'sMintTokencall (internal/founding/seed.go:274-282, right afterflipRepoAuthority) is meanwhile retrying againstkanidmd[5046]and gets three straightincorrect passworddenials at 07:10:21, 07:10:24, 07:10:26 (lines 1826-1936) — i.e., the secretfleetwire.Enrolment.liveIDPreads over SSH from/etc/idss/kanidm-idm-admin-path(internal/fleetwire/enrolment.go:140-141, re-read fresh on every retry attempt) is NOT the secretkanidmd[5046]actually holds, even several seconds after the on-box process itself proved that fresh secret works.Auth result: Denied: Account is temporarily lockedon the Begin step (line 1973), then the Cred step submitted right after is answeredstatus_code: 500/Auth result: AU0001InvalidState(lines 1974-1977) — kanidm 500s because the auth session was already terminated by the lockout.Contributing code gap (this checkout)
internal/kanidm/auth.go:65-67(authenticate's Begin step) discards the response state (nilpassed toauthStep), so a denial surfaced at Begin ("Account is temporarily locked") is never detected before blindly submitting Cred — producing the unhandled 500 instead of a cleanErrAuthDenied.authSteponly maps a non-200 status to a barefmt.Errorf("unexpected status %d", ...)(auth.go:97-99), neverErrAuthDenied, soMintToken's retry guard (enrolment.go:188-190) doesn't retry it and faults the leg immediately.Why this isn't a safe self-fix
Making the Begin-step lockout detectable (return
ErrAuthDeniedthere too) would only reword the failure, not fix it: the deeper problem is the app's secret read is persistently wrong againstkanidmd[5046]'s freshly-recovered credential for multiple retries running (not a one-tick staleness), which is what drives it into lockout in the first place. That points at a real desync between whatever writes/serves/etc/idss/kanidm-idm-admin-pathand the SECOND, unexpected mid-foundingswitch-to-configuration— nix/clan-config territory not present in this checkout (only unrelatedspikes/*/clan/...nix files referencekanidm-admins/idmAdminPasswordFile; the real gateway module lives outside this repo). Also worth asking: why does founding trigger two separateswitch-to-configurationruns (07:09:27 and 07:10:10-11, different store paths) that each bouncekanidm.serviceand re-run account recovery — #635 assumed one settle window after one bounce.What plugging it needs
/etc/idss/kanidm-idm-admin-path's content across the second switch vs. the secretkanidmd[5046]'shandle_admin_recover_accountactually committed, to confirm the exact desync (stale pointer, generation lag, or a second recovery overwriting what the first provisioning step already committed).MintTokenuntil AFTER the last one, not just retry through it) — likely aseed.go/orchestrator sequencing question, not afleetwireretry-tuning one.internal/kanidm/auth.go's Begin-step state should probably still be checked so a lockout denial reads asErrAuthDeniedrather than a raw 500 — a small, independently testable hardening, but not sufficient alone.drive
20260821T070234Zred atactivation:activation faulted: founding: mint the credential-enrolment token at seeding: fleetwire: mint the credential-enrolment token: kanidm: auth cred: unexpected status 500evidence:
test-results/…/20260821T070234Z/on matou-workstation (legs.json, droplet-journal.txt, trace) — a representative screenshot is attached here if one was captured (#596)Ruled by agent under ADR 0174 — veto anytime.
Ruling: fix the contributing code gap and land it now; the deeper root cause is out of scope for a two-way door and gets routed separately below. This is a two-way door — a code change to
internal/kanidm/auth.go, revertible by commit, no credential/posture/trust-surface change.What I found: the retry loop
MintTokengrew in #635 IS the correct code and IS firing here — but this drive shows the settle window can contain a second kanidm bounce (a distinctswitch-to-configuration switchfrom a different nix store path, ~40s after the first, per the droplet journal). Three denials against the stale secret before the retry loop catches up trip kanidm's own soft account-lockout. The 4th attempt's Begin step getsDenied: Account is temporarily locked, butkanidm.Adapter.authenticate(internal/kanidm/auth.go) discarded the Begin step's response state (passednil), so the denial went unnoticed and the code blindly submitted Cred anyway — kanidm answers that with a barestatus_code: 500/AU0001InvalidState(the auth session was already terminated by the lockout), whichauthSteponly ever mapped to a genericfmt.Errorf("unexpected status %d", ...), neverErrAuthDenied— soMintToken's retry guard didn't retry it and faulted the leg hard.Fix:
authenticatenow passes a real*authStateto the Begin step and checks a newauthState.Deniedfield; a Begin-step denial returns the typedkanidm.ErrAuthDeniedimmediately, before ever submitting Cred into an already-dead session.Proof:
TestAuth_LockedAccountDeniesAtBeginReturnsErrAuthDenied— a fake-kanidm double put into the lockout posture (Begin denies "Account is temporarily locked"; a Cred submitted anyway 500s, modelling the realAU0001InvalidStatebug) proves both that the typed sentinel comes back AND that Cred is never actually submitted (credCalls() == 0). Confirmed red first (reproduced the exactkanidm: auth cred: unexpected status 500fault string from the drive) before implementing.go build ./...,go test ./...(whole repo),go vet ./..., andgolangci-lint run ./internal/kanidm/...all clean.One correction to the ticket's analysis: it states "the real gateway module lives outside this repo." That's not quite right —
/etc/idss/kanidm-idm-admin-pathand thekanidm-admins/kanidm-tlsclan-var generators ARE rendered in this repo (internal/clan/vmguest.go:gatewaySecretPointers,kanidmGenerators,renderControlPlaneSurface, shared by both the VM and own-VPS/full-install gateway shapes). What genuinely IS outside this repo is the SECONDswitch-to-configurationinvocation itself and kanidm's own provisioning-package internals (kanidmWithSecretProvisioning_1_10, from nixpkgs) — externalclan/nixos-rebuild tooling behavior, not Go code here.Landed:
ddbc3d13onmain— "sandcastle: #636 — kanidm auth: a Begin-step account lockout blindly submitted Cred into a dead session, 500ing instead of denying".STATUS.mdupdated in the same commit.This closes the contributing code gap the ticket named (item 3 of "What plugging it needs"), but NOT the ticket as a whole — items 1 and 2 are still open and are exactly why the ticket itself already argued this isn't a safe full self-fix. Relabelling
ready-for-humanrather than closing.Why human
Not a pure "Ben's hands" case, but the two open items both need a judgement call only Ben is positioned to make right now:
/etc/idss/kanidm-idm-admin-path's content across the second switch vs. whatkanidmd'shandle_admin_recover_accountactually committed — needed to confirm whether the app's secret read is genuinely stale (a real desync) or just a timing window the now-fixed retry rides out. This is real droplet time/spend on a narrow, possibly self-resolving race, not a quick check.switch-to-configurationruns and, if so, deferMintTokenuntil after the last one — aseed.go/orchestrator sequencing decision that depends on (1)'s answer, and on understanding the externalclan/nixos-rebuild tooling's own two-switch behavior (not this repo's code).Proposed default ruling: ship this hardening and watch it on the next self-hosted rehearsal that reaches seeding/activation. If it still faults at this leg (or a live drive shows the lockout still tripping), that's the trigger to spend a dedicated live-forensic session on (1)/(2); if it doesn't, the settle-retry-through-a-lockout behavior this change adds was sufficient and (1)/(2) can be closed as moot.
Ruled by agent under ADR 0174 — veto anytime.
Diagnosis — the two builds are BY DESIGN; the fault is the admin secret rotating between them
Traced against
test-results/drive-selfhosted/20260821T070234Z/logs/droplet-journal.txton matou-workstation. Answering "why does the box build twice": it is supposed to. The self-hosted full-install path issues two distinct, intended remote applies after the takeover reboot, and they are genuinely different closures (different nix store paths), not a repeated one:composeSelfHostedGateway→clan.Enrollverify stage. Store path8sz0lzi5…,switch-to-configuration switchat 07:09:27. Switches the freshly-installed box into its configured gateway state. (kanidm first comes up at boot,kanidmd[1059]07:07:50.)applyControlPlane→o.clan.Deploy(…, RestartChanged: true)(internal/founding/deploy.go:387,569). Store pathrfzw9wgal…,switch-to-configuration switchat 07:10:10. BecauseRestartChangedis set, this switch stops and restarts kanidm (kanidmd[1059]→kanidmd[5046], 07:10:11-12).Both applies are legitimate. Building twice is not the bug.
The real fault: idm_admin is provisioned with a DIFFERENT password across the two applies
kanidm's secret-provisioning (
kanidmWithSecretProvisioning,idmAdminPasswordFile→ thekanidm-admins.files.idm_adminclan var,vmguest.go:277) runshandle_admin_recover_accounton each kanidm start — boot (kanidmd[1059], 07:07:51) and the post-second-apply restart (kanidmd[5046], 07:10:13). Both times the on-box provisioning process immediatelyAuth result: Success(Token)— so kanidm always holds whatever the file gave it at that instant.But the two runs did not converge on the same secret. After the second provision,
MintToken's SSH read of$(cat /etc/idss/kanidm-idm-admin-path)(internal/fleetwire/enrolment.go:140) authenticates and is denied three times (Auth result: Denied: incorrect password, 07:10:21 / :24 / :26), which trips kanidm's soft lockout on the 4th (Denied: Account is temporarily locked, 07:10:29) and the Begin-step then 500s (AU0001InvalidState). So at mint time kanidm[5046] honours password B while the path the app reads yields password A.This confirms the ticket's hypothesis and narrows it: it is not a stale pointer — the credential itself rotated across the restart, and the app's read did not track it. #635's retry loop is correct but cannot win: it re-reads the same stale path every attempt, so it burns straight into the lockout.
Still to pin on a live box (ticket item 1), now with a specific target: which mechanism rotates
kanidm-admins/idm_adminbetween 07:07 and 07:10. The enrollment'svars generateis guarded to run once (enrollment.go:546,598—VarsGenerated), so the rotation is NOT a second enrollment generate. Candidates to check on the box: (a) avars generatere-run outside that guard (crown-jewels placement / repo re-clone inseed.gotouching theopenssl randgenerator —vmguest.go:248, the "regenerating rotates BOTH" hazard, GOTCHAS #5); (b) a sops-nix re-materialisation on the secondswitchhanding kanidm-provision a different generation of/run/secrets/vars/kanidm-admins/idm_adminthan the app's latercatreads. Confirm by diffing the file's content and its sops generation across the twoswitch-to-configurationruns while the box is live.Recommendation: stop the rotation (don't tune the retry)
The clean fix is to make the idm_admin credential stable and idempotent across both applies, so the second kanidm restart re-provisions the same secret and the app's read can never disagree. That removes the failure at its source and leaves #635's retry as pure belt-and-braces. Concretely, once item 1 names the rotation source: pin
kanidm-admins/idm_adminso a re-materialisation or a re-run of the generator is a no-op (the secret is written once and never rotated by a later apply on the same founding), rather than deferring/retryingMintTokenaround a moving value. Sequencing the mint after the last apply (item 2) is a weaker fallback — it narrows the window but still trusts that the app reads exactly the generation kanidm holds, which is the thing that just failed.ddbc3d1(the Begin-step lockout → clean-denial hardening) stays as correct defence-in-depth: even with a stable secret it keeps a transient lockout from surfacing as a raw 500. It is necessary but not sufficient; the rotation is the root cause.Tasked to a session — Ben's ruling: STOP THE ROTATION
Ben has ruled the fix direction (see the diagnosis comment above): make
kanidm-admins/idm_adminstable and idempotent across both applies so the second apply's kanidm restart re-provisions the same secret. Do not fix this by tuningMintToken's retry/sequencing — that only narrows the window around a moving value.Step 1 — name the rotation source (live). The confirmed fault is that kanidm holds a different idm_admin password after the second apply than the app reads from
/etc/idss/kanidm-idm-admin-path. The enrollment'svars generateis guarded once (internal/clan/enrollment.go:546,598), so the rotation is NOT a second enrollment generate. Use theclan-labskill to stand up a real droplet and drive far enough to reproduce, OR reproduce the two-apply sequence against a lab box, and determine which mechanism rotates the secret between the twoswitch-to-configurationruns:vars generatere-run OUTSIDE the enrollment guard — e.g. crown-jewels placement / repo re-clone ininternal/founding/seed.gotouching theopenssl randkanidm-admins generator (internal/clan/vmguest.go:248; "regenerating rotates BOTH", GOTCHAS #5); orswitchhanding kanidm-provision a different generation of/run/secrets/vars/kanidm-admins/idm_adminthan the app's latercatreads.Confirm by diffing the file's byte content and its sops generation across the two switches while the box is live. Record the finding in the ticket.
Step 2 — stop the rotation. Based on (1): pin the idm_admin (and admin) secret so it is written once per founding and a later apply / re-materialisation is a no-op — never a fresh
openssl rand. If the source is (a), the generator must not re-run for an already-generated node on this path; if (b), the two applies must resolve the same sops generation. Add coverage: a seam/unit test that a second apply on an already-seeded self-hosted gateway re-provisions the SAME idm_admin (asserting the app's read == what kanidm honours), and keepinternal/kanidm/auth.go'sddbc3d1lockout→clean-denial hardening (necessary defence-in-depth, not the fix).Proof:
go build/vet/test ./...green; the real proof is the next unattended selfhosted drive reachingactivationwithout the kanidm 500 — closing this unblocks #523's own next tick (same precedent as #626→#635). If step 1 turns out to need a design ruling rather than a code change (e.g. the two applies genuinely must run and can't share a generation without resequencing founding), route it backready-for-humanwith the live evidence rather than guessing.Two-way door under ADR 0174 for the code change; the direction (stop the rotation) is Ben's explicit ruling.
Live-droplet step-1 investigation (ADR 0174, ruled by agent — veto anytime)
Ben tasked this session with step 1 ("name the rotation source, live"). I stood up a real
clan-labdroplet (.claude/skills/clan-lab, clan-coredb4db726) to test the two candidate mechanisms directly, plus read the pinned clan-cli source shipped on the lab host. Result: neither of the two named candidates is quite right — I found a third, more specific mechanism, but could not get full byte-level confirmation because this generic lab never runs the actual disko/nixos-anywhere full-install path. Posting what's proven vs. what's still open so the next session doesn't re-derive this.Ruled out
kanidmGenerators()(internal/clan/vmguest.go:183) is a zero-argument function returning a fixed constant string — its Nix declaration text is byte-identical on every call, regardless ofGatewayFacts. Sinceclan.core.vars.generators.kanidm-admins's declaration can never differ between the two applies, a generator-content-hash change cannot be what triggers a reseal. This rules out candidate (a) as stated in Ben's comment.vars generatetwice rotates it." On the lab (node1, a persistent VM with the exactkanidm-adminsgenerator block copied verbatim fromvmguest.go), a second plainclan vars generate node1 --flake . --no-sandbox— no--regenerate, no changed generator, no changed answers — is a confirmed no-op:git hash-objectonvars/per-machine/node1/kanidm-admins/idm_admin/secretis identical before and after, and clan emits no new commit. So repeated plain generation alone does not explain the rotation.nixos/modules/services/security/kanidm.nix:158-176, rev173d0ad7a974, present on the lab host at/nix/store/lk1qxln8g3r9yh1bnkzfj2daml9iv8gv-.../kanidm.nix):maybeRecoverAdmindoesKANIDM_IDM_ADMIN_PASSWORD=$(< ${cfg.provision.idmAdminPasswordFile})thenkanidmd recover-account ... --from-environment. This is fully deterministic on whatever bytes are in the password FILE at the moment the oneshot runs — it does not itself generate randomness. So the two different passwords kanidm ends up holding must come from two different file contents, not from kanidm's own logic.New, more specific candidate (not fully confirmed)
Reading the pinned clan-cli source (
clan_lib/machines/install.py:93-124, same droplet):clan machines install(nixos-anywhere) does NOT rely on the target machine decrypting sops at first boot. It:run_generators([machine], ...)itself (a second, independent generate call beyond IDSS's ownenrollment.go:702one),machine.secret_vars_store.populate_dir(all_generators, machine.name, upload_dir, phases=["activation","users","services"])— this DECRYPTS the generator's files into a local temp dir,nixos-anywhere --extra-files <dir>, which copies the DECRYPTED plaintext directly onto the fresh disk at/var/lib/sops-nix/...during install, before first boot.kanidm-admins's files declare no explicitneededFor, and the clan-cli test fixtures show the default is"services"(clan_lib/vars/generator_test.py:19,27,44) — i.e. inside the["activation","users","services"]phase setpopulate_dirpre-delivers. So the FIRST kanidm start (07:07:51 on the real drive,kanidmd[1059]) is very likely reading a plaintext file placed directly by nixos-anywhere's install-time--extra-filesstep, not one decrypted from the git-committed ciphertext via a live sops-nix activation script.EVERY subsequent
clan machines update(the 2nd apply,applyControlPlane→internal/clan/adapter.go'supdateNode) is an ordinarynixos-rebuild switch-shaped deploy: it has no--extra-filesstep, so/run/secrets/vars/kanidm-admins/idm_adminon THAT switch is materialized by the machine's own sops-nix activation script, decrypting the git-committed ciphertext fresh, using the machine's on-disk key (itself delivered via the SAME install-time--extra-filesmechanism, phase"activation").The two applies use two structurally different code paths to materialize the same nominal secret (nixos-anywhere's own pre-install
run_generators+populate_dirsnapshot vs. sops-nix's own runtime decrypt-from-git-ciphertext). If those two paths ever observe a different generate/commit state — even without any explicit--regenerate— they will legitimately disagree, with no "rotation event" required at all. That would cleanly explain the drive's evidence (the box's OWN provisioning process succeeds against the post-2nd-apply value; the app's separately-read/etc/idss/kanidm-idm-admin-pathis stuck on the pre-2nd-apply value).What's still open (why I'm not shipping a fix yet)
I could not get the last byte-level link Ben asked for: confirming these two materialization paths actually diverge in IDSS's real full-install sequence, because
clan-lab's golden image is a generic clan template with 3 already-installed, persistent VMs — it never runsclan machines install/nixos-anywhere/disko at all, so I can't directly diff nixos-anywhere's pre-delivered--extra-filessnapshot against the git-committed ciphertext at the moment of the 2nd apply without a genuine blank-target full-install lab (a materially bigger lab task: a blank Ubuntu VM as takeover target, wired through something equivalent tocomposeSelfHostedGateway, with journal +/var/lib/sops-nix+vars/per-machine/.../secretcaptured at both switches).Given Ben's ruling — "Do not fix this by tuning MintToken's retry/sequencing" and, by the same logic, don't guess at a vars-sequencing fix either without the byte proof — I'm not attempting step 2 (pin the secret) on this evidence alone: the fix has to land at whichever of the two materialization paths is actually stale, and I can't yet tell you which one that is with certainty.
Next step, concretely: a full-install
clan-labvariant (blank target VM, driveclan machines installfor real) that captures, at both switches: (1)/var/lib/sops-nix/...on disk, (2)vars/per-machine/<node>/kanidm-admins/idm_admin/secret's git blob hash in the config repo at the exact revision each apply used, (3) what/etc/idss/kanidm-idm-admin-pathholds. That's the experiment that turns this from "very plausible" into "proven."Lab used and destroyed (
clan-lab-rotation-test-bed9e41d, ~15 min, well within routine lab-droplet spend). No code changes this session —ddbc3d13's hardening stands as the only landed change.Leaving
ready-for-session: this is a live-investigation budget gap, not a human judgement call, soready-for-humanwould misroute it — the next session should pick up at the full-install lab experiment above rather than re-deriving the ruled-out hypotheses.This session: no live experiment attempted — a structural blocker + a tighter next-step recipe
Picked this up as the next
ready-for-sessioncontinuation of the live-investigation Ben tasked (comment above, 20:50:55Z) and the prior session's step-1 report (21:18:59Z). Landed no code — the hardening fromddbc3d13already stands as the only change on this ticket. Posting what I found so the next session (or Ben) doesn't re-derive it.New finding: the shared rehearsal machinery cannot be fired from inside a
ready-for-sessionsessionI considered just re-running the real standing drive (
#523,scripts/rehearsal-cycle.sh --target selfhosted) instead of building bespoke lab tooling — it already performs a genuinenixos-anywhere/disko full install (this IS what produced the20260821T070234Zevidence). Butrehearsal-cycle.sh'shost_capacity_acquire_exclusive(#577, ADR 0184) grabs/tmp/matou-session-runner.locknon-blockingly, and that lock is held by.sandcastle/session-runner.shfor this whole session's lifetime (confirmed empirically:flock -n /tmp/matou-session-runner.lock -c ...fails while this session is live). So the standing drive structurally cannot fire from inside a liveready-for-sessionsession — it would just print "host capacity busy" and no-op. Runningsmoke-private-path.sh --target selfhosteddirectly, bypassing that wrapper, would defeat a deliberate host-contention guard on a shared, memory-constrained box (MemAvailablewas ~4.4–4.5 GiB against the runbook's ~6–8 GiB floor this whole session, from steady-state load of unrelated long-running services on matou-workstation — not something that frees up by waiting) — I did not do that.This also means: even after
#636closes and#523unblocks, the executor cron can fire it fine (it runs outside any live session), but a human/agent wanting to hand-drive a selfhosted rehearsal for forensic purposes must not do it from aready-for-sessionsession — it needs either a dedicated host window, or (better, see below) a separate clan-lab droplet that never touches the shared locks at all.Narrowed the next experiment (smaller than the prior session's proposal)
The prior session's "next step" asked for a full bespoke clan-lab variant replicating the WHOLE IDSS gateway. That's more than is needed. To settle the leading hypothesis (nixos-anywhere's install-time
run_generators+populate_dirsnapshot vs. sops-nix's later runtime decrypt-from-git-ciphertext genuinely diverging with no explicit rotation event), the experiment only needs:clan.core.vars.generators.kanidm-admins(copied verbatim frominternal/clan/vmguest.go:232-249—kanidmGenerators(); it declares no explicitneededFor, so it defaults to clan's"services"phase, which is in nixos-anywhere's install-time pre-delivered set — confirmed by re-reading the prior session's citedclan_lib/machines/install.py:93-124phase list["activation","users","services"]).clan-lab create --fresh(not the golden 3-VM snapshot — its node1-3 are pre-baked qcow2 images, never installed vianixos-anywhere/disko at all, confirmed againstdocs/spike-findings/clan-lab-golden.md). This is the exact same droplet shapescripts/lib/rehearsal-droplet.sh'soc_droplet_createuses for the real drive, and — critically — it is its own separate DO droplet, so it never touches/tmp/matou-*.lockand is safe to run alongside a live session.clan machines install target --target-host root@<ip>, then plainclan machines update target --flake <dir> --host-key-check none— confirmed this is the EXACT invocation production code issues (internal/clan/adapter.go:322-327);RestartChangedadds no CLI flag at all, it only gates a separate explicit-restart step this repo defers to#163— so kanidm's stop/restart across the two applies is plain NixOSswitch-to-configuration's own changed-unit restart, nothing app-specific.sha256sum/content +readlink -fof/run/secrets/vars/kanidm-admins/idm_admin(and its sops generation, if the pinned nixpkgs kanidm module exposes one) right after each of the two applies. Same or different bytes settles it directly.clanCLI is already built and cached in the local nix store on matou-workstation (/nix/store/8wsdr1zjjlkd0m6d8xliw20nznh9nnay-clan-cli/bin/clan), so this experiment does not need clan-cli's from-source build time the golden-image notes priced at ~2.5 min.I did not attempt this myself this session: authoring a correct-enough minimal disko/hardware/networking baseline from scratch and driving two real applies carefully is a genuine (if now much narrower) build task, and I'd rather hand off a precise, de-risked recipe than rush it and burn real droplet spend without rigor.
Where this leaves the ticket
Leaving
ready-for-session— this is still an investigation-budget gap, not a one-way-door judgement call, per the prior session's reasoning (still holds). Flagging for whoever reads the digest: this is now the third agent session touching this ticket's root-cause hunt without landing the byte-level proof (session 1: hardening; session 2 was Ben's own diagnosis; session 3: step-1 lab investigation; this one: scoped the next experiment down further but didn't run it). If the runner's own attempt-counter escalates this toready-for-humanautomatically, that's the right call at this point — the remaining ask is a genuine "spend the time to build and run the narrow experiment above" task, which a session with fuller host/time budget than this tick had should be able to close out directly.Ruled by agent under ADR 0174 — veto anytime (no action taken this session beyond investigation; nothing to revert).
Artifact forensics on the real drive (
20260821T070234Z) — the "secret rotates in git" framing is falsified; the fault is a runtime restart+lockout, not a git rotationBen asked me to investigate directly. Instead of standing up a fresh lab, I mined the captured artifacts of the real full-install drive that produced this bug (
test-results/drive-selfhosted/20260821T070234Zon matou-workstation — the drive itself confirmed genuinenixos-anywhere/disko). Two config-repo snapshots were captured (state/clan-config.pre-flipandstate/clan-config), which is exactly the byte-level evidence the lab was meant to produce.1. The committed secret does not rotate — proven, not inferred
vars/per-machine/gateway/kanidm-admins/idm_admin/secretis one commit only:4ee8d3f 2026-08-21 07:04:12 "vars: update via generator kanidm-admins". No second commit, no--regenerate.git hash-object=1c2587adccbced6b7e50ac2c769e10e881cfe3e1in both;ENC[…data:YUL9GvIT…,iv:mL6HDijS…]identical byte-for-byte).2. What actually fails (hard journal evidence,
logs/droplet-journal.txt)kanidmd[1059]07:07:51: recover-account setsidm_admin; app authenticates →Auth result: Success(Token), token2e8ac70d…issued. Control-plane binary not present yet (idss-control-plane-start: /srv/idss/bin/control-plane: No such file or directory, exit 127) — this is why the second apply exists: it lands the control-plane binary + crown jewels.switch-to-configuration switch07:10:11 → kanidm restarts askanidmd[5046]07:10:13. recover-account runs again and revokes the app's boot-1 token:Revoking auth session whose issuing credential no longer exists | session_id: 2e8ac70d…. kanidm-provision re-auths → Success.idm_adminauth isDenied - incorrect passwordat 07:10:21, :24, :26 →Account is temporarily locked/AU0001InvalidStateat 07:10:29. That lockout is the 500.3. Code rules out the easy explanations
e.idp = e.liveIDP(internal/fleetwire/enrolment.go:105) is a plain func, not memoized; everyMintToken/AwaitCredentialre-readscat "$(cat /etc/idss/kanidm-idm-admin-path)"fresh over SSH.vmguest.go:171) and the provision block'sidmAdminPasswordFile(vmguest.go:277) are bothconfig.clan.core.vars.generators.kanidm-admins.files.idm_admin.path. No two-path divergence in the Nix declaration.RestartChangedadds no CLI flag (confirmed by the 22:22Z session againstadapter.go) — kanidm's restart is plainswitch-to-configurationchanged-unit restart.Where that leaves it — two compounding faults, neither is "git rotation"
Given git is stable, the same path both sides, and no app cache, the remaining divergence is purely runtime and temporal at that one sops path across the two applies. But the sharper reading of the journal is that the framing should shift from "the secret value differs" to two real bugs that fire regardless:
ddbc3d13softened the raw 500→ErrAuthDenied, but the lockout itself is the trap: a transient post-restart auth hiccup is converted into a persistent hard failure.Recommended fix direction (refines Ben's ruling)
"Pin stable across applies" should target the runtime, not git:
ddbc3d13as defence-in-depth.The one thing still needing a live box (now much narrower)
Only to decide (a)-vs-(b) split precisely: on a blank
clan-lab create --freshdroplet with just thekanidm-adminsgenerator, runclan machines installthenclan machines update, and capturesha256sum+readlink -fof/run/secrets/vars/kanidm-admins/idm_adminafter each apply. Same bytes ⇒ it's purely the restart/lockout (fix b, plus stop the needless restart); different bytes ⇒ a real--extra-files-snapshot-vs-sops-decrypt divergence to pin at the materialization layer too. (The 22:22Z session's narrowed recipe is correct; this just says: whatever that experiment shows, fault #1 and #2 above are already actionable now without waiting for it.)No code landed this session — investigation only, artifact forensics. Left
ready-for-human: the remaining call (spend a droplet on the narrowed experiment vs. just land fix (b) on the evidence already in hand) is Ben's.Closing — named code gap fixed; deeper materialization question → #640; drive verification unblocked
Ben's ruling this session: run a verification drive on the new binary first rather than write more speculative retry code.
Why closeable now: the code gap this ticket names is fixed.
ddbc3d13makes a Begin-step lockout return the typedkanidm.ErrAuthDeniedinstead of blindly submitting Cred into a dead session (which 500'd). And the whole activation chain that produced the red drive has landed since this ticket's only evidence drive (20260821T070234Z, 07:02Z):/srv/idss/bin/control-plane: No such file, exit 127)MintTokennow retries onErrAuthDeniedfor ~60s to ride out the settle raceddbc3d13the typed-denial fix aboveUndriven: all four self-hosted drives predate these five fixes, so none of them have been exercised. Closing this ticket removes the last open blocker on #523 (confirmed: #636 was the only open dep), so the executor re-fires the standing drive on
≥b78d7b8— the real verification.The deeper question is NOT dropped — it's #640. Artifact forensics on
20260821T070234Zproved the git secret does not rotate (single commit4ee8d3f, byte-identical ciphertext pre/post-flip) and that app+kanidm read the same sops path — so the original "the secret rotates between applies" framing is falsified. What remains open is value-vs-timing: the box's own provision authed Success at 07:10:13 yet the app was deniedincorrect passwordat 07:10:21 on the same nominal secret. If the verification drive greens past activation, #640 closes; if it reds at the lockout with #635 in place, #640 carries the narrowed live-droplet experiment (diff/run/secrets/vars/kanidm-admins/idm_adminbytes after each apply) to settle it.Full forensics: this ticket's 22:24Z comment and #640.