Auditing Access and Permissions

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 10 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Auditing Access and Permissions in GitHub

Introduction: The Criticality of Access Governance

In the modern software development lifecycle, your source code is your most valuable intellectual property. If the keys to your repository are lost, stolen, or improperly shared, the entire integrity of your product is compromised. Auditing access and permissions in GitHub is not merely a task for compliance officers; it is a fundamental operational necessity for any engineering team that prioritizes security and code quality. When we talk about auditing, we are referring to the systematic process of reviewing who has access to your organization’s resources, what level of access they possess, and whether that access remains necessary for their current role.

Many organizations fall into the trap of "permission creep," where users are granted broad access at the start of a project, but those privileges are never revoked as their roles change or the project scope shifts. Over time, this leads to an environment where dozens of individuals have administrative rights they no longer need, exponentially increasing the risk of accidental deletion, unauthorized code changes, or data leaks. By mastering the art of auditing, you transition from a reactive posture—where you scramble to fix security gaps after an incident—to a proactive stance, where you maintain a "least privilege" environment as a matter of standard practice.

This lesson will guide you through the technical mechanisms of GitHub auditing, from manual reviews in the browser to automated reporting using the GitHub API and CLI tools. We will explore how to identify stale accounts, manage outside collaborators, and ensure that your repository protection rules are actually being followed.


Not read yet

Understanding the GitHub Permission Hierarchy

Before we can audit effectively, we must understand exactly what we are looking at. GitHub uses a hierarchical permission model that starts at the organization level and flows down to individual repositories. If you do not understand the distinction between a "Member" and an "Owner," or how "Repository Roles" interact with "Team Permissions," your audit will be fundamentally flawed.

Organizational Roles

  • Owners: These users have full administrative access to the organization. They can manage other members, change billing settings, and delete the entire organization.
  • Members: These are standard users who can contribute to repositories, but they cannot manage the organization’s high-level settings.
  • Outside Collaborators: These are individuals who are not members of your organization but have been granted access to specific repositories. This is the most common area where security gaps arise, as these users are often forgotten after a project concludes.

Repository Roles

  • Read: Allows users to view the code, clone the repository, and open issues.
  • Triage: Designed for project managers; allows users to manage issues and pull requests without needing write access to the code.
  • Write: Allows users to push changes directly to the repository (unless protected branches prevent this).
  • Maintain: Allows users to manage repository settings, including labels and milestones.
  • Admin: Full access to the repository, including the ability to delete the repository or change its visibility.

Callout: The Principle of Least Privilege The core philosophy of auditing is the Principle of Least Privilege (PoLP). This security concept dictates that every user, process, or program should only have the minimum set of permissions necessary to perform its intended function. If a developer only needs to read code to review a pull request, they should not have 'Write' access. If they only need to fix bugs, they should not have 'Admin' access. When in doubt, grant the lowest level of permission possible and elevate only when a specific task requires it.


Not read yet

Conducting a Manual Audit: Where to Start

If you are just beginning to manage your GitHub security, start with a manual audit. This will give you a feel for the landscape and help you identify obvious outliers.

1. Reviewing Organization Members

Navigate to your organization’s "People" tab. Sort the list by "Role" to see all Owners. You should be able to count the number of Owners on one hand. If you have ten or twenty owners, you have too many. Every owner is a potential target for account takeover attacks.

2. Identifying Outside Collaborators

This is the most important step for many teams. Go to the "People" tab and select "Outside collaborators." This list shows everyone who has access to your private or internal repositories but isn't part of your core team. Review each name. Ask yourself: "Is this person still actively working on this project?" If the answer is no, remove them immediately.

3. Repository Access Review

For each critical repository, click on the "Settings" tab and then "Collaborators and teams." This view provides a breakdown of who has access and how they obtained it. Look for individuals who have "Direct Access" rather than access via a "Team." Managing permissions via teams is a best practice because it centralizes user management; if someone leaves the team, you remove them from the team, and they automatically lose access to all associated repositories.


Not read yet

Automating Audits with GitHub CLI (gh)

Manual audits are fine for small organizations, but they do not scale. As your organization grows to dozens of repositories and hundreds of users, you need automation. The GitHub CLI (gh) is a powerful tool for fetching data that you can then pipe into scripts or logs.

To audit repository collaborators using the CLI, you can use the gh api command to query the GitHub REST API directly. Here is a practical example of how to fetch all collaborators for a specific repository:

# Fetching collaborators for a specific repository
gh api repos/{owner}/{repo}/collaborators --paginate

The --paginate flag is essential here because GitHub will only return a subset of results per request. By using this command, you can export the data into a JSON file, which can then be parsed by a script to identify "Write" or "Admin" users.

Building an Audit Script

