Store credentials in GitHub encrypted secrets and reference them as ${{ secrets.NAME }}, passing them to a step through env: only where needed. GitHub masks secret values in logs, but masking is not a guarantee. Where your cloud supports it, use OpenID Connect to get short-lived credentials instead of storing long-lived keys.
Read the key from the environment
name: deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Call the API
env:
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
run: ./scripts/deploy.shLocal development
Create secrets under Settings, Secrets and variables, Actions, at repository, environment or organisation level; use environment secrets with required reviewers for production. For local testing of workflows, tools such as act take secrets from a git-ignored file. Do not echo secrets or derive new values from them in ways masking cannot detect, such as base64 encoding, because transformed values are not masked.
Production
Scope secrets to the narrowest level, restrict workflows with permissions: and pin third-party actions to a full commit SHA. GitHub does not pass secrets to workflows triggered from forks, except GITHUB_TOKEN with read access, and pull_request_target runs with secrets, so avoid checking out untrusted pull request code there. Prefer OIDC to cloud providers to avoid storing cloud keys.
Mistakes to avoid
- Using
pull_request_targetorworkflow_runwhile checking out and running code from a fork, which can give untrusted code access to secrets. - Printing secrets or structured data containing them (
toJSON(secrets)), or writing transformed copies that GitHub cannot mask. - Passing a secret to a third-party action you have not pinned to a commit SHA, since a changed tag could exfiltrate it.
- Storing long-lived cloud keys as secrets when OIDC could provide short-lived tokens.
- Interpolating
${{ secrets.X }}directly intorun:scripts, where it can end up in shell history or error output; pass throughenv:instead.
When an AI agent works on your GitHub Actions project
Coding agents run inside your project folder, so they can read the same .env file your app reads. BotPassword injects keys at run time instead: the agent calls the run_with intent through the MCP server and the process gets the variables it needs while the agent sees only redacted output. Planned: bpw run, a CLI form of the same.
Frequently asked questions
How do I use a secret in GitHub Actions?
Add it under Settings, Secrets and variables, Actions, then reference it as ${{ secrets.NAME }}, ideally in a step's env: block.
Are GitHub Actions secrets available to pull requests from forks?
No, not by default. Secrets are not passed to workflows triggered by pull requests from forks, apart from a read-only GITHUB_TOKEN. Be careful with pull_request_target, which does run with secrets.
Should I keep API keys in a .env file for GitHub Actions?
A .env file that is git-ignored is fine for local development, but every process and every AI coding agent running in that folder can read it. Load secrets into the environment at run time from a password manager or secrets manager instead, so no plaintext file sits in the project.