AZ-401: Pull Request Enforcement for Human and Copilot Changes
Enforce pull request (PR) review by configuring required controls on the actual target branch, binding the intended build and status producers, requiring the appropriate owners, and checking each actor's effective bypass authority. Then test rejected and permitted paths with disposable changes. Apply that verification to ordinary human changes and to changes produced with GitHub Copilot: artificial intelligence (AI) feedback and a contributor's confidence do not replace the required human approval or actual validation evidence.
Azure Repos branch policies and GitHub protected-branch rules are separate implementations. The procedure below configures each on an existing authorized nonproduction repository and branch, then checks the resulting admission behavior. It is an illustrative exercise, not a report of live policy changes, agent runs or successful tests. Branching strategy and membership are prerequisites; local hooks and scanner installation are separate subjects.
Establish the exact enforcement scope
Use Branch Strategies and Git Worktree Boundaries to select the branch's integration role, and Project Repository and Team Access Boundaries to establish the actual identities and access. Choose a disposable target branch in each platform for this exercise. Obtain its owner's agreement on the intended controls and restoration state before changing settings.
Record the following inputs using real values:
- Organization, project where applicable, repository, target branch and configuration owner.
- Ordinary contributor, independent human reviewer, code owner and authorized administrator identities.
- Existing working build pipeline or continuous integration (CI) workflow, its actual reported check names, and any existing external status producer.
- The paths requiring ownership, the matching owners and the approval count the owner has selected.
- Existing rule/policy identifiers, settings and effective permissions, including inherited or administrative bypass routes.
- The supported Copilot surface, its availability under the actual plan and organization policy, and the identity that will submit or merge a change.
Azure Repos policy editing requires Project Administrators membership or the relevant repository Edit policies permission. A build pipeline must already exist; a status producer must already be able to report PR status. Do not make a nonexistent integration required and describe the resulting permanent wait as a working gate.
For GitHub.com, protected branches and code ownership are available on public repositories with Free plans and on public/private repositories with the applicable paid plans. Confirm the repository's eligibility and actual editing authority. This exercise assumes an existing protected-branch editor accessible to its owner; it does not assume that every repository exposes the same controls or that overlapping rules combine.
Configure Azure Repos branch policies
Open Repos, Branches, the selected branch's More options, then Branch policies. Apply the following example configuration to that exact branch and save each change. Approval counts and owner identities are exercise choices, not universal vendor requirements.
| Control | Configure for this exercise |
|---|---|
| Require a minimum number of reviewers | Set the agreed count; exclude the requestor's own approval, prohibit the most recent pusher's approval, and reset approval votes after new changes. |
| Build validation | Add the existing pipeline, select Automatic and Required, and choose an explicit build-expiration setting. |
| Status checks | Add the actual reported check, select Required and Apply by default; constrain Authorized identity and reset behavior for the chosen producer. |
| Automatically included reviewers | Add the approved individuals or groups, select Required, and configure the intended path scope. |
Reopen the settings and inspect the PR's Policies section. Confirm the real pipeline, status context, owner scope and enabled requirements. Optional controls report information without supplying the intended blocking requirement. Keep a record of what changed so a later rejection can be explained against the configuration that produced it.
Treat the reviewer-count policy and the automatically included reviewer policy separately. Test the chosen reviewer set against a change inside its path scope; do not assume a general approval count proves that the designated owner participated. Use an actual posted status identifier rather than inventing one from a pipeline's display name.
Have the authorized security owner inspect and, within the agreed exercise scope, remove unintended grants for Bypass policies when completing pull requests and Bypass policies when pushing. These govern different paths. Record any deliberately retained exception and its effective actor; visible failing policy status alone does not prove an actor with bypass authority is blocked.
Configure GitHub protected-branch requirements
In the selected repository's existing branch-protection editor, target the exact exercise branch. Inspect which rule actually applies before saving; classic branch-protection rules do not simply accumulate when patterns overlap. Set the following requirements and reopen the saved rule to confirm them:
- Enable required pull request reviews and the agreed approving-review count.
- Enable required code-owner review after configuring valid ownership on the base branch.
- Choose stale-approval dismissal or an explicit most-recent-push approval requirement appropriate to the exercise, and record that choice.
- Enable required status checks, select actual check names and an expected reporting app where appropriate, and choose whether the branch must be up to date.
- Enable Do not allow bypassing the above settings when the agreed outcome includes administrators and roles with bypass permission.
Use unique check job names so different workflows do not create ambiguous results. GitHub can accept successful, skipped or neutral required-check results; inspect whether the intended validation actually executed. An accepted result is not automatically evidence that the test body ran. Preserve this distinction when evaluating the test matrix below.
Push restrictions, where eligible and configured, identify permitted users, teams or apps; they do not replace required reviews and checks. Inspect the actual actor and rule rather than treating permission to push as permission to merge any change. Leave unrelated branch restrictions intact.
Connect code ownership to required approval
For GitHub, place the CODEOWNERS file on the PR's base branch. Supported locations are .github/, the repository root and docs/, searched in that order. Map the relevant paths to real users or visible teams with the required repository write access. Inspect ownership for a representative file before using it as a gate.
For the example, map an application directory to its maintainer team and protect the CODEOWNERS file itself with the approved repository owner. Use the actual identifiers; do not copy a fictional team name into a configuration that appears valid but requests nobody.
Open a non-draft PR changing an owned file. Confirm that the intended owner is requested, then separately confirm that required-owner approval blocks merge until satisfied. Draft PRs do not automatically request code owners until made ready for review. When several owners share a pattern, one owner's approval can satisfy that ownership requirement; listing several names does not mean all must approve.
Azure Repos uses its configured required-reviewer policies for the corresponding ownership outcome. Do not assume that a GitHub CODEOWNERS file configures Azure Repos enforcement. In either platform, test routing and blocking separately: a notification establishes neither approval nor merge denial.
Verify human and Copilot merge paths
Use harmless disposable changes and an existing validation job whose failure can be induced safely. Do not introduce a secret, harmful code or a real deployment solely to demonstrate a rejection. Record the target branch, PR identifier, source revision, actual actor, configuration snapshot, expected result, actual result and decisive policy/check evidence.
Start as an ordinary contributor with no intended bypass, rather than using the configuration administrator. Perform these checks independently on each platform:
| Test state | Acceptance observation |
|---|---|
| Required human approval is missing | Merge is blocked for the ordinary actor; the missing review requirement is visible. |
| An owned path changes but the designated owner has not approved | The configured ownership requirement remains unsatisfied; an unrelated reviewer does not silently substitute. |
| The required build/check fails | The ordinary merge path remains blocked, with the actual run and source revision identified. |
| The expected check has not reported | Investigate its applicability, producer and trigger. Do not count missing evidence as validated work. |
| A new commit is added after approval | The saved reset/recent-push setting has the intended effect, and validation is assessed for the current change. |
| All required evidence is current and satisfied | The intended ordinary merge path is available, subject to the actor's independent repository permissions and any other active requirements. |
For the allowed case, merge only if the owner authorized completing the harmless exercise PR. Otherwise inspect the available merge action and record that acceptance stopped short of changing the target. A disabled action or an error message should be explained by the actual requirement, not guessed from the button's appearance.
Distinguish assistance from the submitting identity
Repeat the matrix for a change prepared with Copilot assistance. When a person submits the assisted change under their own account, the enforcement actor is that account; note the assistance as change provenance without pretending it creates another security principal.
For an actual supported Copilot agent-created PR, record the surface, initiating user, PR/commit actor and intended merge actor. Use the genuine available workflow and a benign task, then repeat missing-review and failing-check states before the satisfied state. Do not simulate a successful agent test by relabeling a human PR. If the required feature is unavailable, record the untested agent path explicitly and resolve it with the owner before claiming full actor coverage.
Copilot experiences differ in execution environments, permissions and data flows. Its application card requires careful review and testing of generated changes and positions Copilot code review as supplementary to human review. Do not turn an agent's completion message, a signed commit or AI review comments into the required human approval or proof that tests ran.
Test bypass as a separate property
Repeat the relevant inspection with the authorized privileged actor. For a disposable exercise branch, perform an owner-approved blocked-operation test if it is safe; otherwise retain the effective permission and rule evidence and state the execution limitation.
The intended outcome is either that the privileged actor is also constrained or that a specifically documented exception explains why it is not. An administrator's successful merge cannot establish ordinary-contributor enforcement. Conversely, an ordinary contributor's rejection cannot establish that administrators, apps or inherited roles lack another path.
If any ordinary human or automation identity unexpectedly bypasses the intended requirements, stop acceptance and preserve its actor, branch and permission evidence. Return the exact grant or rule to its owner; do not weaken the gate or broaden access to make the test convenient.
Keep validation execution safe before merge
Protected merge requirements do not isolate the code that a validation workflow executes. GitHub's secure-use guidance warns about untrusted checkout in privileged workflow contexts, excessive token privileges, secrets exposure and persistent self-hosted runner risk. Use the existing approved validation environment and least required access, and inspect its trust boundary before testing an unfamiliar contribution.
Do not change a workflow to execute an untrusted PR with privileged credentials merely to obtain a green check. Keep secret values out of test fixtures and logs; automatic redaction is not guaranteed. Scanner setup and workflow hardening require their own supported configuration work and are not supplied by a branch rule.
Diagnose the requirement that actually failed
For an unexpected result, preserve the current state before editing controls. Work through the evidence in this order:
- Confirm the repository, target branch, PR source revision and actor.
- Inspect the applicable saved rule/policy and whether the relevant requirement is enabled and blocking.
- Trace the check name, reporting identity, run and actual result; inspect skipped or neutral outcomes rather than assuming execution.
- Check path matching, base-branch ownership and the exact reviewer whose vote counted.
- Inspect effective bypass permissions, administrator applicability and other active branch requirements.
An approval received before the last meaningful change may be insufficient under the chosen review settings. A check that reports under another name may leave the required one pending. A reviewer request can be correct while required-owner enforcement is absent. These observations identify different repairs; changing every control together obscures which one caused the problem.
Restore the exercise without removing shared protection
Compare the final state with the recorded baseline. Restore only the rule/policy entries, reviewer mappings and permission edges deliberately changed for this exercise, through their owners. Preserve earlier requirements and unrelated actor grants. If the owner chooses to keep the new configuration, document that retained state instead of calling it a restoration.
Close or complete disposable PRs according to the agreed outcome and remove only owned test branches when authorized. Preserve the before-and-after configuration and the acceptance evidence. Do not remove a shared CODEOWNERS file, disable protection on a real release branch, or delete the working validation pipeline as cleanup.
The resulting handoff should explain which branches and actors are governed, which evidence blocks them, and which privileged exceptions remain. A screenshot of enabled settings alone cannot answer those questions.
Authoritative Sources
- Set and manage branch policies — Azure Repos required reviews, validation, status, reviewer scope and bypass permissions.
- About protected branches — GitHub eligibility, requirements, check results and administrator applicability.
- About code owners — Base-branch ownership, eligible owners and required approval.
- Application card: GitHub Copilot Agents — Surface-specific capabilities, limitations and human oversight.
- Secure use reference — Workflow token, secrets and untrusted-execution boundaries.

