On this page
  1. Start with an inventory
  2. Require two-factor authentication
  3. Set base permissions to the minimum
  4. Lock down member privileges
  5. Treat outside collaborators as a managed population
  6. Turn on security features by default
  7. Restrict third-party access
  8. Set the Actions defaults
  9. Keep owners few and accountable
  10. A review cadence that sticks
  11. References

Most GitHub incidents do not start with an exotic exploit. They start with a member account that had no second factor, a base permission that gave every employee write access to every repository, a forgotten outside collaborator, or a public repository created by mistake. The organization settings page is where you close those doors, and most of the important switches are available on every plan.

This guide is the baseline the rest of this site builds on. Work through it once for each organization you own, then keep it as a review checklist. Where a setting is only available on GitHub Enterprise Cloud, it is called out.

Start with an inventory

Before changing anything, know what you have. The GitHub CLI and the REST API give you a quick snapshot:

shell
# Owners and members
gh api --paginate "/orgs/ACME/members?role=admin" --jq '.[].login'
gh api --paginate "/orgs/ACME/members" --jq '.[].login' | wc -l

# Members without 2FA (only visible to organization owners)
gh api --paginate "/orgs/ACME/members?filter=2fa_disabled" --jq '.[].login'

# Outside collaborators
gh api --paginate "/orgs/ACME/outside_collaborators" --jq '.[].login'

# Public repositories
gh api --paginate "/orgs/ACME/repos?type=public" --jq '.[].full_name'

Save the output. You will compare against it after the changes, and it is the first evidence you need if an auditor asks how access is governed.

Require two-factor authentication

GitHub now requires 2FA for most accounts that contribute code on github.com, but that account-level requirement is not a substitute for the organization policy. The organization setting is what lets you guarantee that every member, billing manager and outside collaborator has 2FA before they can touch your repositories.

Go to Settings > Authentication security and enable Require two-factor authentication for everyone in the organization. When you save, GitHub removes members and outside collaborators who do not have 2FA. Use the filter=2fa_disabled query above first, contact those people, and give them a deadline. Removed members can be reinstated within three months with their access and forks restored.

Then go one step further. GitHub supports requiring secure methods of 2FA only. Passkeys, security keys, authenticator apps and GitHub Mobile qualify; SMS does not. Users who only have SMS configured lose access to organization resources until they add a secure method, and outside collaborators with SMS 2FA are removed. Announce it before enabling it, and ask people to remove SMS from their accounts.

If your organization uses SAML single sign-on, the identity provider enforces MFA for the SSO step, but GitHub account 2FA still matters because the GitHub account itself can be phished or reused outside your organization. The SAML SSO and Enterprise Managed Users guide covers the identity side in depth.

Set base permissions to the minimum

Base permissions apply to every member on every repository in the organization. They are configured under Settings > Member privileges > Base permissions and the choices are No permission, Read, Write and Admin.

Set it to No permission or Read. Write as a base permission means that any compromised member account can push to every repository, including ones the person never works on. Grant write access through teams scoped to the repositories each team owns instead:

shell
# Give the payments team write access to one repository
gh api -X PUT "/orgs/ACME/teams/payments/repos/ACME/payments-api" \
  -f permission=push

# Check who has admin on a repository
gh api "/repos/ACME/payments-api/collaborators?permission=admin" --jq '.[].login'

Use the built-in roles deliberately. Triage and Maintain exist so that people can manage issues and settings without having admin. Keep Admin on repositories to a small number of people, because repository admins can change branch protection, delete the repository and add deploy keys. Organization-level rulesets limit what repository admins can undo.

Lock down member privileges

The same Member privileges page holds a set of switches that decide what ordinary members can do without asking an owner. A secure default for most companies:

  • Repository creation: allow private (and internal on Enterprise Cloud) only. Disable public repository creation for members, so a public repository is always a deliberate owner action.
  • Repository forking: disable forking of private and internal repositories unless you have a workflow that depends on it. Forks of private repositories stay owned by the user and are easy to lose track of.
  • Repository visibility change: do not allow members to change visibility. Making a private repository public is one of the most common causes of source code and secret leaks.
  • Repository deletion and transfer: do not allow members with admin rights to delete or transfer repositories. Leave that to owners.
  • Issue deletion: restrict to owners.
  • Pages creation: allow private Pages only if you need them, and decide whether public Pages sites may be published from organization repositories.
  • Team creation: members creating teams is usually harmless, but team maintainers can add people to teams that hold repository access, so review it in context.
  • Allow members to invite outside collaborators: turn this off (the setting lives under Settings > Member privileges as the outside collaborator invitation policy). Only owners should add people who are not members.

