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.
Setup (once per project)
Section titled “Setup (once per project)”-
Create a project in Infisical with environments
dev,test,stagingandprod(the slugs the script uses). -
Add the variables from the template’s
.env.exampleto each environment. The template’s Environment page says what each should be. -
Install the CLI and log in:
Terminal window npm install -g @infisical/cliinfisical login # self-hosted: --domain https://<your-infisical> -
Point each
infisical.jsoncat 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 initin that folder and thenyarn secrets init --force, which copies the id from.infisical.jsoninto a freshinfisical.jsonc. A monorepo has oneinfisical.jsoncper workspace, so set it in each. -
Create the folders the configs name (below) in each environment, or change
"path"to match how your project is organised.
Where each template reads from
Section titled “Where each template reads from”"path" in infisical.jsonc is the Infisical folder each one exports.
One config at the project root, "path": "/".
One per app: apps/api reads /backend/api, apps/worker reads
/backend/worker. Run yarn secrets from the app’s folder, or
yarn workspace @scope/api secrets -e test from the root.
One per workspace, under /frontend: /frontend/client, /frontend/auth,
/frontend/admin, /frontend/landing, and /frontend/types for the API-types
generator. yarn secrets at the root runs every workspace’s;
yarn workspace client secrets -e prod runs one.
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.
Projects generated before stacks 0.5
Section titled “Projects generated before stacks 0.5”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>.