Skip to content

feat(fleet): a server a restore rolled back is re-adopted on an administrator's confirmation (part of #487) - #518

Merged
samuelmbabhazi merged 3 commits into
mainfrom
feat/487-readopt-restored-servers
Nov 26, 2026
Merged

samuelmbabhazi merged 3 commits into
mainfrom
feat/487-readopt-restored-servers

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

The first part of #487, as decided: confirmed re-adoption. A restore from a backup older than a server's last certificate renewal no longer leaves that server unmanageable. The gateway records the certificate it refused, and an administrator confirms with their password, which registers it for that same server. Every step is audited and revocation still holds. The Servers page will offer the step in a second pull request, which needs your validation.

Gateway (agent-gateway.ts): when the registry refuses a certificate that TLS verified against the installation CA, NodeReadoptions.notice records it in node_readoptions, one row per node, when all of these hold:

  • the registry knows no such serial. A known serial that was revoked or has expired stays refused and is never recorded;
  • the certificate is current;
  • its node exists in the certificate's organization and was not removed.

Its first record is audited as fleet.node.readoption_requested (by the node). Later presentations refresh last_seen_at at most once a minute. A failure to record changes nothing in the answer: the request stays refused.

API

  • GET /api/v1/organizations/{org}/node-readoptions (node.manage) lists the waiting certificates.
  • POST /api/v1/organizations/{org}/nodes/{node}/readopt (node.manage, session only) takes the caller's password and second factor, the same proof as a join token, and runs in one transaction. It registers the waiting certificate, revokes the node's other certificates, deletes the request and publishes fleet.node.readopted with the revoked serials.
    • It answers 409 for no request, a removed node, a certificate that expired while waiting, or a serial already registered.

Data: the migration node_readoptions, under tenant row security, cascades with its node. The runtime role gets SELECT, INSERT, UPDATE, DELETE on it, and the table joins TENANT_TABLES.

Agent (gateway/runner.go): a certificate the control plane refuses (Unauthenticated, FailedPrecondition) is presented again every 5 minutes, unchanged, with one error log. The agent never enrolls again. A local identity error (unreadable credentials, a mismatched Welcome) still waits for an operator. A re-adopted server therefore connects by itself. Older agents connect once restarted, as INSTALL.md says.

Docs: SPEC 3.1, ADR 0026, INSTALL.md (Back up and restore), THREAT_MODEL, and the restore's closing message in backup.sh. They no longer promise an unconditional reconnection.

Why

Closes part of #487. The gateway requires the presented serial to exist in the registry. After such a restore the agent holds a serial the restored database never saw, and the agent stopped trying for good. The fix accepts nothing by itself: a new certificate needs an administrator's confirmation, and the CA's signature alone is not enough.

How it was tested

  • Domain (node-readoption.spec.ts, 9 tests):
    • what is worth recording: unknown, current, node present and not removed;
    • refresh at most once a minute, and a new certificate replacing the recorded one;
    • what can be confirmed, including an expired or not-yet-valid certificate.
  • Gateway over real HTTP/2 TLS and PostgreSQL (gateway.integration.spec.ts):
    • A CA-signed certificate of an enrolled node that the registry lost is refused twice, recorded once and audited once by the node. The registered certificate keeps working.
    • Nothing is recorded for a revoked registered serial, for a CA-signed certificate of a removed node, or for one naming another organization.
    • Removing the "known serial" check makes this test fail (mutation check).
  • HTTP (fleet-administration-http.integration.spec.ts):
    • The list is visible to administrators only: 404 for member, project admin and outsider.
    • Confirmation refuses a wrong password (401) and other roles (404).
    • With a fresh proof it answers 200. The waiting certificate then authenticates and the one the backup knew does not. The audit event names the administrator and the revoked serial.
    • A second confirmation answers 409, and the list is empty.
  • Agent (TestRunnerPresentsARefusedCertificateAgainLater): refused, then accepted after a "re-adoption". The agent connects without enrolling again. Restoring the old wait-forever makes the test fail.
  • The full API unit and integration suites pass (see the check below). go test -race ./agent/internal/gateway/ passes and golangci-lint reports 0 issues. api:lint, api:typecheck and prettier pass, and pnpm gen regenerated openapi.json and the API client.

