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.

Draft. Guide · zz 0.9.0 or later · Updated · Plain text for agents: /docs/runner.md

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.

  1. Make the files on a computer with zz: zz runners init --env <env>. It writes config.json, runner.env and zriz-runner.service.
  2. 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/
  1. On the server, run sudo sh install.sh from the runner release. Then run sudo 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 }
  }
}

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

Security gives the rules that the runner obeys.