Block an agent from deleting GitHub branches
Configure a SecureAuth Agent Authority policy that allows the pull-request workflow while denying destructive branch and file writes on GitHub.
An agent that can open and manage pull requests is genuinely useful. The same agent with the power to merge, force-overwrite a branch, or rewrite files directly is one bad prompt away from losing history you can't get back. The GitHub MCP server's tool set has no single delete_branch call, so the practical protection is denying the tools that remove or overwrite branch content: merge_pull_request (which folds a branch into another, and on repos with "automatically delete head branches" enabled, removes it in the process), push_files (a multi-file commit written straight to a branch, bypassing review), create_or_update_file (a single-file version of the same), and delete_file (removes a file from a branch in a single commit). This walkthrough denies those four and leaves the core pull-request workflow open.
What you'll need
- The GitHub resource added to your gateway (Add GitHub)
- An agent connected to open the pull requests (Connect an agent)
- Admin access to Access Policies
- If your organization still has the default Allow all rule, disable or delete it first — otherwise the allow rule below is redundant, since anything it doesn't match falls through to Allow all and succeeds anyway. (The deny rule still bites either way: it sits above Allow all and is matched first.)
Removing Allow all flips the whole org to deny-by-default, not just GitHub deletes: from then on every tool matching no rule is denied, reads included. This agent keeps only what the allow rule below grants it, so get_file_contents, list_issues, search_code and every other GitHub read stop working unless you add them — get_*, list_*, and search_* alongside the patterns in step 5 cover the common ones. Anything else in the org that was quietly riding on the fall-through loses access too, so add the rules those workloads need before you remove it.
Steps
Create the allow rule first, since rule order matters: new rules land at the top of the table, so creating the deny rule second puts it above the allow rule, where the first matching rule wins.
- Navigate to Access Policies and click Add Rule.
- Name it "Allow PR workflow."
- Set the effect pill to Allow.
- Set the MCP scope pill to GitHub.
- Add the tool pattern
*pull_request*— it matches every tool withpull_requestin its name:create_pull_request,create_pull_request_with_copilot,update_pull_request,update_pull_request_branch,list_pull_requests,search_pull_requests,pull_request_read,pull_request_review_write, andadd_reply_to_pull_request_comment. It also matchesmerge_pull_request, but that's fine: the deny rule you create next lands above this one and catches everymerge_pull_requestcall first, so this rule never sees it. None of the other nine touches branch content directly —update_pull_request_branchonly merges the base branch's latest commits forward (the same effect as clicking GitHub's "Update branch" button) and fails on conflicts instead of overwriting anything, so it's safe to leave allowed here. - Add
create_branchandlist_branchesso the agent can cut a working branch and see what already exists. Addadd_comment_to_pending_reviewtoo: the pattern in step 5 misses it, and it's the middle step of the standard review flow —pull_request_review_writeopens a pending review,add_comment_to_pending_reviewadds the inline comments, and submitting finishes it. Without it the flow breaks halfway. If your agent uses Copilot reviews, addrequest_copilot_reviewandget_copilot_job_status(the follow-up to the already-matchedcreate_pull_request_with_copilot) on the same grounds. - Set the status to Active and click Create. It lands at the top of the table, at position 1 — a disabled Allow all rule may still appear below it, since disabling only removes a rule from evaluation, not from the table.
- Click Add Rule again to create the deny rule: name it "Block destructive GitHub writes," effect Deny, MCP scope GitHub.
- Add these tool patterns:
merge_pull_request,push_files,create_or_update_file,delete_file. - Set the status to Active and click Create. New rules land at the top of the table, so this deny rule takes position 1, above the allow rule — exactly the order you need.
Verify it works
- Have the agent call
create_pull_request. It should succeed. - Have it call
merge_pull_request. It should fail. - Have it call
push_files,create_or_update_file, ordelete_file. All three should fail too. - Open Agent Trail (Audit log) and confirm the pattern: the PR creation shows a successful
gateway.tool.executedevent, and each denied call showsgateway.tool.errorwitherror_type: blocked_by_policy, naming "Block destructive GitHub writes."
Next steps
- Credential modes — compare SecureAuth's app against bringing your own GitHub OAuth app before you install.
- Tags — label every production repository's resource and scope this deny rule to a Resource tag instead of one server.
- Give Claude read-only access to Jira — the same deny-by-default shape on a different resource.
Give Claude read-only access to Jira
A worked SecureAuth Agent Authority policy that lets Claude search and read Jira issues while blocking every create, edit, and transition call.
Sandbox an agent to one Slack channel
Scope a SecureAuth Agent Authority policy so an agent can only read and post in one designated Slack channel, not your whole workspace.