A field guide to AI agents operating in Slack, GitHub, and Linear — covering permission design, side effects, failure modes, and safe testin

GitHub App Permissions for Autonomous PR Agents

Scope a GitHub App tightly, or your PR agent can rewrite its own CI.

· 11 min read · Updated
Cover illustration for “GitHub App Permissions for Autonomous PR Agents”
Agent Permission Design · October 12, 2026 · 11 min read · 2,451 words

An autonomous PR agent that uses the default GITHUB_TOKEN inside an Actions run hits a wall almost immediately: GitHub places the resulting pull_request workflow runs into an approval-required state, which blocks the very CI checks the agent exists to trigger. That single structural trap explains why the authentication habits built for human developers and simple CI scripts do not transfer cleanly to agents that decide, on their own, when to branch, commit, and open a pull request. When a human developer types git push, or a CI script responds to that push, you get a predictable, bounded actor. An agent that autonomously decides when to act is a different kind of actor, and it needs a credential built for that difference rather than one borrowed from either of its neighbors.

Three authentication options exist in practice, and only one of them fits. Personal Access Tokens are long-lived, broadly scoped, and tied to a personal account's rate limit. They are not supported for agentic workflows, because the credential persists well past the job that needed it and grants far more access than any single agent task requires. GITHUB_TOKEN GITHUB_TOKEN is scoped to the single workflow run, so it does not persist past the job, but it introduces the approval-gate trap described above: an agent that opens a PR with it can end up blocking its own CI. GitHub App installation tokens avoid both failures. They are scoped to exactly the permissions the App was granted, they expire automatically after one hour, and they carry a rate limit of 5,000 requests per hour per installation, separate from any personal account's limit.

The security argument for the App model is straightforward: an App configured with only the permissions it needs limits the damage of any compromise to a narrow, well-defined surface. A PAT with write access across every repository an account can touch has no such limit. Everything that follows in this piece, the permission manifest, the token handoff, the webhook subscriptions, the branch protection layer, assumes the App as the starting primitive. None of it works if the agent is still authenticating like a person.

The minimum permission set a PR agent needs, and the explicit exclusions that matter as much as the inclusions

A PR-creating agent needs a small, specific set of repository-level permissions, and nothing past that set adds real capability. Every permission beyond the floor is scope creep: it expands what a compromised credential could do without expanding what the agent is actually built to accomplish.

The floor consists of two permissions. pull_requests: write is required for creating, updating, and commenting on pull requests, which is the core job of the agent. metadata: read comes implicit on every GitHub App installation and cannot be removed, so it is not a decision point so much as a fact of the platform.

A handful of permissions are conditionally useful, and each should be added only when the agent's actual task requires it. checks: write lets the agent post check run results alongside a PR, relevant when the agent runs its own analysis and wants to surface it as a check. actions: read lets the agent read workflow status and CI results without the ability to trigger or modify runs, useful for an agent that diagnoses a CI failure before proposing a fix. issues: write matters only if the agent manages labels or comments as part of its PR workflow; if issue tracking stays inside deterministic GITHUB_TOKEN bookkeeping, the agent does not need it. statuses: write is for an agent that also reports commit statuses, not one that simply opens PRs.

The exclusions carry as much of the argument as the inclusions, maybe more. administration grants control over branch protection rules and repository settings; an agent with that permission can remove the guard rails meant to constrain it, defeating the purpose of scoping it. No agent that opens PRs needs secrets access, full stop on that point: reading or writing repository secrets has nothing to do with proposing code changes. workflows: write deserves particular attention, because teams often assume the App permission manifest is the control that keeps an agent out of .github/workflows. It is not. GitHub does not offer path-scoped read-only access to that directory as a real App primitive, so granting workflows: write opens a lateral escalation path: an agent that can edit workflow files can rewrite the CI pipeline that is supposed to check its own work. You have to keep the agent out of that directory at the application layer, inside the worker's own file-edit allow-list, not inside the App's permission grant. Finally, environments and deployments sit outside the scope. If an agent also controls deployment environments, it is no longer a PR agent, and it needs its own, separate review.

