MSBA-290 · Lesson 7 of 12 · 25 min

Custom repository roles

▶ Video coming soon A video version of this lesson is on the way.

The seventh session started with a complaint from the stores group. Its release coordinators needed to manage webhooks that announced builds to the point-of-sale deployment system, but webhooks require the admin role, and admin also lets someone delete the repository, change its visibility and turn off branch protection. So for three years the coordinators had simply been repository administrators. Freya called it the most common pattern in her audits: people given far too much access because the predefined role that fits is one size too small.

The five predefined repository roles, briefly

MSBA-161 introduced the five predefined roles for organization repositories. They form a ladder, each including everything below it.

The predefined repository roles.
RoleIntended forKey abilities
ReadPeople who view or discuss codeClone, open issues, comment
TriagePeople who manage issues and pull requests without writing codeApply labels, assign, close and reopen issues and pull requests
WriteContributors who push codePush to branches, merge pull requests, manage releases
MaintainProject managersManage some repository settings without sensitive or destructive actions
AdminRepository ownersEverything, including security settings, webhooks, visibility, transfer and deletion

The ladder works well until someone's job sits between two rungs. A custom repository role fills the gap: it starts from one of the predefined roles and adds specific extra permissions, without moving the person up the whole ladder.

How custom repository roles work

An organization owner, or someone with a custom organization role that allows it, creates a custom repository role in the organization settings. Every custom role has an inherited role, also called its base role, which must be Read, Triage, Write or Maintain; Admin cannot be a base, because nothing can be added to it. The owner then adds fine-grained permissions from a list grouped by area, such as discussions, issues, pull requests, repository settings and security. A permission can only be added if the inherited role does not already include it.

An equation diagram. A box labeled Inherited role: Write, plus two small boxes labeled Manage webhooks and Edit repository metadata, equals a box labeled Custom role: Release coordinator. Below, a crossed-out arrow to Admin with the label not needed.
A custom repository role is an inherited role plus chosen fine-grained permissions.

GitHub's documentation gives examples of permissions that can be added: managing webhooks, editing repository metadata and setting the social preview, managing wiki settings and GitHub Pages settings, marking an issue as a duplicate, triaging discussions, and deleting code scanning alerts. The full list is long and changes as GitHub adds features, so the list in the role editor, not a remembered list, is the reference when designing a role.

Custom repository roles are defined per organization. Current documentation allows up to 20 custom repository roles in an organization; older Enterprise Server releases allowed fewer, five before version 3.19. Once created, a custom role can be assigned to a person or a team on any repository in the organization, exactly like a predefined role, and it appears in the role picker wherever access is granted.

Worked problem

Designing the release coordinator role

Stores release coordinators need to push release branches, publish releases, manage webhooks to the deployment system and edit the repository description. They must not change visibility, delete the repository or alter security settings. Design a custom role.

Show solution
  1. Pushing branches and publishing releases are part of Write, so use Write as the inherited role.
  2. Managing webhooks is an admin ability, so add it as a fine-grained permission.
  3. Editing the description is covered by the repository metadata permission, so add that too.
  4. Visibility, deletion and security settings are not added, so they stay with Admin.

Answer: A role named Release coordinator, inheriting Write, with the manage webhooks and edit repository metadata permissions added.

Permissions are additive

A person can receive repository access from several places at once: the organization's base permission, one or more teams, a direct assignment, and an organization role that grants access to all repositories. GitHub combines all of them, and the result is the sum: roles and permissions are additive. There is no way to subtract access with a role. A custom role based on Read gives nothing extra to someone whose team already grants Write; they still have Write, plus any added permissions from the custom role.

Three inputs feed into one result. Input 1, organization base permission: Read. Input 2, team stores-dev: Write. Input 3, direct assignment: custom role Security triager, inheriting Read, plus delete code scanning alerts. Result box: Write plus delete code scanning alerts, with a small warning label Mixed roles.
Effective access is the sum of every source. Conflicting sources trigger a mixed roles warning on the repository's access page.

When someone's access comes from sources that disagree, the repository's access page shows a mixed roles warning. It is not an error, but it is worth investigating, because mixed roles usually mean that access was granted for one reason and never cleaned up after another. Resolving it means changing the base permission, a team's access or the direct assignment so that one clear source remains.