Security considerations

  • Nothing is accepted without a person. The gateway's behavior for unknown certificates stays a refusal. Recording one requires a certificate the installation CA signed, so an attacker without the CA key cannot create requests.
  • Revocation holds. A known serial, revoked or expired, is never offered for re-adoption. Removed nodes and other organizations' nodes are excluded, and the tenant row security covers the new table.
  • Confirmation. It needs node.manage and the caller's password and second factor, under the credential-proof rate limit (token). It is audited with the serials it revoked, and the node's other certificates are revoked in the same transaction.
  • Agent. It retries a refused certificate every 5 minutes, which gives it no new capability: it presents the same certificate and never enrolls again.
  • Outputs. Logs carry no remote error text and no certificate contents. API outputs carry serials and dates, as the audit log already does.

…istrator's confirmation (part of #487)

After a restore from a backup older than a server's last renewal, the agent presents a certificate the installation CA signed and the restored registry never saw, and the gateway refused it for good: the agent stopped trying.

The gateway now records such a certificate when TLS verified it, the registry knows no such serial (a revoked or expired serial stays refused), and its node exists and was not removed; the first record is audited. An administrator lists them and confirms with their password and second factor: the certificate is registered for that same node, its others are revoked, audited. The agent presents a refused certificate again every 5 minutes and never enrolls again, so a re-adopted server connects by itself.

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3399cca and 8768940.

