Skip to content

7d. Move a host's configuration to another host (0.30.0)

Rebuilding a host, moving to a bigger box, or standing up a staging twin used to mean recreating every account, secret, notifier and registry login by hand. pull config seals the whole lot into one file; push config applies it somewhere else.

Terminal window
# on the host you are copying FROM
export PSTACK_API_URL=https://api.preview.example.com
export PSTACK_TOKEN=…
pstack pull config -o host.sealed # asks for a passphrase, twice
# on the host you are copying TO
export PSTACK_API_URL=https://api.staging.example.com
export PSTACK_TOKEN=… # ITS root token, not the first host's
pstack push config -i host.sealed # asks for the same passphrase

host.sealed is written 0600, and it is a scrypt + AES-256-GCM envelope sealed on your machine — never on the server, because sealing server-side would mean sending the passphrase to the server, which is strictly worse. The passphrase comes from PSTACK_CONFIG_KEY, or is prompted for without echo. There is no passphrase flag on purpose: argv is world-readable through ps.

The advanced UI has an Apply config page: pick the sealed file, type the passphrase, press Preview to see what the file will make this host trust, then Apply. It posts to POST /api/config/sealed and needs an admin — a session is enough.

It can apply a config and cannot produce one, on purpose. Export is exfiltration: one request and every credential on this host is in the caller’s hands, so GET /api/config refuses a browser session and answers only to the PSTACK_TOKEN bearer. A download button would mean an XSS, a borrowed laptop or a stolen cookie yields the lot in one click. Import runs the other way — whoever uses that page must already hold the file and its passphrase, so it shows them nothing they could not read for themselves.

That asymmetry is also why the passphrase is sent to the server here while pull config keeps it local: every secret in the file is about to be plaintext on this host anyway, so there is nothing left for it to protect from this host. It is used once and never stored.

Preview exists because this is the widest-reaching write in the API — a config can create an administrator and choose where the host pulls its images from — and a browser has no equivalent of the CLI’s confirmation prompt unless the server offers it one. Nothing is written until you have seen the list.

PSTACK_API_URL has no default. A guess would silently talk to the wrong host, and this is the one command where the payload is every credential you have. Plain http:// is refused unless the host is loopback or a private address, for the same reason.

What travels, and what deliberately does not

Section titled “What travels, and what deliberately does not”
Travels Stays behind
accounts, with their password hashes — people keep the passwords they already have deployments: they are per-PR and ephemeral, and belong to the host’s Docker. pstack migrate moves them (7f)
API tokens (hashes), so scripts keep working — and a document you author may name the token itself login sessions and half-finished SSO sign-ins
host variables and secrets notifier delivery history
notifiers, with their signing secrets and URLs terminal sessions
the SSO providers and their client secrets Loki’s settings and its S3 secret
registry logins, routing files, named specs forwarding: applied to the host it points at, it would forward to itself

Restoring the right-hand column into a different host would be wrong, not merely useless — so none of it is in the file. Only Loki’s settings and forwarding are named, in skipped: re-enter them on the target.

Predeclaring the tokens a rebuilt host should hold (0.34.0)

Section titled “Predeclaring the tokens a rebuilt host should hold (0.34.0)”

A migration already preserves API tokens. They travel as SHA-256 digests, which is what the tokens table stores anyway, so every script and CI secret holding one keeps working on the other side without anything being re-issued. That is the round trip, and it needs nothing from you.

The other direction is a document nobody exported — one you author, declaring the credentials a rebuilt host should come up holding. A token row may name the token itself instead of its digest:

{
"version": 1,
"users": [{ "username": "ci", "role": "developer", "passwordHash": "$argon2id$…", "createdAt": 1 }],
"tokens": [{ "username": "ci", "name": "pipeline", "token": "pstack_pat_…", "createdAt": 1 }]
}

token is hashed on apply with the same function that mints one, so the value authenticates exactly as an issued token would. A row may carry either token or tokenHash; carrying both with different values is refused rather than guessed at, and named in the skip list.

