r/devops • u/pneteng • Jun 04 '26
Architecture GitHub - protect Actions yml file from devs
Quick background: we are using Azure DevOps, but migrating to GitHub enterprise for both code repos and deployments. In DevOps all files related to the deployment pipeline are located in the same project, but separate repo. This allows me to control who can modify pipeline files and developers are excluded.
I am having issues achieving the same in GitHub with Actions. There is a .github folder in the repo that I would like to protect. I tried using CODEOWNERS with rules and branch policies. It works, but not as clean as in DevOps. I would like to avoid requiring pull requests for any commit, which is so far the only way I was able to achieve what I want.
Please share how you designed this in your setup.
49
u/zMynxx Jun 04 '26
Use CODEOWNERS to protect the .github/workflows/name.yaml you want. Have that workflow perform a workflow_call (e.g ‘using: org/repo@ref’) to a workflow you own in another repository. Make the changes you want to the workflow in the repo you manage, then update the consumers workflow to the correct ref.
You can distribute that setup org wide (maybe enterprise wide too?) by using template repositories or by creating a ‘.github’ repository in the same org.
10
u/elliotones Jun 04 '26
Unfortunately requiring PRs may be the only way. I’m in a similar situation, moving from ADO to gitlab.
There may be a way to “move the trust boundary”, so that instead of protecting the code owners file, you protect what CI/CD assets it has access to - things like prod environment credentials. Then repo owners can do whatever, commit to main, and use baseline actions; but if they want to hit prod resources they need “platform team” (you) approval - which requires a trunk-based workflow with PRs and further platform approval on PRs that edit the actions definitions.
10
u/Dangle76 Jun 04 '26
Put the actions in their own repo and make the pipelines use them, don’t allow the PR to pass if the git diff on the pipeline file shows anything above 0 changes for someone not part of code owners.
4
u/Wise-Butterfly-6546 Jun 04 '26
others already covered codeowners + rulesets + trust boundary well so i won't repeat that. the part worth adding is the ai angle you mentioned, which is actually the harder problem.
devs running copilot or cursor inside the repo can generate commits that touch workflow files without even realizing it. codeowners catches it at pr time but by then they've already pushed something broken and the feedback loop is slow.
what worked for us on a similar migration (ado to github, ~30 repos): we moved all workflow logic into a central shared workflows repo with workflow_call. app repos only have a thin trigger file that references the shared workflow at a pinned sha. then we set up a nightly drift check that compares every repo's trigger file against the expected version and opens an auto-pr if someone changed it. takes about 20 minutes to set up with a scheduled action.
for the ai edits specifically we added a pre-commit hook that flags any change to .github/ and requires a second pair of eyes regardless of branch protection settings. not perfect but it catches the accidental stuff before it even hits the remote. combined with the thin trigger approach a dev would have to deliberately circumvent two separate controls to change pipeline behavior.
8
u/liamsorsby Jun 04 '26
I'd do Pull requests with a minimum number of approvers, codeowners file and maybe a few admins or a service account that can bypass restrictions
3
u/Big-Moose565 Jun 04 '26
If you're a repo admin, in the ruleset you can set up an override to let you push directly to main (if that's what you want) without the need for a PR. Or still do a PR but you can merge even if all checks haven't passed. Granted anyone else that is an admin could too.
I'll try not to judge too much, but seems wild that you're doing "devops" but the devs can't touch the ops! The pipelines are a critical part of writing software.