CTRLctrl docs

Environment variables

Environment variables are how you hand configuration and secrets to your app: API tokens, feature flags, connection strings. Your app reads them from its process environment, as it would anywhere else.

Set them in the dashboard#

  1. Open the app and find the environment variables editor.
  2. Add a key and a value for each variable. Values are masked as you type.
  3. Select save and redeploy.

Saving redeploys the app so it starts with the new values. If the redeploy fails, your variables stay saved and the dashboard says why the redeploy didn't happen.

Set them with the CLI#

# Show every variable, or one
ctrl env get my-app
ctrl env get my-app NODE_ENV

# Set one or more; existing variables are kept
ctrl env set my-app NODE_ENV=production LOG_LEVEL=info

To keep a secret out of your shell history, pipe it in with --stdin, one KEY=VALUE per line. Blank lines and lines starting with # are ignored.

printf 'STRIPE_SECRET=sk_live_...\n' | ctrl env set my-app --stdin

Key names must start with a letter or underscore and contain only letters, digits and underscores. ctrl env set also redeploys the app. See the CLI reference.

Set them through the API#

PUT /v1/apps/:app_id/env replaces the app's whole set of variables, then redeploys:

curl -X PUT https://api.getctrl.dev/v1/apps/my-app/env \
  -H "Authorization: Bearer $CTRL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"env_vars": [["NODE_ENV", "production"], ["LOG_LEVEL", "info"]]}'
{ "ok": true, "redeployed": true }

If the redeploy fails, you get "redeployed": false and an error, and the new variables are still saved.

Because PUT replaces everything, send the full list. Any variable you leave out is removed. GET /v1/apps/:app_id returns the current set in env_vars, as a JSON-encoded string of [key, value] pairs.

Copy variables from another app#

You can copy variables from another of your apps, such as staging into production. First preview what would change:

curl -X POST https://api.getctrl.dev/v1/apps/my-app/env/promote \
  -H "Authorization: Bearer $CTRL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"from": "my-app-staging"}'

The preview lists key names only, never values:

  • add: keys the target doesn't have yet.
  • overwrite: keys whose values differ.
  • skipped: database-managed keys, which are never copied (see below).

Send the same request with "confirm": true to copy them and redeploy. Keys the source doesn't have are left alone on the target. The dashboard has the same flow in the environment variables editor.

Database-managed keys#

When you add a managed database to an app, CTRL writes these variables for you:

Key Holds
DATABASE_URL mysql://user:password@host:3306/dbname
DB_HOST The database's private address
DB_PORT 3306
DB_NAME The database name
DB_USER The database user
DB_PASSWORD The database password

These keys belong to the database:

  • Adding a database replaces any existing variables with these names. Deleting the database removes them.
  • Adding or deleting a database updates the saved variables without redeploying, so redeploy the app to pick up the change.
  • Copying variables between apps, or into a new environment, never copies these keys. That way a copy can't end up pointed at another app's database.

New environments#

When you create an environment by copying another one, its variables come along with two exceptions:

  • The database-managed keys are dropped.
  • A value that mentions the source environment's database host or one of its app hostnames is blanked and flagged, so you can decide whether to keep it. Carried over as-is, it would point the copy at the original's data or apps.

How secrets are handled#

  • Stored: variables are encrypted at rest with AES-256-GCM, and decrypted only to start your app and to show them back to you.
  • Readable: anyone with access to your account, through the dashboard, an API key or the CLI, can read them.
  • Audited: the audit log records which keys changed, never their values.

See Security for more.