Skip to content

Environments, vars and secrets

Each cluster is one environment, such as production, test or staging, with its own database. Packages read the values that differ between environments as vars and secrets. A cloud’s address and an API key are examples. You change them while the cluster runs. This page covers naming an environment and setting its values. Promoting the setup covers copying a tried setup from one cluster to another.

There are no environments inside a cluster (per port or per endpoint). Production and test instances never share a database.

Variable
HOURADVANTAGE_ENVIRONMENTThe cluster’s name, free text: production, test, staging.
HOURADVANTAGE_PRODUCTIONtrue (or 1, yes) marks a production cluster. false (or 0, no, empty, unset) does not. Case does not matter. Any other value stops the instance at startup.

Give every instance of a cluster the same two. They are shown in hourctl peers, hourctl status and GET /api/instance. In GET /api/instance the fields are environment and production. A token scoped to a tenant is told these two and nothing else of the instance. They are logged at startup. hourctl names them on stderr before every change it makes. So you always know which cluster you are changing:

changing PRODUCTION (gw.example.com:9090)
changing PRODUCTION: eu-west (gw-eu.example.com:9090)
changing test (10.0.0.5:9090)
changing PRODUCTION (production at gw.example.com:9090)

A production cluster is PRODUCTION, followed by its name when that is not production. The last line is a named cluster. A cluster that is not production and names no environment is changed without a word.

VarsSecrets
Read by packagesvars.get("name")secrets.get("name")
Keptas they aresealed with HOURADVANTAGE_SECRET_KEY (secrets at rest)
Shown by the API and hourctlname, scope, value, when, whoname, scope, when, who. Never the value.
Audit trailwho set which, and the valuewho set which. Never the value.

A value is text, up to 64 KiB. A name is letters, digits, _, - and ., up to 64 characters. Values for one endpoint only are not vars. They are the endpoint’s options.

Vars and secrets belong to a tenant. A package handling one tenant’s devices reads that tenant’s values. hourctl --tenant names whose you set (default without it). Within a tenant there are two scopes:

A package value overrides the tenant’s value of the same name, for that package only. A package never reads another package’s values.

Terminal window
hourctl var set cloud_url https://cloud.example.com # the tenant's
hourctl var set cloud_url https://zk.example.com --package zk-push
hourctl var list # with SCOPE
hourctl var delete cloud_url --package zk-push
hourctl secret set api_key # asks for it, not shown as typed
hourctl secret set api_key --package zk-push < key.txt
hourctl secret set api_key --file /run/secrets/api_key
hourctl secret list # names, scopes and dates
hourctl secret delete api_key

A secret’s value never goes on the command line. The shell’s history and the process list would keep it there. hourctl secret set asks for it at a terminal. It reads stdin when it is not one. Or it reads --file. One trailing line break is not part of the value.

The admin API has the same. It offers GET /api/tenants/{tenant}/vars, PUT /api/tenants/{tenant}/vars/{name} with {"value": "..."}, and DELETE /api/tenants/{tenant}/vars/{name}. The same exist under /api/tenants/{tenant}/secrets. Each takes ?package=NAME for the package scope.

A change is in use on every instance within about a second. hourctl waits for every instance to acknowledge it (“applied on 3/3 instances”). A device message being handled when a value changes finishes with the value it read.

Read values inside a package’s functions, not while the package loads. vars.get and secrets.get at load time are an error. The loaded module is kept, so a value read then would outlive a change.

A package lists the values it cannot run without in package.toml:

[requires]
vars = ["cloud_url"]
secrets = ["api_key"]

Either scope satisfies one. A revision is not activated while a tenant whose endpoints use the package lacks one. The refusal names each missing value. It adds the tenant, for any tenant but default:

error: package [email protected] cannot be activated: it requires var 'cloud_url', secret 'api_key'
([requires] in its package.toml), which is not set; set them first (`hourctl var set`,
`hourctl secret set`, for the tenant or with --package zk-push) (409)

The other way round, a value a package in use requires cannot be deleted while the other scope does not give it. The refusal names the package. Leave out of [requires] the values a package reads but can do without.

hourd dev reads values from dev.local.toml, which is never committed. dev.toml may hold vars. Secrets in it are refused:

[vars]
cloud_url = "https://test.example.com"
[secrets]
api_key = "my-own-test-key"
[package.zk-push.vars] # the package scope
cloud_url = "https://zk-test.example.com"

A scenario declares the values its package reads. They are test values of its own that nothing else sees:

[vars]
cloud_url = "https://cloud.test"
[secrets]
api_key = "test-key"

A pushed bundle’s scenarios always run with their own values, never the cluster’s.