App environment variables

Give an app its API keys and settings with oalo env, per env: what is secret, what each kind of app gets, its own token and database, and when changes apply.

An app often needs values that don't belong in its code: an API key for a payment provider, the URL of another service, a feature switch. Set them on the app with oalo env, and Oalo hands them to the app's process as ordinary environment variables (process.env.NAME in Node, os.environ["NAME"] in Python, System.get_env("NAME") in Elixir).

Each app has two sets: dev, for the preview, and prod, for the live app. They are separate, so the preview can use a test key while the live app uses the real one. Dev and prod covers what else is kept per env.

oalo env --app shop                                   # list dev's variables
oalo env set API_BASE_URL=https://api.example.com --app shop --public
oalo env set STRIPE_KEY --secret --app shop           # asks for the value, hidden
oalo env set --file .env.production --app shop --env prod
oalo env unset OLD_FLAG --app shop

Only admins and members with Developer access can list or change them.

Secret and public

Every variable is either secret or public.

  • Secret values are stored encrypted and are never shown again, not even to an admin. oalo env lists the name and when it was set. Only server apps receive them.
  • Public values are shown by oalo env, and static apps receive them too.

A variable is secret by default. It is public when its name starts with a browser prefix (VITE_, EXPO_PUBLIC_, NEXT_PUBLIC_, NUXT_PUBLIC_, PUBLIC_, REACT_APP_, GATSBY_), or when you set it with --public. --secret makes any name secret.

To keep a secret out of your shell history, give the name without a value (oalo env set STRIPE_KEY --secret). The CLI then asks for the value without showing it, or reads it from stdin when you pipe it in.

What each kind of app receives

