Skip to content

[M1.2c4b] Connect the agent daemon and verify restart and revocation - #36

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m1.2c4b-agent-daemon
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m1.2c4b-agent-daemon

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Completes M1.2c by wiring enrollment and the reconnect/renewal runner into the Go daemon. Depends on #35 and targets its branch.

An unregistered production agent reads a bounded regular 0600 join-token file, verifies the installation CA, enrolls, atomically saves its identity and only then removes the token file. Subsequent starts use the persisted credentials. Production fails closed on missing or invalid credentials; development without a token remains an idle skeleton. Configuration, example and README document the flow.

Validation: 23 PostgreSQL/TLS integration tests, now including the actual Go daemon against NestJS through enrollment, reused-token rejection, full application restart on the same port, reconnect and live revocation. This test checks persisted identity, token cleanup and log redaction. Go race tests, golangci-lint, TypeScript lint/typecheck/unit tests, protobuf checks and API production build pass. The agent binary remains below 30 MB.

The integration-only helper launches a fixed go test argv without a shell; it is excluded from the production API build and passes no secret in argv. Fixtures are private temporary files removed during teardown. The targeted Semgrep exception is limited to this test harness, following the existing OpenAPI generator precedent.

  • All M1.2c acceptance criteria met
  • New input and lifecycle tests
  • No production process spawning or secret logging
  • Plan, spec, threat model and operator example updated
  • CI and maintainer review

M1.2 remains open for the REST join-token/install-command dependencies already recorded under M1.2b (M2.3/M8.3). Workload execution and durable leases retain their own milestones. No merge requested.

@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m1.2c4a-agent-reconnect branch from 18be0ea to 6f08f0c Compare November 5, 2026 13:38
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m1.2c4b-agent-daemon branch from c050a8b to 496a893 Compare November 5, 2026 13:39
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m1.2c4a-agent-reconnect branch from 6f08f0c to 0c412b3 Compare November 5, 2026 14:30
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m1.2c4a-agent-reconnect to main November 5, 2026 14:30
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m1.2c4b-agent-daemon branch from 496a893 to b6b7230 Compare November 5, 2026 14:32
@samuelmbabhazi
samuelmbabhazi merged commit 3583b84 into main Nov 5, 2026
2 of 11 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m1.2c4b-agent-daemon branch November 5, 2026 14:32
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
…103)

## Task

Review follow-ups for the M1.2 stack (#31, #33, #35). Stacked on #36.
Refs #14

## What changed

**Gateway TLS (#31)**
- `gatewaySecureContext()` holds every TLS setting and is used both when
the server starts and at the daily certificate refresh. Node's
`setSecureContext` resets any option it is not given. Before this fix,
the first refresh silently dropped the gateway from TLS 1.3 to Node's
TLS 1.2 default, where client certificates travel unencrypted.
- A unit test reproduces Node's behaviour and checks that the minimum
survives a refresh.

**Certificates and enrollment errors (#31, #33)**
- Node and gateway certificates start 5 minutes before issuance
(`CLOCK_SKEW_ALLOWANCE_MS`). The 30-day validity still runs from
issuance.
- Before this fix, an agent whose clock was even one second behind
rejected its brand-new certificate. The join token was already burned
and the node name stuck in `enrolling`. During renewal, the same skew
bricked the node.
- An oversized CSR now returns `InvalidInputError` (gRPC
InvalidArgument) instead of `ConflictError` (AlreadyExists).
- Two concurrent enrollments racing for the same node name now get
`node_name_taken` instead of a raw P2002 mapped to Internal.

**Agent renewal durability (#35)**
- `RenewCertificate` and the following save run under
`context.WithoutCancel` with a 30 s budget. A SIGTERM during renewal no
longer cancels an RPC the server may already have committed.
- A failed save of the renewed credentials (full disk, I/O error) is
retried with bounded backoff instead of halting with the only valid key
in memory and the old certificate already revoked.
- SPEC 3.2 documents all of the above.

## How it was tested

- API: `nx run-many -t lint typecheck test -p api` passes, with new and
updated tests for TLS settings, backdated node and gateway certificates,
and the oversized-CSR error kind.
- Agent: `go test -race ./agent/... ./lib/...` and `golangci-lint` pass.
New tests: a renewal survives two failed saves and is persisted
afterwards; a renewal started after cancellation still completes and is
persisted.
- Integration and browser tests could not run locally (no Docker in the
sandbox), and GitHub Actions is blocked by the account spending limit.
CI must pass before merge.

## Security considerations

Restores the TLS 1.3-only guarantee of the agent gateway. Backdating by
5 minutes slightly extends the validity window into the past and does
not change expiry. No change to the action catalogue.

## Checklist

- [x] Lint, TS tests, Go tests pass locally
- [x] Regression tests added
- [x] No new shell invocation and no new secret exposure path
- [x] Audit events unchanged
- [x] SPEC updated
- [ ] CI green (blocked by billing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant