Skip to content

Manage environment variables and secrets (and import contexts)

Goal: keep the settings and keys your scripts need (log levels, API keys, tokens) as personal environment variables and secrets, load them from a .env file, and use them in a script. Admins also keep the context's platform variables and secrets, which workers reference, and import contexts from a contexts.toml.

Prerequisites

  • Signed in, on the context you want them on (entries are kept per context: set them up on each).
  • No admin role is needed for your own variables and secrets: they change nothing on the platform and pass no write gate. The platform scope and importing contexts need an admin.

Add a variable or a secret

  1. Open Config > Environment variables (route /config/env) or Config > Secrets (/config/secrets). The line under the title names the context.
  2. Press Add…, type a Name (a letter or _, then letters, digits and _, e.g. LOG_LEVEL) and a Value, press Save. The notice says Personal variable LOG_LEVEL saved (Personal secret … saved).

    The Add dialog filled in

    The saved variable in the table, and the notice

  3. A secret's row shows … and its last four characters (…abcd), never the value. To change it, select the row, press Edit… and type the new value (the field says set (…abcd); type to replace).

    A personal secret: only its last four characters shown; the secret patterns below

A name is either a variable or a secret: adding a variable BINANCE_KEY while you have a secret BINANCE_KEY says BINANCE_KEY is already a secret.

Import a .env file

  1. On Environment variables, press Import .env… and pick the file, e.g.

    # my settings
    LOG_LEVEL=info
    REGION=eu
    export BINANCE_KEY=abc123…
    GITHUB_TOKEN="ghp_…"
    
  2. The preview lists what this page takes:

    • New: LOG_LEVEL, REGION (not there yet);
    • Changed: names whose value differs, ticked to replace; untick one to keep its current value;
    • Unchanged: same value already;
    • Left out: BINANCE_KEY — a secret pattern, GITHUB_TOKEN — a secret pattern.

    The import preview: New, Changed (ticked), Left out as secret patterns

  3. Press Import N (N: the new and ticked names). Nothing is written before.

  4. Open Config > Secrets and import the same file: now BINANCE_KEY and GITHUB_TOKEN are offered and LOG_LEVEL, REGION are left out as not a secret pattern. A changed secret is found by the server: neither value is shown.

Which names are secrets is decided by the secret patterns at the bottom of Config > Secrets: regular expressions matched anywhere in the name, ignoring case, TOKEN and KEY by default. Add one (e.g. ^AWS_, SECRET$) with Add pattern, remove one with ✕, Defaults restores TOKEN, KEY.

Use them in a script

In Infra > Scripts:

const level = await vf.env('LOG_LEVEL')
const key = await vf.secret('BINANCE_KEY')
print('log level', level, '— key ends with', key.slice(-4))

The secret is fetched from the app server for this run only; Operations called lists vf.secret with the name, not the value. See Scripts.

Delete

Mark rows (or select one) and press Delete…; with several marked, the dialog lists them and asks once more (Yes, delete all N: this cannot be undone).

Platform scope

Admins only: the variables and secrets workers use, shared by everyone on the context.

  1. On Config > Environment variables or Config > Secrets, switch the scope to Platform. The line under the title says where they are kept.

    Environment variables, Platform scope

  2. Add… a platform variable, e.g. REGION = eu (kept in cfg.env), or a platform secret, e.g. alpaca-paper-key (a secret key may also hold . and -). Each save is one write: on a protected context you confirm it, and Infra > Changes lists it.

  3. A platform secret's row shows set and Set at, never the value or its last characters.

  4. Import .env… works as above, with your secret patterns. An imported secret whose name already exists is Changed with the note value not readable (its value cannot be compared): it is replaced unless you untick it. The whole import is one write.

  5. Give them to a worker when you create it (Infra > Workers > New…): secrets under Secret references, variables under Platform variables as attribute=VARIABLE lines, e.g. region=REGION (the attribute is 1-20 lower-case letters or digits). See Start a worker. A worker sees a changed variable at its next start.

  6. Delete a platform secret: type its key (for several marked ones, their number) to confirm. Its value cannot be read back, and every worker of the context that uses it fails at its next load or start. Platform variables and your own entries ask the usual way.

Without the admin role the platform scope is read-only (the buttons say Only admins may change platform entries).

Import contexts

Admins only; the app server needs an overlay file (VIRTUFIN_APP_CONTEXTS_OVERLAY, Settings).

  1. Open Config > Contexts (route /config/contexts): each context with its host, health and whether a key is set (set, from the environment, none; never the key).

    Config > Contexts

  2. Press Import TOML… and pick a file in the contexts.toml format.

  3. The preview lists New, Changed (ticked to replace) and Unchanged contexts, and the bad entries as Left out with their problem (no api_host).
  4. Press Import N. The entries go into the app server's overlay, which replaces the deployment's entries of the same name; an entry without api_key keeps the existing key. The table shows them with Source overlay, and the context menu offers them.

When it does not work

You see Why, and what to do
NAME on lines X and Y The file gives a name twice: remove one line.
NAME is already a secret / already a variable The name is the other kind: delete it there first, or rename it.
(unclosed: Invalid regular expression … The pattern is not a valid regular expression: fix it.
A secret shows only set It is shorter than eight characters: no trailing characters are shown.
Import TOML… is off You are not an admin, or the server has no overlay file (its tooltip says which).
Platform buttons are off You are not an admin: the platform scope is read-only for you.
the gateway does not know the Secrets service yet; try again in a few minutes The api gateway caches the WorkManager's methods for up to an hour after a release: wait and press Retry.
NAME is already a platform secret / variable In the platform scope the name is the other kind: delete it there first.
An imported platform secret is Changed though its value is the same A platform secret's value cannot be read to compare: untick it to leave it alone.