zrizDocsLearnSecuritySign inSign up

Test a database in a private network

Put a zriz runner inside the network. It makes outbound connections only, so you open no port. The work is done when a run on the runner has status pass.

Draft. Guide · zz 0.4.0 or later · Updated · Plain text for agents: /docs/test-private-database.md

The runner reaches the database, and the internet does not. Which connections does the runner make? gives the rule.

The connection string stays in the config of the runner. The example is for Postgres.

Before you start

1. Deploy a runner in the network

Do

Do the guide Deploy a zriz runner with Docker on a host that can reach the database. Then come back.

The guide ends with a run of the sample on the runner. Keep its token, its file config.json, and the name of its environment.

zz runners

Why

The host needs outbound HTTPS to https://zriz.io and a route to the database. It needs no inbound rule.

You should see

{"ok":true,"command":"runners",
"connected":true

If not

2. Add the database to the runner

Do

On the host of the runner, add one resource to resources of config.json. Keep the other keys as they are.

config.json:

{
  "cloud": { "url": "https://zriz.io", "token-env": "ZRIZ_RUNNER_TOKEN" },
  "resources": {
    "target": { "type": "http", "base-url": "<base url>" },
    "<db>": {
      "type": "sql",
      "connection": "postgres://<user>:${DB_PASSWORD}@<host>:5432/<database>",
      "read-only": true
    }
  }
}

The runner reads the config at its start. Start it again, with the password in its environment:

docker rm -f zriz-runner
docker run -d --name zriz-runner \
  -e ZRIZ_RUNNER_CONFIG=/config/config.json \
  -e ZRIZ_RUNNER_TOKEN=<token> \
  -e DB_PASSWORD=<password> \
  -v "$PWD/config.json:/config/config.json:ro" \
  zriz-runner
docker logs zriz-runner

Why

The runner calls only the resources that its config names. It fills ${DB_PASSWORD} from its own environment, so the password is in no file.

You should see

runner connected

If not

3. Write the test

Do

Do this step in the folder of your service. Make a resource file with the same id, and one pipeline that reads the database.

A resource file must have the key connection. zz removes it before a run, and the runner uses the connection of its own config. Thus DB_URL needs no value.

.zriz/resources/<db>.json:

{
  "type": "sql",
  "connection": "${env.DB_URL}",
  "read-only": true,
  "actions": {
    "ping": { "query": "select 1 as ok" }
  }
}

.zriz/pipelines/db-ping.json:

{
  "description": "The runner reaches the database",
  "steps": [
    { "call": "<db>/ping", "expect": [["row-count", "==", 1]] }
  ]
}
zz validate db-ping

Why

The files in the repository name the query and the check. They hold no host and no password.

You should see

{"ok":true,"command":"validate",

If not

4. Run the test on the runner

Do

zz run db-ping --env <env>

Why

zz run needs a runner that serves the environment of the run. The runner is in your network, so the query comes from inside it.

You should see

"status":"pass"

If not

Next