Skip to content

Environments and secrets

vars in the config are the defaults for every environment. To change them for one environment, put them in .specbook/environments/<env>.env, or under environments.<env>.vars in the config. A service’s address is a variable, so each environment can point somewhere else:

services: { petstore: { spec: './openapi/petstore.json', baseUrl: '{{petstoreUrl}}' } }
.specbook/environments/staging.env
petstoreUrl=https://staging.petstore.example/api/v3

Double braces mark a variable, as in {{petstoreUrl}} above. A single brace is something else: {petId} in a spec is the path parameter, and {{petId}} is a Specbook variable that fills it in, from init, an environment variable, a secret ({{secrets.NAME}}), or a value captured by an earlier step.

Name your secrets in the config, for example secrets: { PETSTORE_API_KEY: {} }. specbook add does this for you from the spec’s security schemes, naming each secret after the service. Specbook reads each one from an environment variable first, then from --secrets-file, the environment’s <env>.secrets.env and secrets.local.env. The folder’s .gitignore keeps the secrets files out of your repository.

Run specbook secrets --env staging to see where each secret resolves from. It never prints a value. A test run masks every secret value wherever it appears, including its URL-encoded, JSON-escaped and base64 forms, and removes credentials from reports.

An OAuth client secret cannot live in a browser. A profile that uses one is filled in by a server: the CLI and a bundle read it from the environment, and specbook dev and preview fill it in on the dev server without sending it to the page. See Authorization.

A published portal never holds a secret. A visitor types credentials once per tab, they are kept per API origin, and a key typed for one API is never sent to another. An embed keeps them in memory only.

A relative address such as /api/petstore resolves against the page, so one environment file serves every host a site is published on. This site’s demo environment works that way.