Skip to content

[M1.2a] Fleet: join tokens, installation CA and node enrollment - #29

Merged
samuelmbabhazi merged 8 commits into
mainfrom
feat/m1.2a-fleet-ca-join-tokens
Nov 3, 2026
Merged

samuelmbabhazi merged 8 commits into
mainfrom
feat/m1.2a-fleet-ca-join-tokens

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Task

[M1.2a] Enrollment foundations on the control plane (first third of M1.2, split recorded in docs/PLAN.md). Refs #14

What changed

Domain (modules/fleet/domain)

  • Join tokens: 32 random bytes as base64url, stored as SHA-256 only, 15-minute TTL, single use. evaluateJoinToken is pure and rejects malformed values before any lookup; every rejection reason maps to one client-facing message so callers cannot probe for existing tokens.
  • Nodes: name rule from SPEC, hostname-to-name derivation, bounded sanitizeFacts (agents are trusted for their facts but not for the shape of what reaches the database), SPIFFE identity spiffe://shipkeep/<org>/node/<node> with a strict parser.
  • Events fleet.join_token.issued and fleet.node.enrolled (the node is the actor of its own enrollment, with the caller IP).

Application

  • Ports: JoinTokenStore (atomic consume), NodeStore, CertificateAuthority, ConfirmationKeyProvider.
  • IssueJoinToken: returns the value once with the CA fingerprint for the install command; audits the issuance without the value.
  • EnrollNode: validates the token, caps the CSR at 8 KiB, derives and uniquifies the node name, asks the CA for a certificate, records node and certificate, consumes the token last and atomically (a token can never enroll two nodes), emits the audit event, and returns the certificate, CA PEM, lease epoch 1 and the confirmation public key (the EnrollResponse of SPEC 3.2).

Infrastructure

  • Ed25519 installation CA with @peculiar/x509 over Node WebCrypto: self-signed CA (10 years, keyCertSign), node client certificates valid 30 days with CN = node id, SAN URI = SPIFFE id, clientAuth only, random 128-bit serials. The CSR signature is verified and only its public key is used: subject and requested extensions are ignored. Non-Ed25519 keys are refused.
  • CA and confirmation signing key pairs are created once at first start (unique kind, concurrent starts converge on one CA) and stored with the private half encrypted by EnvelopeService (scope installation:keys).
  • Prisma stores and models: installation_keys, join_tokens, nodes (unique name per organization), node_certificates; migration 20261103125636_fleet. organization_id gets its foreign key when organizations land (M2.3).
  • FleetModule wired into the application. No REST or gRPC surface yet: exposing Enroll is M1.2b and the join-token endpoint waits for RBAC (M2.3), so nothing unauthenticated is reachable.

Tests

  • Unit: 9 join-token, 6 node, 6 enrollment (reuse, expiry, malformed, duplicate name, oversized CSR, fallback name), 5 CA (creation once, encrypted storage, identity decided by the control plane and not the CSR, distinct serials, forged, garbage and RSA CSRs, pre-init guard).
  • Integration against PostgreSQL: issue a token, enroll with a real Ed25519 CSR, verify the chain and SAN, check node, certificate, consumed token, encrypted installation keys and both audit rows, then confirm the spent token is rejected.
  • HTTP pipeline tests now build the application from a Nest testing module with in-memory key stores, so they never reach a database; configureApp is shared with createApp.

Why

ARCHITECTURE flow 1 and SPEC 3.2: the control plane must be able to mint single-use tokens and sign node identities before any agent can connect. Keeping the CA key under the KEK removes the "root key in a web panel" failure mode this project exists to avoid.

How it was tested

  • pnpm nx run-many -t lint typecheck test build: all 7 projects green.
  • pnpm test:integration (Testcontainers, clean environment): 4 tests green.
  • pnpm gen twice: no drift. Semgrep custom rules: clean.

Security considerations

  • Join token values exist only in the API response and the operator's install command; the database and the audit log hold the hash. Rejections are indistinguishable.
  • The CA never honours names from the CSR. Certificates carry the organization in the SAN so the gateway (M1.2b) can bind every call to a tenant.
  • @peculiar/x509 2.2.0 (MIT) is pinned below 3.x because 3.0.0 was published less than seven days ago (pnpm minimumReleaseAge).
  • Change to the data model: four new tables, InstallationKey added to SPEC section 4. No agent action changed.

Checklist

  • Acceptance criteria for M1.2a in docs/PLAN.md are met and ticked
  • Lint, TS tests, Go tests and buf lint pass
  • Tests added, including malicious-input tests (forged CSR, foreign SPIFFE SAN in CSR, RSA key, oversized request, malformed tokens)
  • No new shell invocation and no new secret exposure path
  • Audit events emitted for token issuance and enrollment
  • SPEC and PLAN updated

@samuelmbabhazi
samuelmbabhazi merged commit 712c962 into main Nov 3, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m1.2a-fleet-ca-join-tokens branch November 3, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant