Device add on IDIP: the agent's netbird up is a no-op on a device already on another mesh and records the foreign address as the mesh fact; a member Files placement writes a kanidm-only files-idp.nix onto the gateway and nothing detaches it — gatew… #2040

Closed
opened 2026-10-03 04:15:47 +00:00 by ben · 2 comments
Owner

Two defects found together on the Whakatōhea Demo (IDIP community, release 7373b279) while adding the full-install device Delilah, 2026-10-03. They compound: the first makes a device look joined when it is not; the second breaks the gateway's config the moment that device is set up.

A. The agent's mesh join is a silent no-op on a device already connected to another netbird management — and it reports the OTHER mesh's address as the community mesh fact

Symptom: the install terminal printed ✓ joined the community network and the request reached Enrolled, but the gateway's community mesh (self-hosted netbird-management on the gateway, 100.83.0.0/16) never gained a peer. The ledger recorded mesh_address = 100.98.84.207 — the device's address on the Mātou mesh (netbird.matou.nz), where it had been logged in since an earlier abandoned attempt. Every deploy then dialled root@100.98.84.207 from the gateway and timed out: Set up (seed step, learn node-req-0005's host key at its mesh door (#1075) … Connection timed out), the Services door, AND the auto-update lane's rollout (update: seed node-req-0005: … could not reach the node) every 5 minutes.

Cause: agent/internal/meshup/meshup.go runs netbird up --setup-key K --management-url M, then reads the address back from netbird status --json. netbird's up returns early with "Already connected" when the daemon is already connected — to ANY management — so no login happened, the single-use key was never redeemed, and the status read returned the Mātou wt0. The adapter cannot tell "joined" from "was already somewhere else". The device's /var/log/netbird/client.log has no login at the landing minute; the gateway's peer list had only Tahi's guest.

Fix (proposed): before up, read netbird status --json; if managementState.URL is set and differs from adm.Management (or the daemon is connected anywhere else), either run netbird down and then up (the device consented to join THIS community; its prior mesh is not ours to keep), or fail loud naming the conflict (ADR 0100) — never proceed. After up, assert the status's management URL equals adm.Management and the address lies inside the management's range before recording it; a mismatch is a fault, not a mesh fact. Seam test: a fake runner whose status reports another management URL → the join is refused or re-logged, never reported with the foreign address.

B. A member-device Files placement writes a kanidm-side OAuth2 client onto the gateway, unconditionally — on an IDIP community that breaks the gateway's eval, and nothing ever detaches it

Symptom: after Delilah's first Set up (recommended set: second copies of archive, data-collections, document-archive, files, surveys + backup copies), every gateway deploy failed at preflight:

clan: config_eval on gateway: … error: attribute 'kanidm-admins' missing

including the Remove-device deploy, so the phantom node could not even be removed through the product.

Cause: attachMemberFilesPlacement (internal/provision/deploy.go) always calls clan.AttachFilesIDP, which writes machines/gateway/files-idp.nix (ADR 0210 ruling 3: the Nextcloud OAuth2 client provisioned "beside kanidm") and ComposeGatewayCohost imports it. The render reads config.clan.core.vars.generators.kanidm-admins — a generator only a kanidm community has. There is no IDIP branch (compare the bridge branches #1919–#1924 added for whakapapa/video/code/meetings) and no DetachFilesIDP: removing the device detached every module from the node (detach … from node-req-0005 commits) but left files-idp.nix on the gateway. Config repo commit 9648a83 idss: attach files-idp (OAuth2 client) on gateway at 23:33:43Z is the moment the gateway broke.

Fix (proposed): (1) attachMemberFilesPlacement on an IDIP community (o.bridgeIDP) must NOT write the kanidm client — either render the bridge equivalent for a member-placed Files, or gate files out of member placement on IDIP in the assessment (gated:true, "second copy of Files is gateway-only on this community for now") the same way #2039 asks for Newsletters. (2) Add the detach: removing Files from the last member device (and Remove-device) deletes files-idp.nix and recomposes the gateway. (3) Seam test: an IDIP fleet + member Files placement → the gateway machine dir contains no files-idp.nix, and the composed gateway evaluates (the TestOwnVPSGateway_* eval-smoke family).

Hand recovery performed on the demo (so the box state is known)

  • git rm machines/gateway/files-idp.nix + dropped its import from machines/gateway/configuration.nix, committed as control-plane <control-plane@idss> with the control plane stopped (8667c32); verified by nix eval …gateway…toplevel.drvPath in a scratch copy first (14 s, clean).
  • POST /api/v1/provision/devices/node-req-0005/remove → green (40afc8e idss: remove node node-req-0005); fleet back to gateway + Tahi.
  • Device: fresh code, netbird down BEFORE approval, approve → req-0006 Enrolled with mesh_address 100.83.245.38; the gateway's mesh shows whakatohea.netbird.mesh connected and ssh root@100.83.245.38 answers. Delilah must be set up WITHOUT Files & documents until B lands, or the gateway breaks again.

Acceptance

  • A device already connected to another netbird management either joins the community mesh for real (its ledger mesh_address is inside the community range and the gateway lists it as a peer) or the landing fails loud with the conflict named; the terminal never prints ✓ joined the community network on a no-op up.
  • On an IDIP community, placing Files on a member device never writes a kanidm client onto the gateway; the gateway evaluates after the placement and after the device's removal.
  • Removing a member device that held Files leaves no files-idp.nix behind on a kanidm community either.
  • GOTCHAS #390/#391 (filed with this ticket) stay accurate.

#2038, #2039 (same device, same day), #1075, #1068, #1114, #1927, ADR 0209, ADR 0210 ruling 3, ADR 0214, ADR 0100, agent/internal/meshup/meshup.go, internal/provision/deploy.go (attachMemberFilesPlacement), internal/clan/files_idp_gateway.go.

Two defects found together on the Whakatōhea Demo (IDIP community, release `7373b279`) while adding the full-install device `Delilah`, 2026-10-03. They compound: the first makes a device look joined when it is not; the second breaks the gateway's config the moment that device is set up. ## A. The agent's mesh join is a silent no-op on a device already connected to another netbird management — and it reports the OTHER mesh's address as the community mesh fact **Symptom:** the install terminal printed `✓ joined the community network` and the request reached Enrolled, but the gateway's community mesh (self-hosted `netbird-management` on the gateway, 100.83.0.0/16) never gained a peer. The ledger recorded `mesh_address = 100.98.84.207` — the device's address on the **Mātou** mesh (netbird.matou.nz), where it had been logged in since an earlier abandoned attempt. Every deploy then dialled `root@100.98.84.207` from the gateway and timed out: Set up (seed step, `learn node-req-0005's host key at its mesh door (#1075) … Connection timed out`), the Services door, AND the auto-update lane's rollout (`update: seed node-req-0005: … could not reach the node`) every 5 minutes. **Cause:** `agent/internal/meshup/meshup.go` runs `netbird up --setup-key K --management-url M`, then reads the address back from `netbird status --json`. netbird's `up` returns early with "Already connected" when the daemon is already connected — to ANY management — so no login happened, the single-use key was never redeemed, and the status read returned the Mātou wt0. The adapter cannot tell "joined" from "was already somewhere else". The device's `/var/log/netbird/client.log` has no login at the landing minute; the gateway's peer list had only Tahi's guest. **Fix (proposed):** before `up`, read `netbird status --json`; if `managementState.URL` is set and differs from `adm.Management` (or the daemon is connected anywhere else), either run `netbird down` and then `up` (the device consented to join THIS community; its prior mesh is not ours to keep), or fail loud naming the conflict (ADR 0100) — never proceed. After `up`, assert the status's management URL equals `adm.Management` and the address lies inside the management's range before recording it; a mismatch is a fault, not a mesh fact. Seam test: a fake runner whose status reports another management URL → the join is refused or re-logged, never reported with the foreign address. ## B. A member-device Files placement writes a kanidm-side OAuth2 client onto the gateway, unconditionally — on an IDIP community that breaks the gateway's eval, and nothing ever detaches it **Symptom:** after Delilah's first Set up (recommended set: second copies of archive, data-collections, document-archive, files, surveys + backup copies), every gateway deploy failed at preflight: ``` clan: config_eval on gateway: … error: attribute 'kanidm-admins' missing ``` including the Remove-device deploy, so the phantom node could not even be removed through the product. **Cause:** `attachMemberFilesPlacement` (`internal/provision/deploy.go`) always calls `clan.AttachFilesIDP`, which writes `machines/gateway/files-idp.nix` (ADR 0210 ruling 3: the Nextcloud OAuth2 client provisioned "beside kanidm") and `ComposeGatewayCohost` imports it. The render reads `config.clan.core.vars.generators.kanidm-admins` — a generator only a kanidm community has. There is no IDIP branch (compare the bridge branches #1919–#1924 added for whakapapa/video/code/meetings) and no `DetachFilesIDP`: removing the device detached every module from the node (`detach … from node-req-0005` commits) but left `files-idp.nix` on the gateway. Config repo commit `9648a83 idss: attach files-idp (OAuth2 client) on gateway` at 23:33:43Z is the moment the gateway broke. **Fix (proposed):** (1) `attachMemberFilesPlacement` on an IDIP community (`o.bridgeIDP`) must NOT write the kanidm client — either render the bridge equivalent for a member-placed Files, or gate `files` out of member placement on IDIP in the assessment (`gated:true`, "second copy of Files is gateway-only on this community for now") the same way #2039 asks for Newsletters. (2) Add the detach: removing Files from the last member device (and Remove-device) deletes `files-idp.nix` and recomposes the gateway. (3) Seam test: an IDIP fleet + member Files placement → the gateway machine dir contains no `files-idp.nix`, and the composed gateway evaluates (the `TestOwnVPSGateway_*` eval-smoke family). ## Hand recovery performed on the demo (so the box state is known) - `git rm machines/gateway/files-idp.nix` + dropped its import from `machines/gateway/configuration.nix`, committed as `control-plane <control-plane@idss>` with the control plane stopped (`8667c32`); verified by `nix eval …gateway…toplevel.drvPath` in a scratch copy first (14 s, clean). - `POST /api/v1/provision/devices/node-req-0005/remove` → green (`40afc8e idss: remove node node-req-0005`); fleet back to gateway + Tahi. - Device: fresh code, `netbird down` BEFORE approval, approve → `req-0006` Enrolled with `mesh_address 100.83.245.38`; the gateway's mesh shows `whakatohea.netbird.mesh` connected and `ssh root@100.83.245.38` answers. **Delilah must be set up WITHOUT Files & documents until B lands**, or the gateway breaks again. ## Acceptance - A device already connected to another netbird management either joins the community mesh for real (its ledger `mesh_address` is inside the community range and the gateway lists it as a peer) or the landing fails loud with the conflict named; the terminal never prints `✓ joined the community network` on a no-op `up`. - On an IDIP community, placing Files on a member device never writes a kanidm client onto the gateway; the gateway evaluates after the placement and after the device's removal. - Removing a member device that held Files leaves no `files-idp.nix` behind on a kanidm community either. - GOTCHAS #390/#391 (filed with this ticket) stay accurate. ## Related #2038, #2039 (same device, same day), #1075, #1068, #1114, #1927, ADR 0209, ADR 0210 ruling 3, ADR 0214, ADR 0100, `agent/internal/meshup/meshup.go`, `internal/provision/deploy.go` (`attachMemberFilesPlacement`), `internal/clan/files_idp_gateway.go`.

swarm-claim host=bens-mac-04 run=38316
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=bens-mac-04 run=38316 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #2040 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 2040,
  "status": "success",
  "commits": [
    "f24274e61d6f9af3fcf323dd786d5f6363401fb9"
  ],
  "changed_files": [
    "STATUS.md",
    "agent/internal/meshup/meshup.go",
    "agent/internal/meshup/meshup_test.go",
    "control-plane/cmd/control-plane/resting_composition.go",
    "internal/clan/clan.go",
    "internal/clan/files_idp_gateway.go",
    "internal/clan/files_idp_gateway_test.go",
    "internal/clan/testing/fake.go",
    "internal/provision/assess.go",
    "internal/provision/deploy.go",
    "internal/provision/deploy_test.go",
    "internal/provision/idip_signin_test.go"
  ],
  "tests": [
    {
      "command": "go build ./...",
      "exit_code": 0
    },
    {
      "command": "go vet ./internal/provision/... ./internal/clan/... ./agent/internal/meshup/...",
      "exit_code": 0
    },
    {
      "command": "go test ./internal/provision/... ./internal/clan/... ./agent/internal/meshup/...",
      "exit_code": 0
    },
    {
      "command": "go test ./...",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A device already connected to another netbird management either joins the community mesh for real or the landing fails loud with the conflict named; the terminal never prints the joined line on a no-op up": "agent/internal/meshup/meshup.go: Join now decodes management.url, brings a daemon on a DIFFERENT management down before `up`, and after `up` asserts the status reports the community's management (sameManagement) before recording any address — a mismatch is a loud ADR 0100 error naming the conflict. Proven by TestMeshUp_AlreadyOnAnotherMesh_ReLoginLandsCommunityAddress (down+up lands the COMMUNITY address 100.83.245.38, never the foreign 100.98.84.207) and _NoOpUpRefusedNeverRecordsForeignAddress (refusal names the conflicting management + ADR 0100, records NO address). The live range-membership + gateway-peer-listing leg is unproven_by_seam (scripted runner, not a real netbird daemon).",
    "On an IDIP community, placing Files on a member device never writes a kanidm client onto the gateway; the gateway evaluates after the placement and after the device's removal": "internal/provision/deploy.go: attachMemberFilesPlacement skips AttachFilesIDP when o.bridgeIDP (deploy backstop), and internal/provision/assess.go idipMemberFilesGate gates member-device Files out at selection on IDIP (listed gated + unpickable). Proven by TestDeploy_IDIPMemberFilesWritesNoKanidmClient (zero AttachFilesIDP calls, device render + mesh route still land) and TestForRole_IDIPGatesFilesOnAMemberDevice. Removal cleans up via DetachFilesIDP (TestRemoveDevice_DetachesTheGatewayIDPClient). gateway-evaluates is proven STRUCTURALLY (no files-idp.nix => no kanidm-admins reference); the real IDSS_EVAL_SMOKE nix eval is unproven_by_seam.",
    "Removing a member device that held Files leaves no files-idp.nix behind on a kanidm community either": "internal/clan/files_idp_gateway.go: new DetachFilesIDP deletes machines/<gateway>/files-idp.nix idempotently; internal/provision/deploy.go detachMemberFilesPlacement calls it + recomposes the gateway once anyMemberFilesPlacementRemains is false. Proven by TestRemoval_LastMemberFilesDetachesTheGatewayIDPClient (kanidm community, DetachFilesIDP on gateway karaka) and TestDetachFilesIDP_DropsTheFileAndIsIdempotent (adapter deletes the file, idempotent no-op on re-detach).",
    "GOTCHAS #390/#391 (filed with this ticket) stay accurate": "docs/GOTCHAS.md #390 (the netbird no-op mesh join) and #391 (the kanidm client written onto an IDIP gateway) were already on origin/main; verified accurate against the shipped fix during the rebase (their Rules are exactly what this commit implements). Not re-edited by this commit because the canonical entries already matched — the rebase kept origin/main's copies and dropped the duplicate this run drafted."
  },
  "summary": "Fixed the netbird silent-no-op mesh join (join for real or fail loud, never record the foreign address) and the IDIP member-Files kanidm-client gateway break (gate at selection, skip at deploy, detach on removal).",
  "blockers": []
}
**close-report** for #2040 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 2040, "status": "success", "commits": [ "f24274e61d6f9af3fcf323dd786d5f6363401fb9" ], "changed_files": [ "STATUS.md", "agent/internal/meshup/meshup.go", "agent/internal/meshup/meshup_test.go", "control-plane/cmd/control-plane/resting_composition.go", "internal/clan/clan.go", "internal/clan/files_idp_gateway.go", "internal/clan/files_idp_gateway_test.go", "internal/clan/testing/fake.go", "internal/provision/assess.go", "internal/provision/deploy.go", "internal/provision/deploy_test.go", "internal/provision/idip_signin_test.go" ], "tests": [ { "command": "go build ./...", "exit_code": 0 }, { "command": "go vet ./internal/provision/... ./internal/clan/... ./agent/internal/meshup/...", "exit_code": 0 }, { "command": "go test ./internal/provision/... ./internal/clan/... ./agent/internal/meshup/...", "exit_code": 0 }, { "command": "go test ./...", "exit_code": 0 } ], "criteria": { "A device already connected to another netbird management either joins the community mesh for real or the landing fails loud with the conflict named; the terminal never prints the joined line on a no-op up": "agent/internal/meshup/meshup.go: Join now decodes management.url, brings a daemon on a DIFFERENT management down before `up`, and after `up` asserts the status reports the community's management (sameManagement) before recording any address — a mismatch is a loud ADR 0100 error naming the conflict. Proven by TestMeshUp_AlreadyOnAnotherMesh_ReLoginLandsCommunityAddress (down+up lands the COMMUNITY address 100.83.245.38, never the foreign 100.98.84.207) and _NoOpUpRefusedNeverRecordsForeignAddress (refusal names the conflicting management + ADR 0100, records NO address). The live range-membership + gateway-peer-listing leg is unproven_by_seam (scripted runner, not a real netbird daemon).", "On an IDIP community, placing Files on a member device never writes a kanidm client onto the gateway; the gateway evaluates after the placement and after the device's removal": "internal/provision/deploy.go: attachMemberFilesPlacement skips AttachFilesIDP when o.bridgeIDP (deploy backstop), and internal/provision/assess.go idipMemberFilesGate gates member-device Files out at selection on IDIP (listed gated + unpickable). Proven by TestDeploy_IDIPMemberFilesWritesNoKanidmClient (zero AttachFilesIDP calls, device render + mesh route still land) and TestForRole_IDIPGatesFilesOnAMemberDevice. Removal cleans up via DetachFilesIDP (TestRemoveDevice_DetachesTheGatewayIDPClient). gateway-evaluates is proven STRUCTURALLY (no files-idp.nix => no kanidm-admins reference); the real IDSS_EVAL_SMOKE nix eval is unproven_by_seam.", "Removing a member device that held Files leaves no files-idp.nix behind on a kanidm community either": "internal/clan/files_idp_gateway.go: new DetachFilesIDP deletes machines/<gateway>/files-idp.nix idempotently; internal/provision/deploy.go detachMemberFilesPlacement calls it + recomposes the gateway once anyMemberFilesPlacementRemains is false. Proven by TestRemoval_LastMemberFilesDetachesTheGatewayIDPClient (kanidm community, DetachFilesIDP on gateway karaka) and TestDetachFilesIDP_DropsTheFileAndIsIdempotent (adapter deletes the file, idempotent no-op on re-detach).", "GOTCHAS #390/#391 (filed with this ticket) stay accurate": "docs/GOTCHAS.md #390 (the netbird no-op mesh join) and #391 (the kanidm client written onto an IDIP gateway) were already on origin/main; verified accurate against the shipped fix during the rebase (their Rules are exactly what this commit implements). Not re-edited by this commit because the canonical entries already matched — the rebase kept origin/main's copies and dropped the duplicate this run drafted." }, "summary": "Fixed the netbird silent-no-op mesh join (join for real or fail loud, never record the foreign address) and the IDIP member-Files kanidm-client gateway break (gate at selection, skip at deploy, detach on removal).", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#2040
No description provided.