CI/CD security guide

How to use GitHub Actions secrets securely — leak prevention guide

GitHub Actions secrets feel safe because GitHub masks their values in logs — but masking has real limits. A secret echoed via a shell command, a debug flag left enabled, or a third-party action that calls core.setOutput with a secret value can all sidestep the masking and write the credential in plain text to your workflow run log. This guide covers how masking works, the four patterns that bypass it, how to use OpenID Connect (OIDC) to eliminate stored credentials entirely, and how to audit your workflow files before committing them.

How GitHub Actions secrets work

When you create a secret in your repository or organization, GitHub encrypts it at rest using NaCl sealed boxes (libsodium). When a workflow runs, GitHub decrypts the secret on the runner and injects it as an environment variable. GitHub then scans all log output for the exact secret value and replaces every occurrence with *** before writing the log — this is the masking most developers rely on.

Masking is a last-line defence, not a first one. Here is exactly what it covers and what it misses:

ScenarioMasked?
Exact secret value in log output✓ Yes
Value repeated across multiple steps✓ Yes
Base64-encoded variant of the value✗ No
URL-encoded variant of the value✗ No
Partial match (first 8 characters of key)✗ No
Short secrets (< 6 characters) anywhere in output✗ No (reliability threshold)
Value in uploaded workflow artifacts✗ No
Value written to $GITHUB_STEP_SUMMARY✗ No
Derived value (secret concatenated with other characters)✗ No

4 ways secrets leak in GitHub Actions

These are the most common patterns that cause secrets to appear in plain text in workflow logs or artifacts. Each is a real mechanism, not a theoretical edge case.

Critical

echo and run: env

Directly echoing a secret in a run: step or dumping all environment variables with run: env can expose credentials. GitHub masks the exact value in echo output, but run: env prints key=value pairs that confirm which variable holds a credential. For short secrets (fewer than roughly 6 characters), GitHub’s reliability threshold means values may appear unmasked.

# WRONG — exact value masked, but confirms the variable name
- run: echo "Key is ${{ secrets.OPENAI_API_KEY }}"

# WRONG — prints all env vars; secret values masked but names visible
- run: env
Critical

Debug logging flags

Setting ACTIONS_STEP_DEBUG or ACTIONS_RUNNER_DEBUG to true in your repository’s Actions secrets or variables enables verbose diagnostic logging. This debug output can include shell command expansions, environment variable values, and runner internals — including secrets that masking at normal verbosity would suppress. Never leave these flags set in a production repository. Use them only temporarily in a private test repository.

High

Third-party action outputs

Some community actions call core.setOutput() or core.exportVariable() with values derived from your secrets — including error messages that embed the secret or tokens returned during an authentication exchange. Values passed to setOutput are not automatically masked. Before adding any third-party action to a workflow that handles secrets, review its source code for these calls. Pin to a specific commit SHA rather than a branch or tag so the code cannot change without an audit.

High

Workflow artifacts

If a step writes a secret value to a file — in a debug log, build report, or generated config — and that file is uploaded via actions/upload-artifact, it becomes accessible to anyone with read access to the repository for the artifact’s retention period (90 days by default). Masking does not apply to artifact contents. Audit your upload steps: check that log files, test reports, and config dumps do not contain secret values before uploading.

How to pass secrets correctly

Map secrets into step environment variables via env:, then reference the env var name in the shell command. Never inline a ${{ secrets.NAME }} expression directly in a run: block:

# CORRECT — secret injected as env var, referenced by name in shell
- name: Call API
  env:
    OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
  run: |
    curl -s -H "Authorization: Bearer $OPENAI_API_KEY" \
      https://api.openai.com/v1/models

# WRONG — expression evaluated before masking in some shell contexts
- run: curl -H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" ...
Minimum exposure: define secrets at the step level (jobs.<job>.steps[*].env) rather than the job level (jobs.<job>.env). Job-level env vars are injected into every step, including third-party actions that may not need them.

Avoid using secret values in conditional expressions — their evaluation path is less predictable than a plain shell variable reference:

# RISKY — expression evaluation context varies
- if: ${{ secrets.DEPLOY_KEY != '' }}

# SAFER — set an env var, then check it
- env:
    HAS_KEY: ${{ secrets.DEPLOY_KEY != '' }}
  if: env.HAS_KEY == 'true'
  run: ./deploy.sh

Restrict GITHUB_TOKEN permissions

Every workflow run automatically receives a GITHUB_TOKEN. By default it has broad write access to the repository — it can push commits, create releases, write to the packages registry, and more. A third-party action that misuses this token can silently modify your repository.

Narrow permissions at both the workflow and job level. Apply only what your workflow actually needs:

# Workflow-level default: read-only
permissions:
  contents: read
  pull-requests: write  # only if this workflow comments on PRs

jobs:
  deploy:
    permissions:
      id-token: write   # required for OIDC (see below)
      contents: read
Repository default: under Settings → Actions → General → Workflow permissions, set the default to “Read repository contents and packages permissions” and grant write access per workflow. This is now the recommended default for new repositories.

OIDC — keyless authentication for cloud providers

OpenID Connect (OIDC) lets GitHub Actions authenticate to AWS, Google Cloud, and Azure without storing any long-lived credentials as repository secrets. The workflow requests a short-lived JWT from GitHub’s OIDC provider; the cloud provider verifies it against a trust policy you configure and issues a temporary credential scoped to that specific workflow run.

