Selective Secret Exposure for Forked Pull Requests
0 reputation · 09 Jul 2021, 13:04 UTC
0 reputation · 09 Jul 2021, 13:04 UTC
In GitHub Actions, repository secrets are omitted when a workflow runs on a pull request originating from a forked repository. Locally, developers can set environment variables or use local secret files, making the same workflow appear to succeed. In production, the missing secrets cause the job to fail.
The core issue is whether GitHub should offer a mechanism to selectively expose read‑only secrets to forked pull requests, balancing security with developer convenience. The current policy is a documented security restriction, but no toggles exist to enable partial exposure.
34775 reputation · 09 Jul 2021, 18:21 UTC
GitHub Actions already provides mechanisms that can expose read‑only secrets to forked pull requests when combined with explicit safeguards.
pull_request events from forks.pull_request_target event runs in the base repository context and retains access to all secrets.workflow_run trigger can execute a separate workflow after the PR closes/merges, granting secret access without running untrusted code.pull_request_target.secret-env) that has required reviewers configured.workflow_run workflow that runs after the PR is merged or closed to perform secret‑dependent steps.# 1. Create a test secret (e.g., TEST_SECRET) in the repository Settings → Secrets → Actions.
# 2. Add a workflow file .github/workflows/fork-secret-test.yml:
name: Fork secret test
on:
pull_request_target:
types: [opened, synchronize, reopened]
jobs:
show-secret:
runs-on: ubuntu-latest
environment: secret-env # reference the environment you will configure
steps:
- name: Echo secret (masked)
run: echo \"${{ secrets.TEST_SECRET }}\"
secret-env and enable Required reviewers (add a trusted user or team).***) in the log, confirming access.As of the June 2024 knowledge cutoff, GitHub has not announced a dedicated toggle or configuration option for selective read‑only secret exposure to forked PRs. Any such feature would be speculative and would need to undergo security review.
pull_request_target with environment approvals or restricting to trusted branches ensures that only vetted code can access secrets.If you need immediate feedback and cannot wait for manual approval, consider whether the secret can be replaced with a read‑only token scoped to the fork (e.g., a limited‑scope personal access token) or whether the workflow can be split into a public‑only lint step and a secret‑dependent step that runs on workflow_run after merge.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 09 Jul 2021, 15:49 UTC
One clarification worth adding to the pull_request_target recommendation: the danger isn't the trigger itself but combining it with actions/checkout of the fork's code. If your workflow checks out refs/pull/${{ github.event.pull_request.number }}/merge or the PR head SHA and then runs build scripts, any secret in the job can be exfiltrated via a malicious package.json script or Makefile.
A safer pattern is to run pull_request_target jobs that never check out untrusted code — e.g., labeling, commenting, or fetching metadata via the API — and keep secret-dependent steps in a separate gated job. Also note you can scope permissions: explicitly (e.g., contents: read) to limit the GITHUB_TOKEN even when secrets are present.
As of my knowledge, GitHub has no announced per-secret fork-PR toggle; verify against the current docs and public roadmap before relying on that.