Structuring the token handoff so the agent never holds a credential past the job that needed it

A correctly scoped App registration sets the ceiling on what an agent can do, but the ceiling only holds if the token flow underneath it is built correctly. Scope on paper means little if the credential that reaches the agent process outlives the job, or if it leaks into a log file.

The minting sequence has three steps, and each one carries its own credential lifetime. First, the App's private key, using RS256, signs a JSON Web Token valid for at most 10 minutes. This JWT is the only persistent credential in the entire flow, and it has to live outside the agent process: on disk, at a restrictive file permission, never in an environment variable that ends up captured by a logging system. Second, that JWT is exchanged for an installation token, the credential scoped to exactly the permissions configured on the App and bound to the specific installation. Third, the agent caches that installation token for reuse across the job, with a buffer before its real expiry (treating it as expired five minutes early is a practical pattern) so the agent never races a token that is about to lapse in the middle of an operation. You put the token cache in a local file, not a shared store, and it gets invalidated the moment the process exits.

Logs need scrubbing for secrets before archival, because an installation token that appears in a trace log stays a live, usable credential for the full hour until it expires on its own.

It helps to place this handoff inside a broader model, one that shows what level of access each action represents. Think of agent actions as sitting on a ladder of increasing authority. Early rungs cover read-only operations and dry-run output: plan and diff generation that an agent can produce entirely unattended and that a human reviews before anything is written anywhere. Higher rungs cover reversible mutations, the category a pull request actually belongs to: opening a PR changes nothing in the codebase until a human merges it, and that is why pull_requests: write paired with contents access and nothing else maps cleanly onto that reversible tier. The top rungs cover irreversible or high-blast-radius actions: this is the territory of administration and secrets. If you refuse those two permissions, you keep the agent off that top rung, regardless of how the rest of its token handoff is built.

This layered posture is consistent with where GitHub itself has moved. GitHub Agentic Workflows, in technical preview as of February 2026, run with read-only permissions by default, and any write operation requires explicit approval through "safe outputs" that map to pre-approved GitHub operations such as opening a pull request or adding a comment, enforced through sandboxed execution, tool allowlisting, and network isolation. GitHub made the same choice for its Copilot app: per-write permission prompts became the default there, not an opt-in config flag and not an enterprise policy pack layered on top. The platform itself recommends explicit, named, reversible opt-in when it comes to broader autonomy. Broad access is never the starting point.

That posture exists because confirmation prompts can be fooled. Research into what's been called the "GhostApproval" pattern found agents getting developers to approve edits where the confirmation dialog displayed a harmless-looking filename while the actual write landed somewhere else entirely, somewhere sensitive. A confirmation UI must show the true target, scope, and reversibility of an action to function as a gate. The implication for App scoping is direct: the permission manifest has to be narrow enough that even a confirmation dialog silently pointed at the wrong target cannot produce top-rung damage. If the App never holds administration or secrets in the first place, a misdirected approval can only reach as far as a pull request, not as far as a repository setting or a credential store.

Webhook events to subscribe to and the ones that create unnecessary trigger surface

Permissions govern what a token can do once it exists. Webhook subscriptions govern what causes the agent to act at all, and that is a second attack surface that deserves the same minimal-surface discipline applied to permissions. If an App subscribes to every available event, it receives payloads for actions the agent was never built to handle, and each unnecessary payload is both a processing cost and a potential vector for prompt injection.

A PR-creating agent needs a specific, short list of events. pull_request.opened, pull_request.synchronize, and pull_request.closed cover the lifecycle of PRs the agent opened or is tracking. A push event matters when the agent's trigger is a branch push. issues.labeled issues.labeled matters for the "label an issue, get a PR" workflow, documented across several cloud coding agent products as a standard trigger, where the agent's trigger is a label. check_run.completed and workflow_run.completed matter for an agent that waits on CI results before deciding whether to act.