You can create a simple shell script to identify users with "Admin" access across all your repositories. This helps you find "shadow admins"—people who may have been given admin rights for a temporary task but never had them revoked.

#!/bin/bash

# Define the organization
ORG="your-org-name"

# Get a list of all repositories
REPOS=$(gh api orgs/$ORG/repos --paginate -q '.[].name')

echo "Auditing Admin access for $ORG..."

for repo in $REPOS; do
  echo "Checking $repo..."
  # Fetch users with admin role for this repo
  admins=$(gh api repos/$ORG/$repo/collaborators?affiliation=direct --paginate -q '.[] | select(.permissions.admin == true) | .login')
  
  if [ ! -z "$admins" ]; then
    echo "Admins found in $repo: $admins"
  fi
done

Warning: API Rate Limiting When running automated audit scripts, be mindful of GitHub's API rate limits. If you have hundreds of repositories, a script that queries every single one sequentially might trigger a rate limit error. For large-scale audits, consider adding a sleep delay between requests or using a tool like the GitHub Audit Log streaming feature to capture events in real-time rather than polling the API.


Not read yet

Advanced Auditing: The Audit Log

While checking current permissions tells you the state of your organization right now, the Audit Log tells you how you got there. The Audit Log records every action taken within your organization, such as when a user was added, when a repository was made public, or when an access token was used.

Why the Audit Log is Indispensable

If a security incident occurs, the Audit Log is your primary source of truth. It allows you to trace the actions of a compromised account or identify who authorized a change to a sensitive branch protection rule.

How to Access the Audit Log

  1. Navigate to your organization's settings.
  2. Click on "Audit log" in the left sidebar.
  3. Use the search filters to narrow down your inquiry.

You can filter by:

  • Action: e.g., repo.access, org.add_member, hook.create.
  • Actor: The user who performed the action.
  • Timeframe: When the event occurred.

Monitoring Sensitive Actions

You should create a process to periodically review actions such as:

  • repo.change_visibility: Changing a private repository to public is a massive risk.
  • org.update_member: Promoting a member to an owner.
  • branch_protection_rule.destroy: Removing the guardrails that prevent accidental code merges.

Not read yet

Best Practices for Access Management

Auditing is only effective if you have a solid foundation of access management. If your foundation is cracked, your audit will just reveal a series of failures.

1. Use Teams for Everything

Never grant direct repository access to individuals. Always create a Team (e.g., "Frontend-Developers," "DevOps-Engineers"), grant the team access to the repository, and then add members to that team. This allows you to manage permissions at the group level, making audits significantly easier.

2. Implement Branch Protection

An audit isn't just about who has access; it's about what they can do with that access. Enable branch protection rules on your main or production branches. This requires:

  • Pull request reviews before merging.
  • Status checks to pass (e.g., CI/CD tests).
  • No force pushes (to prevent history rewriting).

3. Enforce Fine-Grained Personal Access Tokens (PATs)

Standard PATs often have too much scope. When developers need to authenticate, encourage or enforce the use of "Fine-grained tokens." These tokens allow you to specify exactly which repositories a token can access and exactly what actions it can perform, rather than granting access to all repositories in the user's account.

4. Regularly Prune Inactive Users

Set a recurring calendar event (e.g., once a quarter) to review your organization's membership. If an employee has left the company or moved to a different department, their access should be revoked immediately. Many organizations use SCIM (System for Cross-domain Identity Management) via SAML SSO to automate this; when a user is disabled in your identity provider (like Okta or Azure AD), they are automatically removed from your GitHub organization.

Note: SAML SSO Integration If you are on a GitHub Enterprise plan, integrating your organization with your company's SAML Single Sign-On (SSO) provider is the single most effective way to secure your organization. It ensures that when someone leaves the company, their access to GitHub is terminated instantly across all repositories.


Not read yet

Common Pitfalls and How to Avoid Them

Even experienced teams make mistakes when auditing permissions. Being aware of these pitfalls can save you from a security headache.

Pitfall 1: Over-Reliance on "Admin"

Many developers feel entitled to "Admin" access because it makes their lives easier. They don't have to wait for someone else to change a setting. However, Admin access is dangerous.

  • The Fix: Use the "Maintain" role whenever possible. It provides the ability to manage issues and settings but does not allow for the destruction of the repository or the modification of sensitive security settings.

Pitfall 2: Forgetting Service Accounts

Service accounts (used for CI/CD pipelines, bots, or automated reporting) are often given broad permissions and then forgotten. Because they don't have human owners who check their email, they often remain active long after the project they were created for has been archived.

  • The Fix: Treat service accounts like human accounts. Audit them during every review cycle. Ensure they are using the least privilege required and have clear documentation on who owns/manages them.

Pitfall 3: Ignoring "Public" Repository Exposure