No AWS_ACCESS_KEY_ID, GOOGLE_APPLICATION_CREDENTIALS JSON file, or AZURE_CLIENT_SECRET ever enters your GitHub repository. OIDC tokens expire within minutes, so even a captured exchange is useless before an attacker can act on it.

AWS — aws-actions/configure-aws-credentials

- uses: aws-actions/configure-aws-credentials@v4
  with:
    role-to-assume: arn:aws:iam::123456789012:role/GitHubActionsRole
    aws-region: us-east-1

In AWS: create an IAM OIDC identity provider for token.actions.githubusercontent.com. Create a role with a trust policy that restricts issuance to your specific repository and branch: repo:your-org/your-repo:ref:refs/heads/main. Attach only the IAM permissions the deployment step actually uses.

Google Cloud — google-github-actions/auth

- uses: google-github-actions/auth@v2
  with:
    workload_identity_provider: projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/POOL/providers/PROVIDER
    service_account: deploy-sa@my-project.iam.gserviceaccount.com

In GCP: create a Workload Identity Pool + Provider for https://token.actions.githubusercontent.com. Add a binding that scopes the principal to your repository attribute (attribute.repository/your-org/your-repo) and bind it to a service account with the minimum required roles.

OIDC requires id-token: write: add permissions: id-token: write at the job level (shown above) or the OIDC token request will be denied. Pair it with contents: read to prevent the token from being used to push to the repo.

Audit workflow files with LeakCheck before committing

Before committing a new or modified workflow file, paste its contents into LeakCheck. Common mistakes that show up in .yml workflow files:

  • Accidentally hardcoded tokens left in a run: block from a debugging session and not removed before committing
  • Base64-encoded service account credentials pasted into a with: parameter during setup and forgotten
  • A full service account JSON object pasted into a run: block to test authentication before moving it to a secret
  • A GITHUB_TOKEN referenced inline in a curl command rather than via env:

LeakCheck scans the same 40+ credential patterns in YAML as it does in source code and .env files. After a flag from GitHub’s own secret scanning, LeakCheck lets you narrow down exactly which line and pattern triggered the alert before you start a git history rewrite.

Paste your workflow file and scan with LeakCheck →

Frequently asked questions

Does GitHub mask all secret values automatically?

GitHub masks the exact string value of each secret in log output, replacing it with ***. However, masking has significant limits: it does not cover base64-encoded or URL-encoded variants of the value, does not mask partial strings or secrets shorter than roughly 6 characters, and does not apply to secrets written to workflow artifacts or to $GITHUB_STEP_SUMMARY. It also does not mask derived values — a string that concatenates a secret with other characters will not be masked. Masking is a last-line defence, not a substitute for the patterns described in this guide.

Can pull requests from forks access repository secrets?

No. Workflows triggered by the pull_request event from a fork repository cannot access secrets — GitHub withholds them to prevent an untrusted contributor from exfiltrating credentials by submitting a malicious workflow change. If you use the pull_request_target event (which does have access to secrets), never check out the head ref from an untrusted fork in that workflow context, as it would allow submitted code to run with write access to the base repository.

What is ACTIONS_STEP_DEBUG and why is it dangerous?

ACTIONS_STEP_DEBUG is a repository secret or variable that, when set to true, enables step-level debug logging in GitHub Actions. ACTIONS_RUNNER_DEBUG enables runner-level diagnostic logging. Both produce verbose output that can include environment variable values, shell command expansions, and runner state — including secrets that would otherwise remain masked. Use these flags only in a private test repository and only temporarily; always remove them once debugging is complete.

Should I use jobs.env or steps.env to pass secrets?

Use the env: key on individual steps (jobs.<job>.steps[*].env) wherever possible, rather than on the job itself (jobs.<job>.env). Secrets defined at the job level are injected into every step in the job, including third-party actions that do not need them and may mishandle them. Step-level env vars limit each secret to exactly the step that consumes it, reducing the blast radius if one step mishandles a value.

What is OIDC and do I need it for every project?

OpenID Connect (OIDC) lets GitHub Actions authenticate to cloud providers by exchanging a short-lived JWT token rather than a long-lived stored credential. The token expires within minutes and is scoped to the specific workflow run. OIDC is strongly recommended for any project that deploys to or reads from AWS, Google Cloud, or Azure — it eliminates the stored credentials most at risk of leaking. Projects that do not interact with cloud provider APIs can continue using stored repository secrets for other integrations (Stripe, SendGrid, etc.) while following the env: usage patterns in this guide.

How do I know if a third-party action is safe to use with secrets?

Review the action’s source code on GitHub before adding it. Search for core.setOutput, core.exportVariable, and console.log calls that reference parameters or environment variables derived from your secrets. Pin the action to a specific commit SHA (e.g. uses: owner/action@abc123def456) rather than a tag, so the code cannot change without you auditing the diff. Prefer actions maintained by verified publishers: GitHub’s own actions/ namespace, the cloud provider’s own namespace, or the tool’s official vendor account.

Can LeakCheck scan YAML workflow files?

Yes — LeakCheck scans any pasted text, including .yml and .yaml files. Paste your workflow file contents into LeakCheck before committing to catch accidentally hardcoded tokens, base64-encoded credentials in with: parameters, or service account JSON blocks in run: steps. LeakCheck flags the same 40+ credential patterns in YAML as it does in source code and .env files.

Related LeakCheck guides

These guides cover the other vectors where secrets commonly escape:

Also in the Copper Bay Labs ship-safety suite

Secrets in CI/CD pipelines are one layer of a broader pre-deploy security posture: