Skip to content

Secrets with Infisical

Every template (except py-worker) ships a yarn secrets script that writes an environment’s variables from Infisical into the matching .env file, so secrets live in one vault instead of being passed around by hand. It runs @aurostack/secrets, configured by a committed infisical.jsonc beside each package.json that has the script.

Command Writes
yarn secrets .env (the dev environment)
yarn secrets -e test .env.test
yarn secrets -e staging .env.staging
yarn secrets -e prod .env.production

The file is written only after the export succeeds; on any failure the script exits non-zero and leaves the existing file alone. Every one of these files is gitignored. --env takes a slug or an alias (-e production), and -p /other overrides the folder for one run; yarn secrets --help lists the rest.

  1. Create a project in Infisical with environments dev, test, staging and prod (the slugs the script uses).

  2. Add the variables from the template’s .env.example to each environment. The template’s Environment page says what each should be.

  3. Install the CLI and log in:

    Terminal window
    npm install -g @infisical/cli
    infisical login # self-hosted: --domain https://<your-infisical>
  4. Point each infisical.jsonc at the project. Generation leaves "projectId" empty, so the template never carries one organisation’s vault into another project. Fill it in from Project Settings in Infisical; it identifies the project but grants nothing, so it is committed:

    "projectId": "2b690ec2-2993-4505-a42f-decfbf23b386",

    Or run infisical init in that folder and then yarn secrets init --force, which copies the id from .infisical.json into a fresh infisical.jsonc. A monorepo has one infisical.jsonc per workspace, so set it in each.

  5. Create the folders the configs name (below) in each environment, or change "path" to match how your project is organised.

"path" in infisical.jsonc is the Infisical folder each one exports.

One config at the project root, "path": "/".

The environments block maps each Infisical environment slug to its aliases and file. Only the environments listed there exist, so delete any your project doesn’t use, or add your own ("qa": { "file": ".env.qa" }).

The nest-api and nest-monorepo workflows run yarn secrets -e test before the tests. The project id and folder come from the committed infisical.jsonc; the workflows add:

  • INFISICAL_TOKEN: a machine identity’s token, as a repository secret;
  • INFISICAL_API_URL: your Infisical instance, set in the workflows.

Their yarn secrets is a script in .bin/ that reads INFISICAL_PROJECT_ID (and INFISICAL_PATH, or INFISICAL_PATH_PREFIX in react-monorepo) from the environment. stack upgrade replaces it with @aurostack/secrets and an infisical.jsonc: copy your project id into its "projectId", and set "path" if you had changed the folder.

For production containers, don’t bake .env files into images (every template’s .dockerignore excludes them): give the container its variables from your deployment platform, or from infisical run -- <command>.