Skip to content

feat(deploy): the control plane on a single machine, Compose side (part of #377) - #381

Merged
samuelmbabhazi merged 4 commits into
mainfrom
feat/377-compose
Nov 20, 2026
Merged

samuelmbabhazi merged 4 commits into
mainfrom
feat/377-compose

Conversation

@samuelmbabhazi

@samuelmbabhazi samuelmbabhazi commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Part 4 of #377 (ADR 0021): the Compose side of the single-machine form.

What changed

  • TRUST_PROXY accepts a third form, one IP address (IPv4 or IPv6), besides none and loopback. Ranges, lists, keywords such as uniquelocal and anything with spaces are refused at startup.
  • deploy/control-plane/compose.single-machine.yml, an override used with compose.yml (docker compose -f compose.yml -f compose.single-machine.yml up -d):
    • no Caddy of its own (caddy gets a profile nobody enables): the server's Caddy owns 80 and 443 and reaches the control plane through the route the agent keeps (feat(agent): the control plane's route on the machine that hosts it (ADR 0021, part of #377) #378);
    • the control plane's HTTP port published on 127.0.0.1:3000 only, the agent gateway on every address;
    • a fixed subnet, 172.31.250.0/24, whose gateway 172.31.250.1 is the only trusted proxy;
    • PostgreSQL, the API, their shared namespace (net) and the one-shot steps in shipkeep-controlplane.slice; PostgreSQL, the API and net with oom_score_adj -900.
  • The bundle ships the override. compose.yml alone is unchanged, so two-machine installations and their upgrades are not affected.
  • SPEC 8 describes the third TRUST_PROXY form.

Why

ADR 0021 needs the control plane to run without its own Caddy, to be reachable only through the server's Caddy, and to trust forwarding headers from that path only.

How it was tested

  • docker compose ... config (Compose 2.40) on the merged files: services without caddy; ports 127.0.0.1:3000 and 7443; slices and adjustments as listed; the subnet and gateway; TRUST_PROXY 172.31.250.1.
  • Lab on a disposable node (Docker 29.10, systemd cgroup driver, cgroup v2), with a service that echoes its client on a network with this subnet, published on 127.0.0.1:3000:
    • from the host's loopback, the service sees 172.31.250.1 as its client, with Docker's userland proxy on and with it off, which the ADR asked to check;
    • through the server's Caddy, a request carrying X-Forwarded-For: 6.6.6.6 arrives with X-Forwarded-For: 127.0.0.1: Caddy replaces the forged value, so the API records the real client;
    • from an application container on another Docker network, the service's container address, the bridge gateway on port 3000 and the container's own loopback on port 3000 are all unreachable.
      The node was restored (its daemon.json, the lab network and container removed) afterwards.
  • config.schema.spec.ts: the accepted and refused TRUST_PROXY values. api:lint, api:typecheck: green.

Security considerations

Forwarding headers are trusted from one address, which only the host's processes reach through a loopback-only port; the server's Caddy overwrites them. A range or list cannot be configured by mistake. Not yet used by any installer: the installer's single-machine form is the next part.

Summary by CodeRabbit

  • New Features
    • Added a single-machine deployment option for running the control plane and applications together.
    • Deployment bundles now include the single-machine configuration.
    • Proxy trust settings accept none, loopback, or one valid IP address; the default remains none.
  • Documentation
    • Documented the trusted proxy address for single-machine deployments.
  • Tests
    • Added coverage for accepted and rejected proxy trust settings.

TRUST_PROXY accepts none, loopback or one IP address, never a range or a list: the gateway through which the server's Caddy reaches the API on a single machine (ADR 0021).

Signed-off-by: samuel mbabhazi <[email protected]>
…chine

No Caddy of its own, HTTP on loopback only, a fixed subnet whose gateway is the trusted proxy, the control plane's containers in shipkeep-controlplane.slice and PostgreSQL, the API and their namespace at oom_score_adj -900 (ADR 0021). Shipped in the bundle; compose.yml alone is unchanged.

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

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The API now accepts a single IP address for TRUST_PROXY and passes configured values to Express. A new single-machine Compose override configures service ports, proxy trust, resource controls, and networking. The deployment bundle includes the override.

Changes: Single-Machine Control Plane

Layer / File(s) Summary
Proxy trust configuration
apps/api/src/platform/config/config.schema.ts, apps/api/src/bootstrap.ts, apps/api/src/platform/config/config.schema.spec.ts
TRUST_PROXY accepts none, loopback, or one valid IP address. The API passes configured values other than none to Express. Tests cover the default, accepted values, and rejected values.
Single-machine Compose override
deploy/control-plane/compose.single-machine.yml, deploy/control-plane/build-bundle.sh, deploy/control-plane/install_test.sh, docs/SPEC.md
The override configures service ports, proxy trust, resource controls, the Caddy profile, and the default network. The deployment bundle includes the override, and the install test checks for it. The specification documents its trusted gateway address.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Possibly related issues

Possibly related PRs

Suggested reviewers: iyuzhang

Merge Risk: Minimal · up to 84bcf

This change lets the API trust a single proxy IP and adds a single-machine Compose override that is included in the release bundle. No actionable merge-blocking issue was found, and the default proxy behavior is unchanged.

Security architecture risk: Low · up to 84bcf

The single-machine option deliberately increases the consequences of an application escaping to the host, because the control plane and its secrets now share that machine. HTTP remains loopback-only, proxy trust is restricted to one address, and existing two-machine deployments are unchanged. No new public authentication bypass was established.

Retained concerns

  • Low · security · inferred: The opt-in topology places applications beside the control plane. An application escape to the host can consequently expose the control-plane database and key-encryption key, rather than remaining confined to a separate workload machine. This is the explicitly accepted deployment tradeoff, not evidence of an escape vulnerability; ordinary application access is still constrained by container and network boundaries.
Security review details

Security Blast Radius

  • inferred — The changed containment scope is one opted-in installation. A workload escape that compromises its shared host can also compromise the control-plane database and KEK, potentially affecting every organization managed by that control plane. This requires crossing the container-to-host boundary; the PR does not demonstrate such an escape.

Security Findings and Attack Paths

  • inferred — Gateway-address trust authenticates a network path, not the Caddy process. Another host-local process can connect to the loopback publication; if Docker presents it as the trusted gateway, its forwarding headers can influence IP-based limits and attribution. This is a host-local trust assumption, not an established Internet attack path. Managed application creation does not permit selecting the declared control-plane default network.

Trust Boundaries and Controls

  • observed — The new trust grant is restricted to one configured IP, not the whole bridge subnet. Local-route configuration requires a loopback upstream. The agent’s control-plane routes use reserved identifiers and are placed before application routes.

Resilience and Maintainability Implications

  • observed — Existing route repair is serialized with other route changes, replaces the route list in one request, preserves unrelated routes, and retries failures with bounded attempts. These controls support the new topology’s ingress ownership during repetition and recovery, but do not prove effective behavior during a live Compose topology conversion.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: adding Compose configuration for running the control plane on a single machine. The changeset adds deploy/control-plane/compose.single-machine.yml, which configures th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: adding Compose configuration for running the control plane on a single machine. The changeset adds deploy/control-plane/compose.single-machine.yml, which configures that deployment, and it adds the single-IP TRUST_PROXY form the override depends on. The title also says the change is the Compose side, which matches the objectives: the installer does not yet use this form. The '(part of #377)' reference is accurate context, not noise, and the length is acceptable. The title is specific, clear, and related to the main change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7e9700c and 84bcff5.

Files selected for processing: 1

  • docs/SPEC.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@samuelmbabhazi
samuelmbabhazi merged commit e2c055a into main Nov 20, 2026
22 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/377-compose branch November 20, 2026 12:03
samuelmbabhazi added a commit that referenced this pull request Nov 20, 2026
Parts 5 and 6 of #377 (ADR 0021): the installers' single-machine form,
and its docs. Stacked on #381 (the Compose override).

## What changed

**Control plane installer** (`deploy/control-plane/install.sh`):
- Asks *Run applications on this machine too?* (default yes;
`--single-machine yes|no`), and with yes the first organization's name
(`--organization`).
- Checks before anything: 2 CPUs, 3 GiB, cgroup v2 with
`memory_recursiveprot`, port 3000 free; after Docker is installed, the
`systemd` cgroup driver.
- Creates `shipkeep-controlplane.slice` (`MemoryLow` = the reservation),
runs Compose with `compose.single-machine.yml`, creates the first
account, then the organization (`organization create`), reads the CA
fingerprint (`server ca-fingerprint`), takes the agent and the server
installer **from its own image** (`/app/web/browser/install`, each
checked against the image's manifest), and runs the server installer
with the join token piped from `server join-token`, never shown or
stored by this script.
- Waits for HTTPS through the server's Caddy (via the network gateway),
and points at `journalctl -u shipkeep-caddy` and at both compose files
in its messages.

**Server installer** (`deploy/install.sh`):
- `--local-control-plane 127.0.0.1:<port>` and `--agent-file <path>`
(still checked against the pinned SHA-256).
- Same machine checks; the agent's configuration gets `connect`,
`route`, `reservation`, `workloads_slice` and `workloads_oom_score_adj`
1000; `shipkeep.slice` gets `MemoryLow`; `shipkeep-workloads.slice` gets
`MemoryMax` = memory − reservation and `CPUWeight` 50.

**Docs**: `INSTALL.md` (One machine for everything), threat model D4,
ARCHITECTURE.

## Why

ADR 0021: one rented server is enough to install Shipkeep and deploy to
it.

## How it was tested

- `deploy/install_test.sh` and `deploy/control-plane/install_test.sh`:
the new checks (mounts, meminfo, the local address, the slice unit,
yes/no answers, organization names and slugs), refused options stop
before anything changes and never show the token, both installers carry
the same reservation values. ShellCheck clean.
- **End to end, on a fresh Ubuntu 24.04 with systemd and no Docker**
(privileged container, nested Docker 29.10, cgroup v2), with a bundle
built from these branches and the image pulled by digest from a TLS
registry; the installer driven through a real terminal with the default
answers:
- Docker, the control plane, the first account, the organization and
this server installed in one run; the password never appeared in the
output. The agent enrolled over `127.0.0.1:7443` (one retry while Docker
restarted for the egress proxy).
- Caddy owns 80 and 443; the API listens on `127.0.0.1:3000` only; the
control plane's route is first in Caddy.
- `shipkeep.slice` and `shipkeep-controlplane.slice` `memory.low` = 1
GiB; `shipkeep-workloads.slice` `memory.max` = memory − 1 GiB, CPU
weight 50; PostgreSQL, the API and `net` in
`shipkeep-controlplane.slice` with `oom_score_adj` -900; Docker in
`shipkeep.slice`.
- The node reports `reserved_cpu_millis` 500 and `reserved_memory_bytes`
1 GiB. A deployed application runs in `shipkeep-workloads.slice` with
`oom_score_adj` 1000, pulled through the egress proxy.
- A 16 GiB application deployed; its redeployment refused before
anything started with *the old and the new release do not fit together
beside the control plane reservation…*, the old release still serving.
- A login carrying `X-Forwarded-For: 6.6.6.6` recorded the real client
address, not the forged one nor the internal gateway.
- From the application's network, port 3000 of the control plane is
unreachable by every address (its container, both gateways, loopback).
- After `DELETE /config/apps/http` in Caddy, the route was back in 12 s;
after a reboot of the machine, every service, the route, the slices and
scores, and both applications came back, node ready.
- The `.test` name gets no public certificate, so the installer ends
with its certificate message, as in earlier labs; the rest of the run
used an internal TLS policy added to the lab's Caddy.

## Not tested

Memory pressure (the kill order and `memory.low` under reclaim) and a
public certificate: the lab machine shares the host's memory, and a
`.test` name has no certificate. Both need the test VM (#200).

## Security considerations

The join token goes from one command to the other through a pipe, never
on a terminal or in a file of the installer. The agent and the server
installer come from the control plane image the bundle pins by digest,
and are checked against its manifest; the server installer still checks
the agent's SHA-256. The installer refuses the single-machine form on a
machine where memory protection would not work, rather than install it
half-protected. The threat model says that a single machine shares a
kernel and recommends two machines for untrusted code.


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

## Summary by CodeRabbit

* **New Features**
* Added an option to install the control plane and workloads on one
machine, with resource reservations and deployment-fit checks;
separate-server installations remain available.
* Interrupted installations can resume from incomplete steps while
preserving the organization identity.
* Organization creation can reuse a specified ID, returning the existing
organization when its details match and rejecting conflicts.
* **Bug Fixes**
* Installation now validates required files and system prerequisites
before setup.
* **Documentation**
* Updated installation, architecture, and security guidance for
single-machine setup, troubleshooting, and teardown.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: samuel mbabhazi <[email protected]>
samuelmbabhazi added a commit that referenced this pull request Nov 22, 2026
…machine check remains (#415)

Part of #413.

## What changed

Step 1 of the first stable version (#377, the single-machine
installation of ADR 0021) said it waited for nothing. In fact its code
and docs were merged on 2026-11-20 in #378, #379, #380, #381 and #382,
as the last comment on #377 says. Only the ADR's last acceptance
criterion remains: a real machine with a public name and certificate.

- Step 1 now says that, and points to step 5.
- Step 5 lists #377 with the other real-machine checks.

## How it was tested

Prettier check. Documentation only.

## Security considerations

None: documentation only.

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

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Documentation**
* Clarified that step 1 covers single-machine installation and requires
step 5 to complete real-machine acceptance.
* Added issue `#377` to step 5 and identified it as a prerequisite for
step 1 acceptance.

<!-- 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