Snapwake

DocsRunning your app

Secrets and environment variables

On Snapwake every environment variable you give an app is stored as a secret: encrypted with your organization's key on the app's home server, and never written into the app's image. There is no separate list of "plain" variables.

Setting them

Terminal
snapwake secret shop set DATABASE_URL=postgres://u:p@db.example.com/shop STRIPE_KEY=sk_live_...
snapwake secret shop unset OLD_FLAG
snapwake secret shop list          # names only; values are never shown again
snapwake redeploy shop             # start the app with the new values

At deploy time, two more ways:

Terminal
snapwake deploy . --env-file .env.production

and the [env] table of snapwake.toml. Both add to the app's secrets and replace variables of the same name; neither removes variables you set earlier.

Env file format: one KEY=VALUE per line. Empty lines, lines starting with # and lines without = are skipped, a leading export is dropped, spaces around the key and the value are trimmed, and one pair of double quotes around the value is removed. Nothing else is interpreted: single quotes stay part of the value, and there are no escapes and no ${VAR} expansion.

Rules

  • Names are letters, digits and _, start with a letter or _, and are at most 256 characters.
  • Values are one line: no newlines. To store a PEM key or a JSON file, base64-encode it and decode it in your app.
  • All of an app's variables together, as KEY=VALUE lines, must fit in 64 KB. One secret set may send at most 1000 names and 256 KB, so it can accept more than 64 KB in total; the app then fails to start and to wake. Keep large values (certificates, JSON configs) in object storage.
  • The app must exist and have been placed on a server before you can set secrets. A deploy does this for you; if you set secrets right after creating an app from the API, retry after a second if you get "the app has no home node yet".

How your app receives them

As environment variables, when the app starts. Each deploy boots the new version with your variables in its environment, and that running process is what the snapshot saves. Every wake restores the same process, with the same environment. So a changed value reaches process.env / os.environ only after snapwake redeploy (or the next deploy).

Variables you set win over the image's own ENV with the same name, as with docker run -e. Each name appears exactly once in the environment.

As a file, on every wake. /run/flare/secrets.env holds the current values as KEY=VALUE lines and is rewritten on every wake. The path is also in the FLARE_SECRETS variable. An app that reads its secrets from this file, or through the runtime helpers (secret("NAME")), picks up a changed value on its next wake without a redeploy.

Two things to know about the file during the beta:

  • It is written on wakes from a snapshot, not when a VM boots fresh. The first VM of each new version boots fresh and serves until its first sleep, so the file isn't there yet. Apps with volumes also boot fresh after a deploy or a crash.
  • It is readable only by root. An image that runs as another user (USER in the Dockerfile) can't read it.

So read the file first and fall back to the environment, which is always set:

JavaScript
import { secret } from "@flare/runtime";
const key = secret("STRIPE_KEY") ?? process.env.STRIPE_KEY;
Python
import os
from flare import secret
key = secret("STRIPE_KEY") or os.environ.get("STRIPE_KEY")

During the build, for framework builds only: your variables are set while dependencies install and the build runs, so next build can read NEXT_PUBLIC_*. Dockerfile builds don't see them; use build arguments.

Where they are kept

  1. The CLI sends the values to Snapwake's control service over HTTPS.
  2. The control service holds them in memory only, until the app's home server picks them up (at most 10 minutes).
  3. The home server encrypts them with your organization's key and stores them with the app. The control service keeps only that encrypted copy, which a new home server uses after a failover.

The values are not written into the image, not printed in logs, and never returned by the CLI, the console or the API. They are, however, part of the encrypted snapshot of a running app, because the app's process has read them.

Names with a meaning

Name Effect
PORT, HOSTNAME ignored for framework builds, which always listen on port 3000
NODE_OPTIONS framework builds: added to the options Snapwake sets for Node.js. Images and Dockerfile builds: replaces them, which turns off the reseeding of random generators after wake; include --import=/flare/preload.mjs in your value to keep it
PYTHONPATH images and Dockerfile builds: replaces Snapwake's, which turns off the reseeding and the flare module; include /flare/python in your value to keep them
FLARE_REGISTRY_AUTH, FLARE_REGISTRY_AUTH_<HOST> registry credentials for private images; given only to the build, never to the app
FLARE_PG_POOL=1 turns on the Postgres connection pool; DATABASE_URL is then replaced inside the app
REDIS_URL (or the name you chose) for a queue worker, replaced inside the app by a local address that survives sleep
SQLITE_PATH, DATABASE_URL set for you by snapwake deploy --sqlite (Volumes and SQLite)