Skip to main content

Triage and Remediation

Remediation

Using Console

Below are concise, step‑by‑step instructions to reduce excessive repository admins in GitHub using the web console (GitHub.com UI).

1. Confirm You Have Permission

You must be:
  • An Organization Owner (for org repos), or
  • A Repository Admin (for personal or org repos)
to change admin permissions.

2. List Current Admins for a Repository

  1. Sign in to GitHub.com.
  2. Open the repository:
    https://github.com/<org-or-user>/<repo-name>
  3. Click Settings (top menu in the repo).
  4. In the left sidebar, click:
    • Collaborators and teams (for org repos: “Manage access”)
  5. Under Manage access, review:
    • Teams with access and their permission level
    • Individuals with access and their permission level
Anyone with Admin permission here is effectively a repo admin.

3. Reduce Individual Admins to Lower Roles

For each user who doesn’t truly need admin rights:
  1. In Settings → Manage access, find the person with Admin access.
  2. Click the gear icon (or three-dot menu) next to that user.
  3. Under Repository access, change:
    • From: Admin
    • To: Maintain (for maintainers) or Write (for regular contributors)
  4. Click Save or Update access.
Repeat for all users who should not be admins.

4. Use Teams Instead of Individual Admins (Org Repos)

If you are in an organization:
  1. Go to the org page: https://github.com/<org>
  2. Click Teams.
  3. Create or choose a team (e.g. repo-maintainers).
  4. Click the team → RepositoriesAdd a repository to this team.
  5. Select the repository and set permission to:
    • Maintain for people who manage issues/PRs but don’t need admin, or
    • Write for regular contributors.
  6. Remove individual Admin access for those now covered by the team (same method as step 3).

5. Remove Unnecessary Teams with Admin Access

  1. In the repository, go to Settings → Manage access.
  2. Under Teams, find any team with Admin level.
  3. Click the gear icon next to the team.
  4. Change permission:
    • From Admin
    • To Maintain or Write, as appropriate.
  5. Save changes.

6. Restrict Who Can Be a Repo Admin at Org Level (Optional)

For organizations to keep admin counts low going forward:
  1. Go to the Organization page.
  2. Click Settings.
  3. In the left sidebar, review:
    • Member privileges / Repository creation / Base permissions.
  4. Set:
    • Base permissions to Read (or lower), not Admin.
    • Restrict who can create repositories or manage settings to Organization owners only.
  5. Ensure only a small set of Organization Owners exist (Org Settings → People → change role from Owner to Member where appropriate).

7. Periodically Audit Admins

  1. On a schedule (e.g. monthly), for each critical repo:
    • Go to Settings → Manage access.
    • Export or screenshot current access.
  2. Remove or downgrade permissions that are no longer needed.

If you share your repo type (personal vs organization) and current number of admins/teams, I can suggest an exact target layout (e.g., “1 owner + 1 maintainers team + write-only contributors”).
Below is a concise, step‑by‑step way to identify and reduce excessive repo admins using the GitHub CLI (gh).Assumptions:
  • You have gh installed and authenticated (gh auth login).
  • You’re an admin/owner on the repo or org.
  • Replace OWNER (user/org) and REPO with your values.

1. List who has admin access on a repository

A. List collaborators and their permissions (classic collaborators)

This shows logins that have admin: true via direct collaborator access.

B. List teams with admin access (for org repos)

Members of these teams may effectively be “repo admins” depending on team permission.

C. (Optional) List org members with admin role (org‑wide)

Use this to identify who can manage repos/org settings globally.

2. Decide the minimal required admins

Offline step:
  • For each admin user or team, decide:
    • Keep as admin,
    • Downgrade to maintain or push, or
    • Remove.
Document the desired target state: user/team → new permission.

3. Downgrade or remove individual repo admins

A. Change a collaborator’s permission (e.g., admin → maintain)

Valid values: pull, triage, push, maintain, admin.

B. Remove a collaborator entirely


4. Downgrade or remove admin teams

A. Change team permission on the repo (admin → maintain, for example)

B. Remove team access to the repo


5. Reduce organization‑wide admins (if needed)

Use this carefully—org admins lose global powers.

A. List current org admins

B. Change a user’s org role from admin → member

C. Remove a user from the org (if appropriate)


6. Re‑verify effective repo admins

Re‑run checks:
Confirm the list is limited to the strictly necessary admins.
Below is a practical, step‑by‑step way to reduce excessive repo admins in GitHub using Python (via the GitHub REST API and/or PyGithub).

1. Preparation

  1. Decide the policy you want to enforce, for example:
    • Only a specific team(s) can be admin.
    • Or max N admin users per repo.
  2. Create a GitHub Personal Access Token (PAT) with at least:
    • repo
    • admin:org (if managing org repos, teams, etc.)
Export it as an environment variable (recommended):

2. Install Python dependencies


3. Enumerate Admins and Decide Remediations

3.1. Using PyGithub to list repos and their admins

Use this output to decide which users/teams should no longer have admin rights.

4. Implement Least-Privilege Changes

4.1. Define allowed admins (policy)

Example: only one “core-admins” team plus maybe some specific user(s) per repo.

4.2. Downgrade or remove excessive admins

Run in dry-run mode first by commenting out the change lines and just printing what would happen.

5. Safer: Dry-run / Audit Mode

Add a DRY_RUN = True flag:

6. (Optional) Using Raw REST API via requests

If you prefer not to use PyGithub:
  • List collaborators with permission: GET /repos/{owner}/{repo}/collaborators?permission=admin
  • Change a collaborator’s permission: PUT /repos/{owner}/{repo}/collaborators/{username} with body: {"permission": "push"}
Minimal example:

7. Governance

  • Run the audit/remediation script periodically (e.g., as a GitHub Action or CI job).
  • Log all changes.
  • Optionally notify affected users/teams before/after changes.
If you describe your exact policy (who should remain admin and in what cases), I can adjust the Python logic and permissions transitions precisely to match it.
Changing a collaborator’s permission does not replace the repository; it updates access in place, but it is immediately effective and may block previous admin/push actions.For verification, terraform plan should show:
  • No change to github_repository.repo
  • github_repository_collaborator.admin with permission = "admin"
  • All other github_repository_collaborator.* changing from admin/push to the lower permission you chose (e.g., pull).