Treat outside collaborators as a managed population

Outside collaborators are not members. They do not count against base permissions, they are not bound by SAML SSO in the same way as members, and they tend to accumulate. Contractors finish, agencies change, and the access stays.

Review them on a schedule:

shell
gh api --paginate "/orgs/ACME/outside_collaborators" --jq '.[].login' |
while read -r user; do
  echo "== $user"
  gh api --paginate "/orgs/ACME/repos" --jq '.[].name' | while read -r repo; do
    perm=$(gh api "/repos/ACME/$repo/collaborators/$user/permission" \
      --jq '.permission' 2>/dev/null)
    [ -n "$perm" ] && [ "$perm" != "none" ] && echo "  $repo: $perm"
  done
done

For large organizations this loop is slow; the organization audit log (action:org.add_outside_collaborator and action:repo.add_member) and the tools in the organization audit guide scale better. If you are on Enterprise Cloud, the enterprise policy for repository collaborators can prevent members from inviting outside collaborators at all, and Enterprise Managed Users removes the category entirely.

Turn on security features by default

GitHub's security configurations (Settings > Advanced Security > Configurations) let you apply a set of features to every repository and to new repositories automatically. The GitHub-recommended configuration enables the dependency graph, Dependabot alerts and security updates, secret scanning with push protection, and code scanning default setup where the features are available on your plan. Public repositories get secret scanning, push protection and code scanning at no cost; private repositories need GitHub Secret Protection or GitHub Code Security licenses for those features.

At minimum, enable for all repositories and new repositories:

  • Dependency graph and Dependabot alerts
  • Secret scanning and push protection (see the secret scanning guide)
  • Private vulnerability reporting for public repositories

The Dependabot and dependency review guide explains how to keep the noise manageable once alerts start arriving.

Restrict third-party access

Two settings decide which applications can reach your organization's data:

  1. Settings > Third-party Access > OAuth application policy: enable access restrictions so that OAuth apps must be approved by an owner before they can read organization resources with a member's token.
  2. Settings > Personal access tokens: decide whether fine-grained tokens need owner approval and whether classic tokens are allowed at all.

Both are covered in detail in Fine-Grained PATs, GitHub Apps and OAuth Apps. Do them in the same session as this baseline; an organization with strict member privileges and unrestricted classic tokens is only half hardened.

Set the Actions defaults

Under Settings > Actions > General, three settings belong in the baseline even before you review individual workflows:

  • Workflow permissions: select Read repository contents and packages permissions so GITHUB_TOKEN is read-only unless a workflow asks for more.
  • Allow GitHub Actions to create and approve pull requests: leave it off.
  • Actions permissions: allow only actions created by GitHub, verified creators, and an explicit allowlist, and require actions to be pinned to a full-length commit SHA.

The reasoning and the YAML that goes with it are in the GitHub Actions security guide.

Keep owners few and accountable

Organization owners can do everything, including disabling every control on this page. Two or three owners is a reasonable number for most organizations; more than that should be justified. Owners should use hardware security keys or passkeys, and daily work should happen from accounts that are not owners where practical.

Check the audit log for owner changes (action:org.update_member with a role change to admin) and alert on them. The audit log guide has the queries and streaming setup.

A review cadence that sticks

A baseline decays. Put these on a calendar:

  • Monthly: outside collaborators, new public repositories, members without secure 2FA, new OAuth app and token approvals.
  • Quarterly: owners list, team memberships for sensitive repositories, repository admins, deploy keys and webhooks.
  • On every offboarding: remove from the organization (not just from teams), revoke approved fine-grained tokens, and rotate any shared secret the person could read.

Automate as much of it as possible with the API calls above or a scheduled scan such as the ones in the organization audit guide.

References

Tags:organizationidentityrepositories

Written by

Florian Amette, Security Engineer & Editor

Security engineer writing practical hardening guides for GitHub organizations, repositories and CI/CD pipelines, with a focus on software supply-chain security.