Three things to know before you use it:

  • A token belongs to an account. There is no host-wide machine token but PSTACK_TOKEN (below), so the document must create — or the host must already have — the user the token is for. The token inherits that account’s role, and follows it: promote the account and every token it holds is promoted with it.
  • An export never emits token. The host does not have the plaintext to emit; that is the point of storing a digest. Round-tripping an export is still hash-only.
  • pull config’s pre-write summary calls it out — “carried in PLAINTEXT, so whoever wrote this file holds it” — because a digest proves nothing about its author and a plaintext token proves they hold the credential. Seal the file (push config requires it) and treat it as the secret it is.

PSTACK_TOKEN is not one of these and cannot be a list. It is a single value, compared directly, and it is also the HMAC key share links are signed with — which is what makes rotating it the only way to revoke every outstanding link. A second accepted value would silently break that, so per-machine credentials are personal tokens, named and individually revocable, not extra root ones.

/api/config answers for the root token and nothing else. An admin browser session gets 403, and so does an admin’s personal API token — the two credentials the UI hands out. The cost is deliberate and permanent: there is no button for this in the UI and there should never be one. A full credential dump reachable from a cookie means one XSS, or one stolen laptop with a live session, empties the host from the victim’s own browser.

Both directions emit an event — config.exported and config.imported — so a credential dump reaches your notifiers instead of happening silently. The payloads carry counts and identities (which registries, which notifier names), never contents.

Everything is matched by its natural key — username, variable name, notifier name, registry host — and anything already on the target is skipped, not updated:

created user alice
created secret DB_PASSWORD
created notifier "ops"
created registry ghcr.io as bot

Run it again and every line becomes a skipped with the reason:

skipped user alice: an account with that name already exists here
skipped registry ghcr.io: a credential for it is already stored here

So this is a merge onto a host, not a restore over one: to change a value that is already there, change it the normal way afterwards. Applying the same file twice creates nothing the second time, which is also the repair procedure — apply is not transactional. A step that fails part-way leaves whatever it had already written, so if push errors, fix the cause and run it again; the entries that landed the first time are simply skipped.

Before it writes anything, push names every registry and notifier URL the file would make this host trust, and asks:

Applying host.sealed would make this host trust:
- pull images from ghcr.io as bot
- send slack notifications to webhookUrl=https://hooks.slack.com/services/… ("ops")
Apply it? [y/N]:

Those strings are credentials, so they are printed to a terminal only. With -y, or anywhere stderr is a pipe, you get a count instead and the list never reaches a log file. -y is also mandatory when there is no terminal to ask: push will not apply a file unattended without it.

pstack cloud-init can carry the export into a first boot:

Terminal window
pstack cloud-init --domain … --acme-email … --config host.sealed # embed the file
pstack cloud-init --domain … --acme-email … --config-url https://… # fetch it at boot

Both need PSTACK_CONFIG_KEY set when you render, because the machine being provisioned is what has to open the file. That is the tension, and the rendered file states it in its own SECRETS header rather than papering over it:

  • --config puts the sealed export and its passphrase in the same file, which your provider stores as instance metadata. The seal protects that export everywhere except exactly there.
  • --config-url embeds only the passphrase. Opening the export then needs the metadata and access to the URL — the combination that actually buys something. Serve it from somewhere only the new host can reach, and take it down afterwards.

The apply runs as the last boot step, after init, reaching the API on the control container’s Docker bridge address rather than https://api.<domain> — this early in a first boot your DNS may not have propagated and Traefik may hold no certificate, and a config that silently failed to apply is the one outcome that step must not have. It reads PSTACK_TOKEN out of control/.env itself, so that token is not carried in the file. The sealed copy is deleted whether the apply worked or not, and a failure shouts in the boot log rather than leaving you with a host that looks finished.

Two risks come with the feature itself. Neither is a bug, and neither goes away.

  1. A leaked export is offline-crackable against every account. It contains argon2 password hashes for every user on the host — that is why logins keep working after a move. Someone who gets both the file and the passphrase does not need to crack anything; someone who gets only the file can grind at the hashes with no rate limit and nobody watching. Keep the file and the passphrase apart, commit neither, and delete the file when the move is done. Rotate the source host’s credentials if you cannot account for a copy.
  2. push writes registry credentials, which is to say a config file decides where a host pulls its images from — and its notifiers decide where that host’s events are sent. A file you did not produce yourself can repoint both. That is what the pre-write summary above is for; read it, and do not pipe -y at a file whose origin you cannot name.