AppPreview (dev)Live (prod)
Serverevery dev variable, at startevery prod variable, when its containers start (its image's build sees only the public ones)
React, Figmapublic dev variables, when the preview startspublic prod variables, at build
Expo (web)public dev variables, when the preview startspublic prod variables, at build
Flutter (web)public dev variables, as --dart-definepublic prod variables, as --dart-define

Static apps (React, Figma, Expo, Flutter) never receive secrets. Whatever their build can see may end up in the JavaScript that every visitor downloads. Keep keys in a server app and have the static app call it.

In a Vite app, read a public variable as import.meta.env.VITE_NAME. In Expo, use process.env.EXPO_PUBLIC_NAME. In Flutter, use String.fromEnvironment('NAME').

Names Oalo keeps

Oalo sets some variables itself, and they always win:

  • PORT, DATABASE_URL, APP_SCHEMA and OALO_ENV for server apps;
  • OALO_URL and OALO_SYNC_TOKEN for server apps (see below);
  • CONTAINER_HOST and its VITE_ and EXPO_PUBLIC_ forms, for links between your apps;
  • APP_SLUG, VITE_PORT, and the basics (PATH, HOME, LANG, TZ).

These names, and any name starting with OALO_, can't be set with oalo env. Other names take letters, digits and _, and can't start with a digit.

An app's process receives only these variables, its own and Oalo's. It never sees the workspace's own credentials.

The app's database

A server app's DATABASE_URL is a PostgreSQL URL (postgresql://...), and APP_SCHEMA names its schema: dev in the preview, prod live.

  • One login per env, shared. Every server app in the workspace uses the same database login for an env, with up to 20 connections open at once between them. Keep pools small (5 or so per process).
  • Its tables sit next to your data models, in the env's schema. The login can create tables there and read and write every table there, but nothing in public and nothing in the other env. Prefix your tables with the app's name so they can't collide with a model or another app's tables.
  • The schema is the default, so plain SQL and most ORMs need nothing set. An ORM that names its own schema needs APP_SCHEMA (Prisma, for one, uses public unless its URL says ?schema=).
  • Read them from the terminal with oalo db tables and oalo db query "select * from myapp_orders order by id desc limit 5" (--env prod for live). It runs as this same login, read-only, so it sees what your app sees. oalo data reads Oalo models only. Workspace admins.
  • Your app's tables can start workflows: oalo data events <table> created turns on row events for one (see App events).
  • To use a database outside Oalo instead, give it another name, such as EXTERNAL_DATABASE_URL: DATABASE_URL is always Oalo's.

Bringing data in

oalo db restore loads a Postgres database you already have into an env. Run it with --check first: that does everything except the write, and reports the tables (rows and size), the extensions and any conflicts.

oalo db restore latest.dump --env prod --check
oalo db restore latest.dump --env prod
  • From a file made by pg_dump --format=custom (Heroku's latest.dump is one) or plain SQL. Or from a database: put its postgres:// URL in a variable and pass --from-env SOURCE_DATABASE_URL, and your Base runs pg_dump against it. It must be at a public address; one inside a private network is refused.
  • One schema comes in: public, or the only one there is, so a file from oalo db dump needs nothing more. --schema <name> picks another. Its tables, with their indexes, constraints, sequences (which carry on where they were), views, functions and triggers, land in the env's schema, owned by the env's database login. The app reads them at DATABASE_URL, and its own migrations can change them.
  • A name already in the env is refused: a table, view, sequence, type or function with the same name as one there (your data models and other apps' tables live there too). The reply lists them. Rename or drop the one in the way, or restore into the other env. Tables your app's release: already made there count too, so restore before it first runs against DATABASE_URL.
  • Extensions: plpgsql, pgcrypto, uuid-ossp, citext, hstore, pg_trgm, btree_gin, btree_gist, unaccent, fuzzystrmatch, intarray, ltree, cube, earthdistance, tablefunc and vector. A dump that needs another is refused, naming it. pg_stat_statements, which only monitors, is skipped, and the result says so.
  • All or nothing: a failed restore leaves the env as it was. Writes made to the old database after the copy starts aren't in it.
  • --env is required; prod asks you to confirm, or needs --yes in a script. Up to 10 GB, one restore at a time per Base, workspace admins only.

Moving a whole app with its database: see Moving from Heroku, Railway, Render, Fly.io or Primcloud.

The app's own Oalo token

A server app starts with OALO_URL (this workspace's API) and OALO_SYNC_TOKEN, a Sync API token made for that app. With it the app's server reads and writes its data (/api/sync/v1), sends events that start workflows (/api/events/v1, see App events) and calls workflows for their answer (/api/workflows/v1, see Calling a workflow from your app), with nothing to copy from the dashboard.

  • Each env has its own, locked to that env's data, like the app's database login. The preview's token reads and writes dev rows only; asking it for env=prod is refused. The live app's reaches live rows only.
  • A preview's events are a dry run. The event registers, so its trigger can be set up, and the reply lists the workflows it would start, but none runs. Its workflow calls are test runs (dev data, sends simulated). The live app's events and calls are real.
  • Neither can change models (the Data API's create and promote touch both envs). Define models in the Data pane, or with a workspace token.
  • Static apps get none: the token would end up in the browser. Their users sign in instead (see Connect your own frontend).
  • It does more than data: it starts chat sessions for the chat widget (/api/chat/v1/sessions, see Chat widget), and it signs Oalo's calls to the app's own endpoints (see App tools), so rotating it changes that signature key too.
  • Rotate it with oalo env rotate-token --env prod. The old one stops working at once, and the app restarts on the new one: the preview, or the live app's current commit is relaunched (that is a build). Revoking it in the Sync API panel has the same effect at the app's next start.
  • The tokens are listed in the Sync API panel as "app dev (OALO_SYNC_TOKEN)" and "app prod (OALO_SYNC_TOKEN)". Deleting the app revokes them.

When a change takes effect

  • dev: the preview restarts with the new values. Pass --no-restart to wait for its next restart instead.
  • prod: the live app is relaunched at the commit it already runs, so it picks the values up (a build; no new code goes out). Static apps bake public values in at build time, and this rebuild does that. Pass --no-restart to batch several changes: the last one without it relaunches.

If a key was committed to the code

Oalo scans an app's code as it arrives (an import, each push and each oalo deploy) for keys and tokens committed by mistake, and tells you where: in the deploy's output, the team chat and the app's log. oalo secrets --app shop lists what's open. For each one:

  1. Rotate it with its provider. It stays in the repo's history, so deleting the line isn't enough.
  2. Set the new one with oalo env set NAME --secret --app shop.
  3. Read it from the environment in the code (process.env.NAME, os.environ["NAME"]).

If a finding isn't a secret (a test value, say), oalo secrets dismiss <fingerprint> --app shop stops it being reported. Oalo never keeps the value it found, only where it is.

Limits

  • A value can be up to 32 KB. Multi-line values (a PEM key, say) are fine.
  • An app can have up to 200 variables per env, adding up to 240 KB.
  • --file sets every line of the file, or none if one line is invalid.
  • apps.md: the kinds of app, and preview versus production.
  • tokens-and-credentials.md: the tokens Oalo itself issues.
  • sync-rest-api.md: reading and writing the workspace's data from your own server.
Related
Try it on your own Base

Sign up, install the CLI, and deploy your repo in a few minutes.

bring your repo