Safeguard
Security Guides•

How do you use CODEOWNERS to protect workflow files from outsiders?

A pull request can edit the workflow that checks it. Require code owner review on the workflows directory so outside changes get a named human approver.

Safeguard Security Team
3 min read

Add the workflows directory to a CODEOWNERS file and turn on required review from code owners in branch protection. Any pull request that edits a workflow file then needs approval from the named owners, which stops an outside contributor from quietly changing the pipeline that checks their code.

Why workflow files need their own rule

On the pull_request event, GitHub runs the workflow from the pull request's merge ref. A contributor can therefore propose a change to the workflow in the same pull request as the code. A harmless looking edit could drop a scan step, change a condition so a check is skipped, or point a job at a different runner.

GitHub's secure use guidance recommends exactly this protection: use CODEOWNERS to control how changes are made to workflow files, so proposed changes first require approval from a designated reviewer. Its approval guidance for fork runs also says to be especially alert to changes in the workflows directory.

Steps

  1. Create or edit CODEOWNERS in the repository.
  2. Add a line mapping the workflows directory to a small security or maintainer team.
  3. Add other pipeline files: build scripts called by workflows, Dockerfiles used in CI, dependency update configuration, and the CODEOWNERS file itself.
  4. In branch protection or rulesets, enable required review from code owners.
  5. Require at least one approval and dismiss stale approvals when new commits are pushed.
  6. Make sure the owners team has write access, since owners without it are not effective reviewers.

An example, written as plain lines in the file:

/.github/workflows/  @your-org/maintainers-security
/.github/CODEOWNERS  @your-org/maintainers-security
/scripts/ci/         @your-org/maintainers-security

What to look for when you review

ChangeWhy it matters
A new trigger such as pull_request_targetMoves the job into a privileged context
A permissions block widenedGives steps more access
A new third party actionNew code runs in your pipeline
A removed or conditional scan stepMay let a check skip
A new runs-on valueMay move a job to a different machine
New secrets referencedPossible exfiltration path

Limits to keep in mind

CODEOWNERS applies when changes arrive through a pull request. A maintainer with bypass rights can merge around it. Keep the owners list small, avoid giving admins routine bypass, and log exceptions.

Also remember that a first time contributor's workflows may need maintainer approval before running. Those two controls work together. Approval stops the run. CODEOWNERS stops the merge.

Try it yourself

Click through it at your own pace, or open it full screen.

Look at how a gate collects its conditions before it lets a change through.

Where Safeguard fits

Safeguard's policies and gates add automated conditions to a pull request, while compliance and evidence automation can keep a record of reviews. The free scan is a starting point.

Quick check

Can CODEOWNERS stop a workflow from running?

No. It controls who must approve a merge. Fork run approval controls whether a first run starts.

Should the CODEOWNERS file be protected too?

Yes. List it in itself so owners cannot be changed without owner approval.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.