Worked problem

Working out effective access

The skerry organization's base permission is Read. A developer is in the commerce-web team, which has Triage on the checkout repository, and has been given the custom role Docs steward, inheriting Read with the manage wiki settings and manage Pages settings permissions, directly on the same repository. What can she do?

Show solution
  1. Base permission gives Read.
  2. The team gives Triage, which includes Read.
  3. The custom role adds wiki and Pages settings on top of its Read base.
  4. Add them together: Triage abilities plus wiki and Pages settings.

Answer: She has Triage plus the wiki and Pages settings permissions, and the access page may show a mixed roles warning.

Keeping roles consistent across organizations

Because custom repository roles live in organizations, an enterprise with several organizations can end up with a Release coordinator role that means slightly different things in each. Skerry avoided that in two ways. First, it had only three organizations. Second, its platform team defined each role once in a configuration file and created or updated it in every organization with a script that calls the REST API. That made the role definitions reviewable in a pull request, like any other code.

Creating a role from a script. Permission names come from the API's list of fine-grained repository permissions, which should be read rather than guessed.
# 1. List the fine-grained permissions this organization offers
gh api /orgs/skerry-stores/repository-fine-grained-permissions --jq '.[].name'

# 2. Create the role, using names copied from that list
gh api --method POST /orgs/skerry-stores/custom-repository-roles \
  -f name="Release coordinator" \
  -f description="Write, plus webhooks and repository metadata" \
  -f base_role="write" \
  -f "permissions[]=<webhook permission name from step 1>" \
  -f "permissions[]=<metadata permission name from step 1>"

Priya noticed that the permission names in the API are not the same words as the labels in the role editor, and that guessing them leads to confusing errors. The platform team's script first called the API endpoint that lists the available fine-grained permissions for the organization and validated the configuration file against it, so a misspelt permission failed the pull request check instead of the deployment.

When not to create a custom role

Custom roles are powerful, but a sprawl of them is its own problem: nobody remembers what Release coordinator v2 adds over Release coordinator. Skerry wrote three rules. Create a custom role only for a job that several people do. Name it after the job, not the person. And prefer changing a process over creating a role, for example by letting a GitHub App manage webhooks centrally if that removes the need for people to manage them at all. By the end of the session the stores organization had two custom roles, Release coordinator and Security triager, and eleven fewer repository administrators.

Choosing between custom repository roles and other tools.
NeedBetter answer
Someone needs one admin-only setting on many repositoriesA custom repository role on a team, or a predefined organization role if it applies to all repositories
Someone needs to read every repositoryA predefined organization role for all-repository read, not membership of every team
Automation needs to change settingsA GitHub App with exactly those permissions
A person needs temporary elevated accessA time-limited team membership driven from the IdP, removed afterwards

Kinds of fine-grained permission

The permissions that can be added to a custom repository role fall into a few broad groups. Issue and pull request permissions cover tasks such as marking duplicates, managing labels or setting milestones without needing higher roles. Discussion permissions cover moderating and organizing discussions. Repository permissions cover settings that are normally admin-only, such as webhooks, metadata, the social preview, wiki settings, Pages settings and some branch and tag settings. Security permissions cover reading, dismissing or deleting alerts from code scanning, secret scanning and Dependabot. Knowing the groups helps when talking to teams about what they need; the exact list should still be read from the role editor or the API at the time of design.

A second worked role: the security triager

Skerry's security team had an opposite problem to the release coordinators. Two analysts needed to read every alert in the payment repositories and to dismiss false positives, but they did not need to push code. Write would have let them push; admin would have let them change everything. The security manager role from lesson 6 was too broad for two analysts working on one organization's repositories.

Worked problem

Designing the security triager role

Security analysts need to read code, view and dismiss code scanning and secret scanning alerts on payment repositories, and delete code scanning alerts raised by a misconfigured rule. They must not push or change settings. Design the role.

Show solution
  1. Reading code and alerts needs at least Read, so use Read as the inherited role.
  2. Add the security permissions for viewing and dismissing code scanning and secret scanning alerts.
  3. Add the permission to delete code scanning alerts, which GitHub documents as available for custom roles.
  4. Assign the role to a security-triage team on repositories whose data-classification property is restricted.