Events like pull_request_review.submitted, pull_request_review_comment.created, and status. Subscribing to review events when the agent only opens PRs, and never reviews them, produces a steady stream of payloads the agent will simply discard. Each discarded payload still had to be received, validated, and routed, and each one is a small, standing opportunity for an attacker to try smuggling something through.

The webhook receiver's own design matters as much as the subscription list sitting in front of it. The receiver should validate the HMAC signature on every incoming payload, filter by event type before anything reaches the agent, and enqueue events rather than process them inline, so if traffic suddenly floods in, it does not block the agent process or burn through its rate limit. For agents triggered off fork pull requests, one event deserves particular caution: pull_request_target runs with access to the base repository's secrets, and it should be used only with documented precautions, never checking out untrusted PR code inside the same job that has access to those secrets.

Branch protection as the guard rail the App permission model cannot provide on its own

A correctly scoped App can open pull requests against a branch, but nothing in its permission manifest stops that same credential from pushing straight to the default branch instead. That constraint does not live in the App's permissions.

Branch protection rules handle two constraints the permission model cannot. The first is a straightforward rule against direct pushes to main: branch protection, not App permissions, is what actually enforces that an agent cannot write straight to the default branch. The second concerns force-pushes. Agents should never appear on a branch's bypass list, and the branch protection rule needs to apply to the App's bot identity exactly the way it applies to any human committer on the repository.

A related gap sits inside the file-edit restrictions described earlier: GitHub does not offer the App a way to be restricted to read-only access on a specific path like .github/workflows. That is not a configuration the App permission system supports. The protection against an agent editing workflow files has to be built and enforced by the worker itself, checking every proposed diff before it pushes and rejecting anything that touches that directory.

Budget and rate limits fall into the same category of things the App permission model does not handle. Per-repo, per-day limits on how many PRs an agent can open belong at the dispatcher or orchestration layer, sitting above the App entirely, not inside the App's own configuration. The full picture, then, is a stack of independent layers: a narrow App scope, branch protection on top of it, a worker-side file allow-list, and a dispatcher-level budget ceiling. That stack is defense in depth in the ordinary sense: any one layer can fail on its own without the whole system failing with it.

Testing the full permission and token flow with a stateful GitHub API simulator

Testing a GitHub App's permission configuration against the real API forces a choice between two bad options: a real repository, which risks an accidental push landing somewhere it shouldn't, or a throwaway repository, which lacks the realistic state needed to exercise the flows permission scoping is actually meant to constrain. Neither option gives confident coverage of what matters, which is the sequence of calls an agent makes in practice, not any single call in isolation.

The flows that matter to validate are inherently stateful. Creating a branch, pushing a commit, opening a PR, confirming that a check run appears against it, and confirming that a direct push to main gets rejected are five steps that depend on each other in sequence. None of them can be tested against a stateless mock that just returns the same fixed payload regardless of what came before it.

A stateful GitHub API simulator solves this by holding the repository's state across sequential calls. Pushing a branch makes it show up in later list calls. Opening a PR makes it appear in later queries against that repository. Attempt a write the simulated App's scope does not permit, and the simulator returns the correct 403, exercising the agent's error-handling path before that agent ever runs against a live repository. For CI specifically, a simulator like this starts with the job, exposes a localhost endpoint the agent points at instead of the real GitHub API, maintains state through the entire PR-creation sequence, and shuts down when the job ends. No live credentials touch the test run, you burn no rate limit, and no test suite can accidentally open a pull request against a real repository.

Fault injection extends the same approach into failure conditions that are hard to produce on demand in production: simulating a 429 when the installation token endpoint is under load, or a 403 when a required permission is missing from the manifest. Running the agent's retry and fallback logic against those simulated failures confirms that the logic actually works, rather than waiting for those conditions to show up unannounced against a live installation.

Related guide

More in Agent Permission Design