Files ignored due to path filters: 3

  • apps/api/openapi.json is excluded by !apps/api/openapi.json
  • docs/generated/route-role-matrix.md is excluded by !**/generated/**, !docs/generated/**
  • packages/api-client/src/gen/openapi.ts is excluded by !**/gen/**, !packages/api-client/src/gen/**
Files selected for processing: 27

  • agent/internal/agent/gateway_integration_test.go
  • agent/internal/gateway/client_test.go
  • agent/internal/gateway/runner.go
  • agent/internal/gateway/runner_test.go
  • apps/api/prisma/migrations/20261126120000_node_readoptions/migration.sql
  • apps/api/prisma/schema.prisma
  • apps/api/src/audit-coverage.spec.ts
  • apps/api/src/modules/fleet/application/fleet-administration.ts
  • apps/api/src/modules/fleet/application/ports.ts
  • apps/api/src/modules/fleet/application/readopt-node.ts
  • apps/api/src/modules/fleet/domain/events.ts
  • apps/api/src/modules/fleet/domain/node-readoption.spec.ts
  • apps/api/src/modules/fleet/domain/node-readoption.ts
  • apps/api/src/modules/fleet/fleet-administration-http.integration.spec.ts
  • apps/api/src/modules/fleet/fleet.module.ts
  • apps/api/src/modules/fleet/gateway.integration.spec.ts
  • apps/api/src/modules/fleet/infrastructure/prisma-node-readoption.store.ts
  • apps/api/src/modules/fleet/interface/agent-gateway.ts
  • apps/api/src/modules/fleet/interface/fleet-administration.controller.ts
  • apps/api/src/modules/fleet/interface/fleet-administration.dto.ts
  • apps/api/src/platform/prisma/tenant-database-role.ts
  • deploy/control-plane/backup.sh
  • deploy/postgres/runtime-role.sql
  • docs/INSTALL.md
  • docs/SPEC.md
  • docs/THREAT_MODEL.md
  • docs/adr/0026-instance-backup-as-an-encrypted-export.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator Author

Lab acceptance (run28)

Setup

  • Control plane: the published v0.1.0-alpha.7 bundle, switched to this branch's image (e430cbd). The node_readoptions migration applied at start.
  • Server node-b: set up with the v0.1.0-alpha.3 installer, migrated, then given this branch's agent. It serves the application third, pinned to it.

Steps

  1. Simulated restore. In the database, node-b's registered certificate was replaced by an older one, as a restore from a backup older than its last renewal leaves it. The agent kept the certificate it holds.
  2. Refusal. Its open stream was closed at the next credential check.
    • The agent logged the control plane refused this agent's certificate; an administrator can re-adopt this server, or its certificate was revoked, once.
    • The node went suspect, then down. third.shipkeep.test kept answering from its container throughout, as rule 10 requires.
  3. Record. The agent presented the same certificate again 5 minutes later, and the gateway recorded it.
    • GET …/node-readoptions listed 2b4c154c… for node-b.
    • Audit: fleet.node.readoption_requested, by the node.
  4. Confirmation. POST …/nodes/<node-b>/readopt with the owner's password answered 200.
    • The registry then held 2b4c154c… active and the "backup" certificate revoked, and the list was empty.
    • Audit: fleet.node.readopted, by the user.
  5. Return. The agent's next attempt was accepted (agent connected), and node-b was ready again with the same id.
  6. Management works. A new deployment of third succeeded (release 2), and its route moved to the new container.

Note: the first refusal came from the open stream's per-second credential check, which this PR leaves as it was. The certificate was therefore recorded at the agent's next connection, 5 minutes later. In a real restore the control plane restarts, so every agent opens a new connection and goes through the recording path at once.

@samuelmbabhazi
samuelmbabhazi merged commit 53eb186 into main Nov 26, 2026
27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/487-readopt-restored-servers branch November 26, 2026 14:56
samuelmbabhazi added a commit that referenced this pull request Nov 26, 2026
… a password (closes #487) (#519)

## What changed

The second part of #487: the Servers page offers the re-adoption that
#518 added to the API.

- **`sk-node-readoptions`**: a card under *Agent upgrades*, hidden while
nothing waits.
- It lists each server whose certificate the gateway refused after a
restore, with its name, since when it is refused, and until when its
certificate is valid.
- **Re-adopt** opens a password and authentication-code form, the same
proof as a join token. On success the card says the server connects
again within 5 minutes, and the server list is refreshed.
  - A refused proof keeps the server listed, with the runner's error.
  - Changing organization clears everything.
- **API client:** `FleetApi.readoptions` and `FleetApi.readopt`.
- **French translations.**
- **INSTALL.md** now describes the step on the Servers page.

## Why

Closes #487. An administrator recovers a restored server from the page
they manage servers on, not with an API call.

## How it was tested

- **Unit tests** in `node-readoptions.spec.ts` (4 tests):
  - nothing is shown while no server waits;
- the waiting server is named, the button stays disabled until a
password is typed, and the code is trimmed. The call carries the
organization, the node and the proof, the success text shows, and the
list refreshes;
- no empty `totp` is sent, and a refused proof keeps the server listed
with no success;
  - another organization clears the card.
- **Full web suite:** 59 files, 371 tests. Web lint and typecheck pass.
- **Real lab** (run28, the #518 control plane with this production
bundle, in Chromium):
  - A simulated restore made the gateway record `node-b`'s certificate.
  - The card listed it in English and French, on desktop and mobile.
- **Re-adopt node-b** with the owner's password showed `node-b is
re-adopted: it connects again within 5 minutes.`, and the list emptied.

Screenshots are in the review page linked in the conversation. **This
changes the UI: it waits for the maintainer's validation before merge.**

## Security considerations

No new capability: the page calls the routes of #518, which check
`node.manage`, the password and second factor, and audit the
confirmation. The password field uses `autocomplete="current-password"`
and is cleared after each attempt. The certificate serial is not shown.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Added a Servers page workflow for re-adopting servers with
unrecognized certificates. Administrators can re-adopt a server using
their password and, when required, a TOTP code.
* The server list refreshes after a successful re-adoption, and the
server’s name is shown.
* **Bug Fixes**
* Failed server-list loads can be retried, and existing server entries
remain visible if a reload fails.
* **Documentation**
* Updated restore instructions to explain how to re-adopt servers from
the Servers page.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: samuel mbabhazi <[email protected]>
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