Skip to content

fix(deploy): --migrate brings an earlier server to the guarded layout (closes #490) - #516

Merged
samuelmbabhazi merged 4 commits into
mainfrom
fix/490-installer-migrate
Nov 26, 2026
Merged

samuelmbabhazi merged 4 commits into
mainfrom
fix/490-installer-migrate

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

The second half of #490. deploy/install.sh --migrate yes brings a server set up by an earlier version of the installer to the current layout, in place. It keeps the node's identity and credentials, its journal, its containers and volumes, and Caddy's configuration and certificates. The first half, shipkeep-agent adopt-routes, merged in #514.

Recognized layouts, checked before any change

  • The shipkeep, shipkeep-caddy and (optional) shipkeep-egress accounts and groups.
  • The agent's directories, owned by shipkeep.
  • The agent and Caddy units, byte for byte as an installer wrote them: the 0.1.0-alpha.1–alpha.3 agent unit (legacy_agent_unit) or today's, and no drop-in on either.
  • An agent.yaml for the control plane and CA of the command being run, and not a control plane machine's.
  • No pending agent upgrade, port 7480 free (or held by the egress proxy), and Docker API 1.47.
  • Anything else is refused with what to reconcile. A control plane machine, and the --local-control-plane, --agent-file and --control-plane-only options, are refused too: those installs already have the current layout.

Steps. Each step leaves a server that runs, and an EXIT trap starts the agent again whatever stops the run.

  1. Download and verify the agent the control plane serves (the same pin as a fresh install). Validate the existing agent.yaml with it.
  2. Create the shipkeep-egress account and the root-owned guard copy.
  3. Stop the agent and run adopt-routes as shipkeep.
    • Any refused route stops the migration with the agent restarted as it was. The message says to deploy those applications again.
  4. Install the new binary (rename), then the guarded unit (rename): binary first, since the unit waits for a READY that old agents never send. Start the agent.
  5. install_egress.
    • It now skips the Docker restart when Docker already runs in the slice behind the proxy and its guard, and only reloads the guard. A second run therefore changes no container.
    • Docker's restart restarts the agent, and the installer waits up to 2 minutes for it.

Texts

  • The agent's refusal now reads the agent's service predates upgrades: run the server installer with --migrate yes. The control plane still maps the old text, which agents of alpha.4–alpha.7 send.
  • A deployment refused by the egress check says to run the server installer again with --migrate yes, which does restore the proxy (tested below). French translation updated.
  • A fresh install that finds an existing one now points to --migrate yes.

Docs: INSTALL.md (Upgrade), ADR 0028, SPEC 3.4's reason table, and deploy/README.md (acceptance step 6).

Why

Closes #490. The documented recovery was to run the installer again, which refuses any existing installation, and the only alternative was a full reinstall.

How it was tested

Real lab (run28, Ubuntu 24.04 systemd containers with their own Docker):

  • Control plane. The published, cosign-verified v0.1.0-alpha.7 bundle, switched to this branch's image. Lab-only changes:
    • The image's agents are stamped 0.1.0-alpha.6 and the control plane announces 0.1.0-alpha.7, so that Upgrade agents targets the real signed release.
    • Caddy uses tls internal, because .test names never get a public certificate.
  • Server. Installed with the original v0.1.0-alpha.3 install.sh and the published alpha.3 agent, its checksums.txt cosign-verified. Two whoami applications (hello, world), each with a domain.

What the lab showed:

  1. The danger, without migrating. One Docker restart swapped the two containers' addresses. hello.shipkeep.test then answered from world's container and vice versa, and the alpha.3 agent never corrected it.

  2. Migration on that server: refused.

    • Output: routes: 0 already followed, 0 adopted, 2 refused with other_application for both, and exit 1.
    • The alpha.3 agent was active again, with the unit and Docker unchanged.
  3. Both applications deployed again, as the message says, then the same command.

    • Output: 2 adopted and Migrated (from the legacy layout).
    • Agent 0.1.0-alpha.6 runs under the guarded unit. Docker is in shipkeep.slice with the guard table loaded, and reports HttpProxy/HttpsProxy http://127.0.0.1:7480 and an empty NoProxy.
    • Docker's restart moved hello from .4 to .2 and world from .5 to .3. Each route followed its own container: each domain answered with its own application's hostname.
    • Kept: the same node id, ready, and credentials.json and agent.yaml byte-identical. The journal kept every operation (24) and gained one route record per application.
  4. Run again: 2 already followed, Migrated (from the current layout), and Docker's start time unchanged.

  5. Upgrade agents to 0.1.0-alpha.7 from the control plane.

    • The migrated agent downloaded and verified the real release and swapped its binary, and the guard counted the start.
    • Log: upgrade confirmed, version 0.1.0-alpha.7 (commit 4ef57df). The rollout ended succeeded, and both routes were still right.
  6. Interruptions, on a second fresh alpha.3 server with one pinned application. Four lab copies of the installer sent themselves SIGTERM at each boundary:

    • (a) routes recorded, agent stopped;
    • (b) new binary, old unit;
    • (c) guarded unit started, Docker not behind the proxy;
    • (d) proxy running, Docker not restarted.

    After each, the agent was active (alpha.3, then the new one under the old unit, then under the guarded unit), no temporary file was left, and the route served its application. The next run went on from there.

  7. The final run found a race, which is fixed in the last commit. It exited 1 with "The agent did not come back after Docker": Docker's restart restarts the agent, and the check read it while it was activating. The installer now waits.

    To retest the exact case, I removed Docker's egress drop-in on that server, which is also the egress_unguarded case, and restarted Docker out of the slice. --migrate yes then exited 0: Docker was back behind the proxy, the agent active, and the route right.

Local checks

  • bash deploy/install_test.sh passes. It adds migration checks:
    • The legacy unit equals today's without the five guard lines, and its hash is the one all three releases wrote.
    • Edited, changed, commented, linked and missing units are refused.
    • The configuration check refuses another address, port or CA, a control plane machine, double quotes, a link and a missing file.
    • A bad --migrate value or combination is refused before anything else, and never shows the token.
    • Mutation checks: dropping the role check, or changing a unit line, fails them.
  • shellcheck is clean.
  • Go tests for agent/internal/actions pass, as do api:lint, api:typecheck and the touched API specs.

Security considerations

  • No new privilege. The migration runs only as the operator's sudo, from the checksum-verified command the control plane shows. It installs only the agent binary pinned in that command.
  • Strict layout match. It refuses anything it did not write, so it never takes over an unrelated service. It also refuses a configuration for another control plane.
  • Routes. It never records a route whose traffic already goes elsewhere: that is adoption's rule (feat(agent): adopt-routes records the routes older agents left unrecorded (part of #490) #514), and the lab showed it refusing two crossed routes.
  • Remaining window. From Docker's restart to the new agent's first pass (seconds), routes hold the old addresses. That is the same window a reboot of any current server has (ADR 0017).
  • Agent action list unchanged.

@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 59 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 83a2d76 and 16e5d8d.

Files selected for processing: 14

  • agent/internal/actions/dispatcher.go
  • agent/internal/actions/upgrade_test.go
  • apps/api/src/modules/deployments/domain/pipeline.spec.ts
  • apps/api/src/modules/deployments/domain/pipeline.ts
  • apps/api/src/modules/fleet/domain/agent-action.spec.ts
  • apps/api/src/modules/fleet/domain/agent-action.ts
  • apps/web/src/app/delivery/agent-action-rows.spec.ts
  • apps/web/src/app/ui/fr.ts
  • deploy/README.md
  • deploy/install.sh
  • deploy/install_test.sh
  • docs/INSTALL.md
  • docs/SPEC.md
  • docs/adr/0028-agent-and-control-plane-upgrades.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
samuelmbabhazi merged commit 3399cca into main Nov 26, 2026
27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/490-installer-migrate branch November 26, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide an upgrade-guard migration for existing agent installations

1 participant