CI / Secrets and trust
Get the values on your machine
Your app needs the development database URL and API keys on your own machine, and you do not want to copy them by hand. The readers of a CI environment can read its values back, into one value or into a .env file.
3 min read
You need to be a reader of the environment. With the default settings, people with write access read development and preview. Nobody reads the values of production back.
1. Read one value
src secret get DATABASE_URL --env development
src secret get prints one value.
2. Write the whole environment to .env
src env pull --env development
src env pull writes every secret value and variable of the environment to .env, as a job in the environment gets them: the value of a variable in the environment, else its plain value.
- A name that is both a secret and a variable gets the secret, and the pull warns about it.
- The file is readable by you only. Add
-f .env.localto write another file. - The pull refuses to replace a file that exists, unless you add
--force. - Each value is quoted, so that
source .envin a shell never runs it. Some values cannot be quoted that way: a value that holds a'and also one of",\,$or a backtick. Then the pull stops and names the variable.
Warning
Keep the file out of git. The forge refuses a push that adds a .env file.
Done
Your .env holds the development values, and your app runs with them. Each secret value read goes to the audit trail, with who read it. Admins see it with src secret audit --env development, and on the Activity tab of the Secrets section of Settings.
A monorepo with a .env.example in each folder can fill the .env of each folder with only its own keys: see Fill the .env of each folder.
Read only some keys from a script or an agent
An agent or a script that needs two keys does not have to read the whole environment. Name the keys:
curl "https://source.tanstack.com/api/v1/repos/acme/app/ci/environments/development/values?keys=DATABASE_URL,API_URL" \
-H "Authorization: Bearer $SRC_TOKEN"
An MCP client calls pull_ci_environment with name and keys, like ["DATABASE_URL", "API_URL"].
- The forge reads and audits only those keys. A key with no value is not in the answer.
- You can name at most 500 keys. Each key must be a CI name, like
NPM_TOKEN. Any other key gets a 400 answer. - Without
keys, or with an emptykeys=, the answer has every value of the environment. - A token with repositories reads the values only when it holds
secrets:read.