Answer: A Security triager role inheriting Read with alert viewing, dismissal and code scanning alert deletion added, assigned to a team.

Auditing custom roles

Custom roles change what people can do, so their life cycle should be visible. Creating, editing and deleting a custom role are recorded in the audit log, as are assignments of the role to people and teams. The REST API lists the custom roles in each organization with their inherited role and permissions, which makes it easy to compare what exists with the definitions in the configuration repository. Skerry's weekly drift check did exactly that and opened an issue whenever someone had edited a role by hand in the web interface instead of through the pull request process.

Auditing custom repository roles.
QuestionWhere to find the answer
Which custom roles exist and what do they grant?Organization settings, or the custom repository roles REST endpoint
Who changed a role definition?Audit log events for the role
Who holds the role on a repository?The repository's access page or the collaborators API
Does the live role match its approved definition?A scripted comparison against the configuration repository

Custom roles and the predefined organization roles

Custom repository roles and the predefined organization roles from lesson 6 solve different problems. A custom repository role is assigned on individual repositories, so it suits jobs that touch a set of repositories, such as release coordination for the stores group. A predefined organization role grants a bundle of access to every repository in the organization at once, so it suits jobs that genuinely span everything, such as a platform engineer who needs read access to all code to debug shared workflows. Using a custom repository role for an organization-wide job means assigning it on hundreds of repositories and remembering to assign it on new ones; using an organization-wide role for a narrow job grants far more than needed. The question to ask is how many repositories the job really touches.

Worked problem

Choosing the right tool

Skerry's architecture group, six people, must read every repository in the skerry organization to review designs, but must not push anywhere. Should they get a custom repository role or something else?

Show solution
  1. The job spans every repository in the organization, including new ones.
  2. A custom repository role would have to be assigned on each repository and on every new one.
  3. A predefined organization role granting read access to all repositories covers it in one assignment.
  4. Assign that role to an architecture team driven by an Entra ID group.

Answer: A predefined all-repository read role assigned to an IdP-backed team, not a custom repository role.

Roles when teams are connected to the IdP

Custom roles combine naturally with teams connected to IdP groups. The role defines what a job can do; the team, driven by the IdP group, defines who does the job; and the assignment of the role to the team on a set of repositories defines where. Each of the three can then change independently. When a new release coordinator joins, the identity team adds them to the Entra ID group and they receive the role everywhere the team holds it, with no GitHub change at all. When the job changes, the platform team edits the role definition through a pull request. When a new repository is created, the team is granted the role on it, which Skerry automated for repositories whose owning-team property named the stores group.

Common mistakes

  • MistakeGiving admin to anyone who needs one admin-only permission.

    InsteadCreate a custom role that inherits a lower role and adds that permission.

  • MistakeExpecting a role to remove access granted elsewhere.

    InsteadPermissions are additive; remove the source of unwanted access instead.

  • MistakeChoosing Admin as the inherited role.

    InsteadThe inherited role must be Read, Triage, Write or Maintain.

  • MistakeCreating slightly different roles by hand in each organization.

    InsteadDefine roles once in code and apply them with the API.

Summary and key terms

  • Predefined repository roles are Read, Triage, Write, Maintain and Admin.
  • A custom repository role inherits Read, Triage, Write or Maintain and adds fine-grained permissions.
  • Current documentation allows up to 20 custom repository roles per organization.
  • Effective access is the sum of base permission, teams, direct assignments and organization roles.
  • Mixed roles warnings point to conflicting sources of access that should be cleaned up.
  • Define roles as code and keep them few and named after jobs.
Custom repository role
A repository role built from an inherited role plus chosen fine-grained permissions.
Inherited role
The predefined role a custom role starts from, also called its base role.
Fine-grained permission
A single repository ability that can be added to a custom role.
Base permission
The default repository access every organization member receives.
Effective permission
The combined access a person has from all sources.
Additive permissions
The rule that access from different sources is summed, never subtracted.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Which predefined role cannot be an inherited role?

    Show answer

    Admin.

  2. A user has Write from a team and a custom role inheriting Read. What is their base level of access?

    Show answer

    Write, because permissions are additive.

  3. Where are custom repository roles defined?

    Show answer

    In an organization, for use on that organization's repositories.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz