Secrets and variables
Runs often need configuration, such as a proxy address, and credentials, such as a deploy token. Forge keeps the first as variables: plain values every run gets as environment variables, readable by everyone in the organization or project. It keeps the second as secrets: encrypted values a run gets only when it asks for one by name, and which can't be read back.
Variables
Variables are on the Variables tab of the Variables and secrets page of the organization
or a project, and on an environment's page. Changing them needs variable:write; developers and
up have it.
- Name: letters, digits and
_, not starting with a digit. Names are case-sensitive. - Value: up to 32 KiB.
${NAME}includes another variable;$${is a literal${. - Locked: levels below can't set this name.
A run's environment is built from levels, the most specific last: the organization, then the
project, then the environment it deploys to, the template, the flow, the schedule or trigger, and
the run's own env. Variables from a Git event (FORGE_GIT_*) come last of all. A name set at a
lower level overrides a higher one, unless it is locked there.
What runs get, on the Variables tab, shows the merged result and where each value comes from. A run's page lists every variable with the level it came from.
Variables are not for secrets: they are stored and shown as they are. The same goes for env in a
run spec and forge run --env.
Groups
An organization can keep named Groups of variables and secrets, such as db-prod, on the
Groups tab of its Variables and secrets page. A project attaches the groups it uses on its own
page's Groups tab, an environment on its page, and a group can be included in every project. A
later group wins over an earlier one, and a project's or environment's own values win over all of
them.
Secrets
Secrets are on the Secrets tab of the Variables and secrets page of the organization or a
project, and on the page of an environment or a group.
Adding, changing and deleting them needs secret:write (maintainers and up). A value is up to
64 KiB, stored encrypted, and never shown again: not in the console, the API or the output.
When a run asks for a name, Forge looks in this order: the environment the run deploys to, the project, the groups attached to them, then the organization. A name can't be both a variable and a secret.
In the run spec
A run names the secrets it needs under secrets. {} gives the value as an environment variable
of the same name; file puts it in a read-only in-memory file instead:
image: alpine:3.20
secrets:
DEPLOY_TOKEN: {}
TLS_KEY: { file: /run/secrets/tls.key }
commands:
- name: deploy
run: ./deploy.sh --token "$DEPLOY_TOKEN" --key /run/secrets/tls.key
From the command line, --secret NAME gives an env secret and --secret NAME=/path a file:
forge run --secret DEPLOY_TOKEN --secret TLS_KEY=/run/secrets/tls.key --cmd ./deploy.sh alpine:3.20
- A run can name up to 50 secrets. A secret's name can't also be in the run's
env. ${NAME}in env values refers to variables, not secrets. Read a secret in your commands from its environment variable or file.- A file can't be under
/proc,/sysor/dev.
Who may use them
Starting a run that asks for secrets needs secret:use on the project, besides run:create.
Developers and up have it. Schedules and triggers run as a service account, whose role needs it.
Masking
Secret values are replaced by *** in the run's output, also in their base64 and URL-encoded
forms and line by line for values over several lines. The run's summary and test reports are
masked the same way. Values shorter than 4 characters aren't masked. Masking is a safety net: a
run that sets out to leak a secret can, so only give secrets to code you trust.
Versions and rotation
Each new value is a new version. The last 10 are kept under Versions, with who set each one and when. To rotate a secret, enter a New value; leaving it empty keeps the current one.
- A run gets the version that was current when it was created. Running runs keep it, and retries use the same version.
- Make current rolls back to an older version. The secret is then marked Rolled back.
- A secret marked Lost has to be set again before runs that need it can start.
Restrictions
A secret's settings narrow which runs get it:
- Projects (organization secrets): only these projects may use it. None ticked: all projects.
- Templates: only runs started from these templates. Changing the list then needs the right to edit those templates. A deleted template stays listed, so the secret doesn't open up.
- Saved flows: the steps of these saved flows' flow runs may use it too. With templates ticked as well, a run from either will do. None ticked in either: any run.
- Runner labels:
label=valuelines, such asenv=prod, that a runner must have to receive the secret. A run with such a secret waits for a runner that has them. - Environment secrets: a secret on an environment's page goes only to runs that deploy to it, so a production password can stay there while staging uses the project's. A protected environment's rules apply before such a run starts. See environments and deploys.
Runs get secrets on your own runners and on shared runners, which run each run in its own microVM. A runner label only your runners have keeps a secret off the shared ones. See runners.
Runs from Git
- A run from a pull request from a fork gets no secrets. Its run page lists the ones withheld. See Git integration.
- A run file or flow file from a repository may only name the secrets its trigger lists as Allowed secrets, because anyone who can push can change the file. Secrets restricted to templates are never available to them.
Image registries
Logins for private image registries are not secrets: they are kept on the Registries page of
the organization or project. Each registry has a host, such as ghcr.io, and up to two logins: a
pull login and a push login. They are stored encrypted, versioned and never shown back, and each
new login is tested before it is saved.
A run names the registry to pull its image with:
image: ghcr.io/acme/tools:1.4
registry: ghcr
The registry's host must be the image's, and a login is never sent to another host. Pulling with
a registry needs registry:pull and pushing registry:push; developers have both. Like secrets,
a registry can have runner labels that keep its logins on the runners you choose.
Limits
- 100 secrets and 200 variables per organization, project, environment or group.
- A secret's value up to 64 KiB; a variable's up to 32 KiB.
- 50 secrets per run.