Sometimes, a developer might accidentally change a repository visibility from "Private" to "Public" to share a link with a vendor. This is a common source of data leaks.

  • The Fix: Use GitHub's organization settings to restrict who can change repository visibility. By default, only Owners should have the ability to make a repository public.

Pitfall 4: The "Audit-and-Forget" Mentality

Auditing is not a one-time project. It is a recurring operational process. If you audit once and then ignore it for two years, your permissions will drift back into a chaotic state within months.

  • The Fix: Embed auditing into your team's culture. Make it a part of the "offboarding" process for employees and a standard item in your quarterly security reviews.

Not read yet

Comparison Table: Audit Methods

Method Effort Level Scalability Use Case
Manual UI Review Low Low Small teams with < 5 repositories.
GitHub CLI Scripts Medium Medium Medium-sized teams needing automated reports.
Audit Log API High High Large enterprises with strict compliance needs.
Identity Provider (SSO) High (Setup) Very High Mandatory for security at scale.

Implementing a Security-First Workflow

To truly master access management, you need to shift from "auditing after the fact" to "governance by design." This means creating workflows that prevent permission bloat from happening in the first place.

The "Request-Approval" Workflow

For sensitive repositories, do not allow developers to grant themselves access. Implement a request-approval workflow. If a developer needs access to a repository, they must open an issue or a pull request in a dedicated "access-management" repository. This creates a paper trail of why access was granted, by whom, and when.

Documentation as Audit Evidence

When you perform an audit, document the findings. Create a simple report that includes:

  1. The date of the audit.
  2. The scope (which repositories were checked).
  3. The number of users removed or downgraded.
  4. Any anomalies found and how they were resolved.

This documentation is invaluable if you ever undergo a formal security audit (like SOC2 or ISO 27001). It proves that your team is not just talking about security, but actively practicing it.


Not read yet

Addressing Common Questions (FAQ)

Q: How often should I audit my organization? A: For most organizations, a quarterly audit is appropriate. If you are in a highly regulated industry (finance, healthcare), you may want to move to a monthly cadence.

Q: What do I do if I find an unauthorized user in my repo? A: Remove them immediately. Then, check the Audit Log to see when they were added and who added them. Finally, review any commits they made or pull requests they merged to ensure no malicious code was introduced.

Q: Can I automate the removal of outside collaborators? A: Yes, you can use the GitHub API to identify collaborators who have not contributed in the last 90 days and automatically remove them. However, be careful with automation; always test your scripts on a test repository before running them on production code.

Q: What is the difference between "Collaborators" and "Contributors"? A: "Collaborators" are people you have explicitly granted access to. "Contributors" are people who have submitted code to your repository (via pull requests) but may not have direct access to push code. You generally don't need to "audit" contributors in the same way you audit collaborators, as they don't have persistent access.


Not read yet

Summary of Best Practices

  1. Centralize via Teams: Move away from individual repository permissions and move toward team-based permissions.
  2. Enforce SSO: If your plan allows it, use SAML/SSO to link GitHub access to your corporate identity provider.
  3. Automate the Audit: Use the gh CLI to generate reports on repository access rather than relying on manual clicking.
  4. Review the Audit Log: Make it a habit to check the organization Audit Log for suspicious activity like repository visibility changes or member role escalations.
  5. Prune Regularly: Set a recurring schedule to remove stale accounts and outside collaborators.
  6. Use Protected Branches: Ensure that even those with access cannot bypass code review processes.
  7. Document Everything: Keep a record of your audits to demonstrate compliance and accountability.

Key Takeaways

  • Access management is a continuous process, not a one-time task. The moment you stop auditing, your security posture begins to degrade as users change roles and projects evolve.
  • The Principle of Least Privilege is your north star. Always aim to provide the minimum access required for the job. If a user is asking for more, force them to justify why the current permission level is insufficient.
  • Automation is the key to scalability. While manual reviews are a great starting point, they will inevitably fail as your organization grows. Use the GitHub CLI and REST API to create repeatable, reliable audit processes.
  • The Audit Log is your best friend during an investigation. Understanding how to navigate and search the Audit Log is the most critical skill for responding to security incidents effectively.
  • Service accounts require the same scrutiny as human users. Do not overlook automated bots or CI/CD tokens, as these are often the most overlooked entry points for attackers.
  • Culture matters as much as tools. Educate your team on why these permissions exist. When developers understand that these rules are in place to protect their own work, they are much more likely to follow them without friction.
  • Visibility is the first step to control. You cannot secure what you cannot see. By consistently auditing and maintaining a clean list of who has access to your code, you eliminate the "shadow" access that often leads to data breaches.

By following these guidelines, you will move beyond simple compliance and build a robust, secure environment for your development team. Access management is one of the most impactful things you can do to protect your organization's future, and by taking ownership of this process today, you are setting your team up for long-term success.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.