MSBA-299 · Lesson 6 of 12 · 21 min
Domain review: API access and integrations
▶ Video coming soon A video version of this lesson is on the way.
On Tuesday evening, November 17, Wren began with Priya's weakest objective group from the baseline. "You missed four token and app questions out of five," she said. "Not because you do not know what a token is. Because you answered as the person who writes the script, and the exam asks as the person who sets the policy." Priya laughed, because it was true. At Tidewater she created tokens. At Skerry she had watched Amadou Ferrand-Bakari and the platform team decide which tokens anyone was allowed to create.
The third objective group of domain 3, manage API access and integrations, has four bullets: configure personal access tokens; understand rate limits for personal access tokens and GitHub Apps; describe GitHub Apps and OAuth apps; and approve or deny app usage based on policy. It is one group of three in the largest domain, so on a typical form it supplies several questions. MSBA-291 lessons 3 and 4 and MSBA-290 lesson 11 taught it.
Two kinds of personal access token
A personal access token lets a person, or a script acting as that person, call the API or use Git over HTTPS. GitHub has two kinds. A personal access token (classic) has broad scopes, such as repo or admin:org, that apply to everything its owner can reach, and it does not have to expire. A fine-grained personal access token is limited to one resource owner, a user or an organization, to selected repositories or all of them, and to specific permissions, each set to read or write; it must have an expiry date. A fine-grained token can never do more than its owner can, and it can do less, which is the point.
| Question | Classic token | Fine-grained token |
|---|---|---|
| What can it reach? | Everything the owner can reach, within its scopes | One resource owner and selected repositories |
| How are permissions expressed? | Broad scopes | Individual permissions, read or write |
| Must it expire? | No, unless a policy says so | Yes |
| Can an organization require approval? | No; it can only allow or block classic tokens | Yes, and approval is required by default |
| SAML single sign-on | Must be authorized for each SSO organization | Created for an organization through its own approval flow |
Organization owners control both kinds through a personal access token policy, and enterprise owners can set the same policies for every organization. For classic tokens the choices are to allow or restrict them and, optionally, to set a maximum lifetime, which by default is not required. For fine-grained tokens the choices are whether they may access the organization at all, whether an owner must approve each token before it works, and the maximum lifetime, which defaults to 366 days and can be set shorter. Tokens created by organization owners do not need approval. Tokens that break the policy are blocked from the organization's resources rather than revoked, so they start working again if the policy is relaxed. Owners can review pending requests and active tokens, and revoke a fine-grained token's access to the organization.
Skerry's decisions are a useful pattern. Classic tokens were restricted in stages, after the platform team found and replaced the automation that used them. Fine-grained tokens were limited to 90 days across the enterprise. Approval was required only in skerry-stores, where the point-of-sale code lives, because requiring approval everywhere would have flooded the platform team with requests. Eleven exceptions were recorded in the exception register with review dates.
Worked problem
A token policy question
An organization wants developers to keep using tokens for local scripts, but no token may reach its repositories for more than 30 days, and owners must know which tokens exist. Classic tokens are still in use by two scripts that will be replaced next month. What should be configured now, and what later?
Show solution
- Fine-grained tokens: allow them, require approval so owners see each one, and set the maximum lifetime to 30 days.
- Classic tokens: a 30-day maximum lifetime can be set for them too, but they cannot be made subject to approval, so owners cannot see each one; they must eventually be restricted.
- Restricting classic tokens today would break the two scripts; record them as exceptions with a date.
- Next month, after the scripts move to a GitHub App or fine-grained tokens, restrict classic tokens.
Answer: Now: allow fine-grained tokens with approval and a 30-day maximum lifetime, and set a 30-day maximum for classic tokens. Later: restrict classic tokens once the two scripts have moved.
Rate limits
The second bullet asks you to understand rate limits for personal access tokens and GitHub Apps. Primary limits are counted per hour. Unauthenticated requests get 60 per hour per IP address. An authenticated user, whether through a personal access token, an OAuth app or a GitHub App acting on the user's behalf, gets 5,000 requests per hour, shared across everything acting as that user. A GitHub App installation gets at least 5,000 per hour, scaling with the number of repositories and users up to 12,500, and 15,000 per hour when installed on an Enterprise Cloud organization or enterprise. The GITHUB_TOKEN in Actions gets 1,000 per hour per repository, or 15,000 for resources in an Enterprise Cloud account.
There are also secondary rate limits, which protect the service from bursts: no more than 100 concurrent requests, a points budget per minute for each endpoint, a cap on CPU time, and limits on how fast content such as issues and comments can be created. Responses carry headers that report the limit, the requests remaining, the requests used, the reset time and the resource the request counted against; a secondary limit adds a retry-after header. Well-behaved integrations read those headers and slow down instead of retrying blindly.
HTTP/2 200
x-ratelimit-limit: 15000
x-ratelimit-remaining: 14212
x-ratelimit-used: 788
x-ratelimit-reset: 1763740800
x-ratelimit-resource: coreThe exam's favourite rate limit scenario is a nightly script that runs as one person's token, touches thousands of repositories and fails halfway through with rate limit errors. The best fix is rarely "use a second token". It is to move the script to a GitHub App installed on the organization, which gets its own, larger allowance on Enterprise Cloud, does not depend on a person's account and can be limited to exactly the permissions it needs. Reducing the number of calls, for example by using GraphQL to fetch related data in one request or by using conditional requests, helps as well.
GitHub Apps and OAuth apps
The third bullet asks you to describe GitHub Apps and OAuth apps. Both let third-party or internal software use GitHub on someone's behalf, but they are built differently, and GitHub recommends GitHub Apps for new integrations.
| Question | GitHub App | OAuth app |
|---|---|---|
| Who does it act as? | Itself, or a user with a user access token | Always the user who authorized it |
| How are permissions expressed? | Fine-grained permissions chosen by the app | Broad scopes |
| Which repositories can it reach? | Only those it is installed on | Everything the user can reach, within its scopes |
| How long do its tokens last? | Installation tokens expire after one hour | Tokens last until revoked |
| Does it depend on a person staying? | No; it is owned by the organization | Yes; it stops when the user loses access |
| Rate limit | Its own allowance, larger on Enterprise Cloud | Shares the user's 5,000 per hour |
For automation inside an enterprise, GitHub Apps are usually the right answer: a service account consumes a licence and a person's token disappears when they leave, while an app is owned by the organization, has only the permissions it declares and can be installed on only the repositories it needs. In Actions, a workflow can create a short-lived installation token from an app's ID and private key when the built-in GITHUB_TOKEN is not enough, for example to trigger workflows in another repository.
Approving and denying apps
The last bullet asks you to approve or deny app usage based on policy. For OAuth apps, organizations can turn on OAuth app access restrictions, which block every OAuth app from the organization's private resources until an owner approves it; members can request approval, and owners review the requests. For GitHub Apps, only organization owners and people given the app manager role, or repository admins for apps limited to their repositories, can install an app; members can request an installation and owners approve or decline. Enterprise policies can limit who may install apps across organizations, and installations and approvals are recorded in the audit log.
Skerry's inventory from MSBA-291 is the model answer to "how do you get control of integrations": list every installed app and authorized OAuth app, find an owner and a purpose for each, remove what nobody claims, replace OAuth apps with GitHub Apps where possible, and turn on restrictions so that new integrations go through review. Of 214 app installations, 61 were kept; of 38 OAuth apps, 12 were approved and 9 replaced.
| Request | Policy answer |
|---|---|
| A team wants a project management tool that is an OAuth app | Review the scopes it requests; approve it for the organization if it is needed and no GitHub App alternative exists |
| A member wants a GitHub App on all repositories | Members cannot install it; they can request it, and an owner or app manager installs it on selected repositories |
| Nightly automation runs as a departing engineer's classic token | Move it to a GitHub App owned by the organization |
| A vendor asks for an owner's token to set up an integration | Decline; install the vendor's GitHub App with the minimum permissions instead |
Deploy keys and other credentials
Questions in this group sometimes include credentials that are neither tokens nor apps. A deploy key is an SSH key attached to a single repository, read-only by default, which suits a server that only needs to pull one repository; it is not tied to a person, but it is also not visible in organization-wide token reviews, so some enterprises restrict deploy keys by policy. SSH certificate authorities, set at enterprise or organization level, let members use short-lived certificates instead of long-lived keys. And for Actions, the GITHUB_TOKEN is created for each job and expires when the job ends, which is why lesson 7 recommends it, with least-privilege permissions, over any stored token.
Watching API access
Policies only help if someone looks at what they allow. Organization owners can list the fine-grained tokens that have access to the organization, with each token's owner, repositories, permissions and expiry, and can revoke that access. They can see which GitHub Apps are installed, with their permissions and repository selection, and which OAuth apps have been approved or denied. The audit log records token requests, approvals and denials, app installations and permission changes, and, where an owner has turned on API request events, the API calls themselves with the type of credential used. That last option is what lets a team answer "which automation still uses a person's token?", a question that domain 5 returns to.
Worked problem
Will the app fit inside its limit?
Skerry's platform team is replacing a nightly script with a GitHub App installed on the skerry organization, which is on Enterprise Cloud. The job reads settings from 4,000 repositories, using three REST calls per repository, and must finish within an hour. Will it stay inside the primary rate limit, and what else should the team watch?
Show solution
- Calls needed: 4,000 repositories times 3 calls is 12,000 requests.
- Allowance: a GitHub App installation on an Enterprise Cloud organization gets 15,000 requests per hour.
- 12,000 is inside 15,000, leaving 3,000 for retries and for anything else the app does in the same hour.
- Secondary limits still apply: the job should run requests with modest concurrency, well under 100 at once, and back off when a retry-after header appears.
Answer: Yes. 12,000 requests fit inside the 15,000-per-hour allowance, but the job should limit concurrency and honour retry-after headers. As one engineer's token, with 5,000 per hour, the same job would need well over two hours.
Priya ended the session by rewriting her flash card on this objective group as four questions to ask of any integration: who does it act as, what can it reach, how long do its credentials live, and who approved it. If an answer is "a person", "everything", "forever" or "nobody", the exam option that fixes that answer is usually the right one.
Common mistakes
MistakeFixing rate limit errors by adding more personal tokens.
InsteadMove automation to a GitHub App, which has its own allowance, and reduce calls.
MistakeExpecting an organization to require approval for classic tokens.
InsteadApproval applies only to fine-grained tokens; classic tokens can be allowed or restricted and given a maximum lifetime.
MistakeAssuming a policy violation revokes tokens.
InsteadNon-compliant tokens are blocked from the organization, not revoked.
MistakeTreating OAuth apps and GitHub Apps as interchangeable.
InsteadOAuth apps act as the user with broad scopes; GitHub Apps act with fine-grained permissions on chosen repositories.
MistakeRunning automation as a shared service account.
InsteadIt consumes a licence and depends on a person's credentials; use a GitHub App.
Summary and key terms
- Classic tokens have broad scopes and need not expire; fine-grained tokens target one owner, chosen repositories and specific permissions, and must expire.
- Token policies allow or restrict classic tokens and control fine-grained access, approval and maximum lifetime; non-compliant tokens are blocked, not revoked.
- Primary limits: 60 unauthenticated, 5,000 per user, 5,000 to 12,500 per app installation, 15,000 on Enterprise Cloud; GITHUB_TOKEN 1,000 per repository, 15,000 on Enterprise Cloud.
- GitHub Apps act as themselves with fine-grained permissions and one-hour installation tokens; OAuth apps act as the user with broad scopes.
- OAuth app access restrictions, installation requests and the app manager role put integrations under review.
- Fine-grained personal access token
- A token limited to one resource owner, selected repositories and specific permissions, with a required expiry.
- Personal access token policy
- Organization or enterprise settings controlling classic and fine-grained token use.
- Primary rate limit
- The hourly allowance of API requests for a user, app installation or token.
- Secondary rate limit
- Limits on concurrency, request bursts and content creation that protect the service.
- Installation token
- A GitHub App token for one installation, valid for one hour.
- OAuth app access restrictions
- An organization setting that blocks OAuth apps until an owner approves them.
Practice problems
Work each problem on paper first, then reveal the answer to check.
What is the default maximum lifetime for fine-grained tokens under an organization policy?
Show answer
366 days, which owners can shorten.
What rate limit does a GitHub App installation get on an Enterprise Cloud organization?
Show answer
15,000 requests per hour.
Can a member install a GitHub App on organization repositories?
Show answer
No; they can request it, and an owner or app manager installs it.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.