Sub topic 6
Passing secrets and using secrets: inherit
This chapter assumes you can write a basic workflow, know what repository and organization secrets are, and have read the previous chapters on defining a reusable workflow with workflow_call and calling it from a job. Here you will see how secrets cross the boundary between caller and called workflow.
Secrets are not passed automatically
A called workflow runs in its own context. It does not see the caller's secrets unless the caller hands them over. This is a safety feature: a shared workflow only receives what you decide to give it.
There are two ways to pass secrets:
- Name each secret explicitly with
secrets:. - Pass everything the caller can access with
secrets: inherit.
Declaring secrets in the called workflow
The called workflow lists the secrets it expects under on.workflow_call.secrets. Each entry can be marked required.
# .github/workflows/node-test.yml
name: Node test
on:
workflow_call:
inputs:
node-version:
description: Node.js version to use
type: string
required: false
default: '20'
secrets:
npm_token:
required: false
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
- run: npm testSteps read the value through the secrets context, as in ${{ secrets.npm_token }}. If a secret is marked required: true and the caller does not supply it, the run fails.
Unlike inputs, secrets have no type field. Every secret is a string.
Passing secrets explicitly
The caller maps each secret name the called workflow declares to a value. The value is usually one of the caller's own secrets.
# .github/workflows/ci.yml in the calling repository
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
call-test:
uses: my-org/shared-workflows/.github/workflows/node-test.yml@v1
with:
node-version: '22'
secrets:
npm_token: ${{ secrets.NPM_TOKEN }}The name on the left (npm_token) is the name the called workflow declared. The expression on the right (secrets.NPM_TOKEN) is the caller's secret. They do not have to match, which lets the shared workflow use neutral names.
Explicit passing is the better default. Reading the caller's file tells you exactly which secrets leave the repository.
Passing everything with secrets: inherit
When the caller and the called workflow belong to the same organization or enterprise, you can write secrets: inherit. Every secret the caller can access becomes available to the called workflow.
jobs:
call-test:
uses: ./.github/workflows/node-test.yml
secrets: inheritThis covers repository, environment, and organization secrets that the calling workflow can reach. With inherit, the called workflow can read a secret by name without declaring it under workflow_call.secrets. Declaring it is still good documentation.
Choosing between the two
| Approach | Strength | Risk |
|---|---|---|
| Explicit `secrets:` | The caller shows exactly what is shared. Names can differ. | More lines to maintain. |
| `secrets: inherit` | Short. New secrets reach the workflow with no edit to the caller. | The called workflow can read secrets it does not need. |
Use inherit for workflows you own and trust, such as a same-repository call or a shared repository your team controls. Use explicit passing for anything maintained by someone else.
Common errors
- A secret is empty in the called workflow. The caller did not pass it, or the name on the left does not match a declared name. Check spelling and case.
- Passing a secret through
with:. Inputs are not masked the way secrets are. Send sensitive values only throughsecrets:. - Calling across organizations with
inherit. It works only inside the same organization or enterprise. Outside it, pass secrets explicitly. - Using the
secretscontext in a job-levelif:. Thesecretscontext is not available inif:conditions. Copy the value into anenvvariable at the job level and test that.
Exercise
A shared workflow in your organization declares one secret, deploy_key. Your caller repository stores it as PROD_DEPLOY_KEY. Write the secrets: block for the calling job, then say when you would choose secrets: inherit instead.
Show answer
The block is secrets: followed by deploy_key: ${{ secrets.PROD_DEPLOY_KEY }}. Choose secrets: inherit when the called workflow is in the same repository, or in a repository in the same organization that you control and trust, and you want new secrets to reach it without editing the caller. With inherit the names must match, so you would need a secret named deploy_key in the caller.