Repository navigation
[M1.2b2] Serve agent enrollment and renewal over TLS gRPC - #31
Merged
Merged
Conversation
4 of 5 tasks
samuelmbabhazi
force-pushed
the
feat/m1.2b1-certificate-lifecycle
branch
from
November 5, 2026 13:32
7b2009f to
3b136a7
Compare
samuelmbabhazi
force-pushed
the
feat/m1.2b2-agent-gateway
branch
from
November 5, 2026 13:35
24806b7 to
60615f9
Compare
5 of 6 tasks
Collaborator
Author
|
Rebased onto the rebased #30.
|
samuelmbabhazi
force-pushed
the
feat/m1.2b1-certificate-lifecycle
branch
from
November 5, 2026 14:21
3b136a7 to
2c5e133
Compare
samuelmbabhazi
changed the base branch from
feat/m1.2b1-certificate-lifecycle
to
main
November 5, 2026 14:22
samuelmbabhazi
force-pushed
the
feat/m1.2b2-agent-gateway
branch
from
November 5, 2026 14:23
60615f9 to
34bbf2a
Compare
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
Implements the first part of M1.2c: node keys and credentials that remain coherent across enrollment and renewal. Depends on #31; this PR intentionally targets its branch. The agent generates Ed25519 keys and signed CSRs, validates the key/certificate pair against the installation CA and exact tenant/node SPIFFE identity, and persists one atomic credential generation. Loading rejects symlinks, loose permissions, oversized files, mismatched identities and invalid certificates. The private key uses the redacting Secret wrapper and is exposed only at TLS and explicit persistence boundaries. Validation: Go tests with the race detector, golangci-lint, TypeScript lint/typecheck and unit tests, protobuf lint/format. Regression tests cover forged identities, substituted keys/CAs, failed replacements, secret formatting and file permissions. No new dependencies, remote actions or database writes. Plan, specification and threat model updated. - [x] M1.2c1 acceptance criteria and regression tests - [x] No shell invocation or secret logging - [x] Atomic persistence with 0600 files - [x] Documentation updated - [ ] CI and maintainer review M1.2c remains open for enrollment, streaming and reconnect/renewal scheduling. No merge requested.
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
[M1.2b2] TLS gateway and unary agent RPCs. Part of #14. Stacked on #30: review and merge #30 first, then retarget this PR to main. Neither PR should be merged automatically.
What changed
Start a dedicated HTTP/2 gRPC listener using Connect-RPC after Nest initializes. Serve
EnrollandRenewCertificatethrough the existing fleet commands. Use a separate Ed25519 server-auth certificate signed by the installation CA, configure its DNS/IP SAN withAGENT_GATEWAY_SERVER_NAME, and refresh the in-memory credentials daily.Client certificates are optional at the TLS handshake solely to support initial enrollment. Every other RPC requires a verified TLS peer, client-auth purpose, SPIFFE identity and a current matching database certificate record. Identity headers are ignored and revoked serials are rejected on every request, including reused connections. Bound message sizes, sanitize errors and close HTTP/2 sessions during shutdown.
Make enrollment transactional before exposing it over the network: concurrent uses of one join token produce one node and one certificate, and audit failure rolls back the node, certificate and token consumption. The regression test first reproduced two persisted nodes for one token before this correction.
Scope and dependencies
M1.2b stays open: the CA fingerprint is already returned by
IssueJoinToken, but the REST endpoint and installation-command UI depend on M2.3/M8.3.Connectstream lifecycle and revocation-driven disconnection land with M1.2c. Streaming RPCs currently authenticate and returnUnimplemented; no leases or actions are claimed to work yet. These boundaries are recorded in PLAN, SPEC, README and THREAT_MODEL.How it was tested
pnpm gensucceeds without changes to generated contracts; API build succeeds.Security considerations
The
rejectUnauthorized: falseserver option permits the certificate-free enrollment handshake. It is not client-side disabling of server verification: the application gate requiresTLSSocket.authorizedon protected RPCs and also checks database registration/revocation. Tests prove a rogue CA cannot bypass the gate even by copying an enrolled node identity and serial.The generic Semgrep
bypass-tls-verificationrule flags this server configuration. Its precise finding is suppressed inline with the server-only rationale above; all other rules remain enabled, and the full CI rule set is rerun. This does not weaken any client-side TLS verification.Connect-RPC dependencies are Apache-2.0. No action catalogue change, host shell execution, plaintext key persistence or new public REST endpoint.
Checklist