Nexus Void Research
GitHub, Repository Security, Branch Protection, CODEOWNERS, GitHub Actions, Secret Scanning, Supply Chain Security, How-to
How to Secure a GitHub Repository: Branches, Secrets, Actions
How to secure a GitHub repository: enforce 2FA, least-privilege teams, branch protection with code owners, push protection, and hardened GitHub Actions.
To secure a GitHub repository, require two-factor authentication for everyone, give people and tokens the least access they need, protect the default branch with rules that require pull request reviews and passing checks and block force pushes, turn on secret scanning with push protection, lock down GitHub Actions (read-only GITHUB_TOKEN, actions pinned to commit SHAs, no secrets for untrusted pull requests), and review access and audit logs regularly.
Your repository is the front door to everything you ship. Anyone who can push to the default branch, change a workflow or read a secret can put code in front of your customers. Supply chain frameworks such as SLSA and the OpenSSF Scorecard check most of the controls below. This guide walks through them in order of impact, for a single repository or a whole organisation.
Step 1: Secure the accounts
Require two-factor authentication for every organisation member and outside collaborator, preferably with passkeys or security keys.
Use single sign-on for the organisation if your plan supports it, so leaving the company removes GitHub access automatically.
Review outside collaborators and remove anyone who no longer needs access.
Limit organisation owners to a small number of people who use a separate, well-protected account for admin work if possible.
Step 2: Give least-privilege access
Who | Give |
|---|---|
Most developers | Write on the repositories they work on, through teams |
Reviewers of sensitive code | Membership in a CODEOWNERS team |
Release managers | Maintain, not Admin |
Admin | Two or three people, not everyone who asks |
Contractors | Time-boxed access to specific repositories |
Manage access through teams, not individual grants, so it is easy to see and revoke. Prevent members from changing repository visibility or creating public repositories unless that is part of your workflow.
Step 3: Protect the default branch
Use branch protection rules or repository rulesets on main (and release branches):
Require a pull request before merging, with at least one approving review.
Require review from code owners for sensitive paths.
Dismiss stale approvals when new commits are pushed.
Require status checks to pass: tests, build, and security checks.
Require conversation resolution before merging.
Block force pushes and branch deletion.
Apply the rules to administrators too, or keep bypass to a named break-glass group.
Add a CODEOWNERS file so changes to authentication, payments, infrastructure and workflow files always get the right reviewer:
Step 4: Keep secrets out of the repository
Turn on secret scanning and push protection, so a commit containing a recognised credential is blocked before it lands.
Store CI secrets in encrypted secrets, scoped to environments with required reviewers for production.
Never commit
.envfiles, cloud credentials or Terraform state.
If a secret has already been committed, rotate it, then follow how to remove secrets from git history.
Step 5: Lock down GitHub Actions
Workflows run with access to your code, secrets and sometimes your cloud accounts, so they are a favourite target.
Set the default
GITHUB_TOKENpermission to read-only at the organisation or repository level, and grant write per job only where needed.Pin third-party actions to full commit SHAs, because tags can be moved to malicious code.
Restrict which actions can run to those from your organisation, verified creators or an allow-list.
Be careful with
pull_request_targetandworkflow_run: they run with secrets in the context of the base repository, so never check out and run code from an untrusted pull request in them.Never interpolate untrusted input such as issue titles or branch names directly into
run:scripts; pass them through environment variables.Use OpenID Connect to get short-lived cloud credentials instead of storing long-lived cloud keys.
Require approval for workflows from first-time contributors on public repositories.
We go deeper in how to secure a CI/CD pipeline with GitHub Actions.
Step 6: Control tokens, keys and apps
Prefer fine-grained personal access tokens scoped to specific repositories, with an expiry, over classic tokens.
Require approval for personal access tokens that access organisation resources.
Use read-only deploy keys unless a deployment truly needs to push.
Review installed GitHub Apps and OAuth apps, their permissions and which repositories they can access. Remove anything unused.
Protect webhooks with a secret and verify signatures on the receiving end.
Step 7: Watch dependencies
Turn on dependency alerts and security updates, and review new dependencies in pull requests. See how to resolve Dependabot alerts for clearing the backlog without drowning in noise.
Step 8: Make it easy to report and review
Add a
SECURITY.mdthat tells researchers how to report vulnerabilities, and enable private vulnerability reporting.Review the audit log for unexpected permission changes, new deploy keys, token approvals and disabled protections.
Run OpenSSF Scorecard against your repositories to spot missing controls:
scorecard --repo=github.com/your-org/your-repo.Review access quarterly: members, teams, collaborators, apps, deploy keys and tokens.
GitHub repository security checklist
Check | Done when |
|---|---|
2FA required | Organisation enforces 2FA for all members and collaborators |
Least privilege | Access via teams; few admins; contractors time-boxed |
Branch protection | PR reviews, code owners, status checks, no force push, admins included |
CODEOWNERS | Sensitive paths and workflow files have owners |
Secret scanning | Push protection on; secrets in encrypted CI storage |
Actions hardened | Read-only token, SHA-pinned actions, no untrusted code with secrets |
Tokens and apps | Fine-grained, expiring tokens; apps reviewed |
Dependencies | Alerts and updates on; new packages reviewed |
Reporting and audit | SECURITY.md; audit log and access reviewed |
How does ARGUS help secure GitHub repositories?
Pull request review on every PR. The ARGUS GitHub App reviews pull requests when they are opened or updated, comments inline with a suggested fix, and can post a required commit status so you can make "ARGUS security review" one of the checks your branch rules require.
It never approves. ARGUS requests changes when a Critical or High finding lands on changed lines, but approvals stay with your human reviewers and CODEOWNERS.
Merge audit record. ARGUS keeps a record of each pull request, including those merged with unresolved findings, so accepted risk is visible.
GitHub Actions checks. ARGUS checks the actions in your workflows against known advisories, flags any action not pinned to a full commit SHA, and reads runtime versions from
actions/setup-*steps to flag end-of-life Node, Python, Java and other toolchains.Secret, dependency and code scanning on the full repository, with findings ranked by exploitability, and Assign to Agent fix pull requests that go through your normal review.
Limits: pull request review runs on GitHub; the App needs write access to contents only for agentic fix pull requests. ARGUS does not manage your organisation's settings or branch rules for you. See ARGUS AI code review, or scan a repository free.
Frequently asked questions
How do I secure a GitHub repository?
Require two-factor authentication, grant least-privilege access through teams, protect the default branch with required reviews, code owners and status checks, block force pushes, enable secret scanning with push protection, harden GitHub Actions, use fine-grained expiring tokens, review apps and audit logs, and add a SECURITY.md.
How do I protect the main branch on GitHub?
Create a branch protection rule or ruleset for main that requires a pull request with approving reviews, code owner review, passing status checks and resolved conversations, dismisses stale approvals, blocks force pushes and deletion, and applies to administrators too.
What GitHub Actions settings matter most for security?
Set the default GITHUB_TOKEN permission to read-only, pin third-party actions to full commit SHAs, restrict which actions may run, avoid running untrusted pull request code in pull_request_target workflows, pass untrusted input via environment variables, and use OIDC for cloud credentials.
Should I pin GitHub Actions to a commit SHA?
Yes, for third-party actions. Tags such as v4 can be moved to point at different code, including malicious code if the action's repository is compromised. A full commit SHA is immutable. Use a tool such as Dependabot to keep pinned SHAs updated.
What is CODEOWNERS and why does it matter for security?
CODEOWNERS is a file that assigns owners to paths in a repository. With branch protection requiring code owner review, changes to sensitive areas such as authentication, infrastructure and workflow files cannot merge without approval from the right team.
Fine-grained or classic personal access tokens?
Fine-grained tokens. They can be limited to specific repositories and permissions and must have an expiry, so a leaked token does far less damage. Organisations can also require approval before fine-grained tokens access their resources.
How do I check my GitHub repository's security posture?
Run OpenSSF Scorecard against the repository, which checks controls such as branch protection, token permissions, pinned dependencies and dangerous workflows. Also review the organisation's audit log, member and app access, and branch rules on a regular schedule.
What should a SECURITY.md file contain?
How to report a vulnerability privately (an email address or private vulnerability reporting), what information to include, which versions are supported, and what response time to expect. It gives researchers a safe channel so issues reach you before they reach the public.
DATA SOURCES
SLSA: https://slsa.dev/ ; OpenSSF Scorecard: https://scorecard.dev/