Your forked merge requests are running with your secrets
One pipeline decision controls whether a stranger's merge request can read your deploy keys. Here's how to check it in five minutes.
Open source projects take merge requests from strangers. That’s the point. The problem starts when the pipeline that tests those merge requests runs on the same runners, with the same variables, as the pipeline that deploys to production.
On GitLab, a merge request from a fork runs its pipeline in the fork by default, with the fork’s runners and the fork’s variables. That default is safe. It stops being safe the moment a maintainer clicks Run pipeline on the merge request in the parent project to get a green check, because that pipeline runs the contributor’s code with the parent project’s variables and runners. GitHub has the same trap under a different name: workflows triggered by pull_request_target run with the base repository’s secrets.
The five minute check
- List every CI/CD variable at the project, group and instance level.
- For each one, check whether it is protected. Protected variables only reach pipelines on protected branches and tags.
- Check who can run parent-project pipelines for fork merge requests, and whether anyone does it routinely.
- Check which runners pick up those jobs, and what else those runners can reach.
If any deploy credential is unprotected and fork code ever runs in your project, a merge request can print it, encode it, or send it somewhere. Masking doesn’t help much here. It hides the value in the job log, but it does nothing to stop a script from base64-encoding the value or posting it to a server.
Masking is a log filter. It is not access control.
Read the job before you run it
When a maintainer runs a fork pipeline in the parent project, they are approving code execution with project credentials. Treat it that way. Read the diff to .gitlab-ci.yml, to any script the pipeline calls, and to build files that execute code, such as Makefile, package.json scripts or setup.py. A one-line change to a test helper is enough to read the environment.
Fence secret jobs off from fork code
Jobs that need credentials should refuse to run for merge requests that come from another project. The predefined variables make that a two-line rule:
deploy-staging:
stage: deploy
rules:
- if: $CI_MERGE_REQUEST_SOURCE_PROJECT_ID && $CI_MERGE_REQUEST_SOURCE_PROJECT_ID != $CI_PROJECT_ID
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
environment: staging
script:
- ./deploy.sh
This does not replace protected variables. It is a second wall in case someone unprotects a variable to debug something and forgets to change it back.
What I do instead
- Every deploy credential is protected and scoped to one environment.
- Where the platform supports it, pipelines get short-lived tokens through OIDC federation instead of stored keys, so there is nothing long-lived to steal.
- Fork pipelines run on a dedicated runner pool with no secrets and no egress beyond the package mirror.
- Deploy jobs require an approval on a protected environment.
- A canary token sits in an unprotected variable. If it ever gets used, I know someone tried.
That last one costs nothing and has caught more probing than any scanner I’ve run.
Where this lands in the standards
NIST SP 800-218 asks you to secure the environments where software is built (PO.5) and to protect all forms of code from unauthorized access and tampering (PS.1). The DoD Enterprise DevSecOps Fundamentals treat the pipeline itself as part of the attack surface. A pipeline that hands production credentials to unreviewed code is the shortest path through both.