Deploy a zriz runner
A runner calls your resources from inside your network. zz has one inside for http and sql. Deploy one for browser and cli, or for a shared env.
Do you need one?
The runner is open source: ZrizTech/runner.
For http and sql, no. zz run starts the runner of zz when no deployed runner is connected. It needs no Docker.
Deploy a runner when the app or the database is not reachable from the computer that runs zz. Also deploy one for a shared env, or for browser and cli resources.
How it connects
The runner makes outbound connections only: to https://zriz.io, and to the resources in its config. Nothing listens. You open no port.
Deploy one binary
This shape is for http and sql. It needs no Docker.
- Make the files on a computer with zz:
zz runners init --env <env>. It writesconfig.json,runner.envandzriz-runner.service. - Copy the files to the server with this line:
sudo mkdir -p /etc/zriz-runner && sudo install -m 644 config.json /etc/zriz-runner/config.json && sudo install -m 600 runner.env /etc/zriz-runner/runner.env && sudo cp zriz-runner.service /etc/systemd/system/
- On the server, run
sudo sh install.shfrom the runner release. Then runsudo systemctl enable --now zriz-runner.
zz runners init --env staging
To upgrade, run install.sh again and restart the service: sudo systemctl restart zriz-runner. Then zz runners shows the runner as connected.
Deploy with Docker
This shape is for browser and cli. It has two containers, the runner and the worker. The worker holds no secret.
zz runners init writes config.json, runner.env and compose.yml when the project has a browser or cli resource. On a local computer, add --start to start them.
zz runners init --env staging --start
On a server, copy the files and run docker compose up -d. A browser resource takes its URL from the env value <RESOURCE>_URL. A localhost host becomes host.docker.internal.
The config
The config holds the names of secrets, not their values. Put each value in runner.env.
config.json:
{
"cloud": { "url": "https://zriz.io", "key-env": "ZRIZ_RUNNER_KEY" },
"resources": {
"shop": { "type": "http", "base-url": "https://staging.shop.example", "secrets": ["SHOP_API_KEY"] },
"shop-db": { "type": "sql", "connection": "postgres://app_ro:${SHOP_DB_PASSWORD}@db.example:5432/shop", "read-only": true }
}
}
- The
resourcesmap is the allowlist. The runner calls no other target. ${NAME}is filled from the environment of the runner.cloud.urlmust behttps.- All the projects of an org share its runner. A resource id must be unique in the org.
- A resource file in
.zrizstill needs the keyconnection. zz removes it before a run.
A read-only Postgres user
Use a role that can read and cannot write. Run these statements as the owner of the tables. <user> and <schema> are yours.
create role <user> login password '<password>';
grant connect on database <database> to <user>;
grant usage on schema <schema> to <user>;
grant select on all tables in schema <schema> to <user>;
alter default privileges in schema <schema> grant select on tables to <user>;
Prove it: an insert as this role must fail with permission denied for table. Also set "read-only": true on the resource.
Revoke a runner
zz runners revoke <name> revokes the key of a runner. The page /app/runners shows each runner and each key.
To change a key, revoke the runner and run zz runners init again. The key is ZRIZ_RUNNER_KEY.
When it fails
runner-unavailable: Onlybrowserandclineed a deployed runner with Docker. Runzz runners init --start.poll refused: The cloud refused the key. The runner writes one error line and waits, with no restart loop. Revoke the runner and runzz runners initagain.poll failed: The runner cannot reachhttps://zriz.io. Permit outbound HTTPS.missing environment variable: A${NAME}of the config has no line inrunner.env.
Security gives the rules that the runner obeys.