SecOps Lab

Who approved the last agent-authored change to a pipeline file?

Trace it to a pull request and an approver, then check whether that approval gated the merge. Commands for git, gh and glab, worked on real changes to Claude Code's and GitLab's own pipelines.

By the end of this you will have four things: a commit, the pull request that merged it, the name of the person who approved it, and the setting that made the approval necessary. If one of them is missing, you will know which one and why. You need a clone of the repository, read access to it, and gh or glab logged in. The worked example is Claude Code's own public repository, so you can run the GitHub commands yourself and compare your output with mine. GitLab's commands are folded into a box at the end of step 3, worked on GitLab's own repository, and its fixes into one at the end of step 6.

Why ask

A pipeline file decides what runs with your deploy credentials. When every change to it needs a second person's approval, one person's mistake or one stolen account can't reach your deploy branch unreviewed. It is also the separation of duties an auditor tests under change management.

Coding agents make the second person matter more. An agent edits a pipeline file like any other file, and it can follow instructions planted in what it reads: GitHub lists hidden messages in issues and comments among the risks of Copilot's cloud agent. The developer who started the agent may not have read every line, so the approval can be the first time a person reads the change. A required approval assumes two people behind every change. From GitHub's documentation on rulesets:

Requiring one approval usually means two people are involved in a change: the person who wrote it and the person who approved it. That assumption doesn't hold when Copilot opens a pull request under its own app identity instead of on behalf of a person, for example when you prompt it from a shared context such as a group thread or channel.

The question tests one of the twelve controls I assess in my agent permission-expansion assessment offering, more specifically number 4: changes to pipeline definitions, CODEOWNERS and agent configuration require, on the last commit and before the merge, an approval from a person who is neither the author nor whoever started the agent. A pass covers that control in that repository. The other eleven need their own answers.

1. Decide which files count

Three groups of files change what your pipeline does.

Part of your pipeline, and of the rules that review it, may live in other repositories: reusable GitHub workflows, GitLab include: project: files, and rulesets managed with Terraform or similar tools. The last pipeline change may have landed there, so list those repositories and repeat these steps in each.

Put the paths in a shell array, and add any directory your pipeline includes files from. Keep it an array: in zsh, a single string of paths matches nothing, and git doesn't warn you.

paths=(
  .github/workflows .github/actions .gitlab-ci.yml .gitlab
  CODEOWNERS .github/CODEOWNERS docs/CODEOWNERS
  ':(glob)**/CLAUDE.md' .claude .mcp.json ':(glob)**/AGENTS.md'
  .github/copilot-instructions.md .github/instructions .cursor
)

The two :(glob)**/ entries also find instruction files in subdirectories.

2. Find the agent-authored changes

A harness can mark its work in three places: the commit author, a trailer at the end of the commit message, or the pull request it opened. This is what two of them do today.

Markers change between versions, so check a recent agent commit in your own repository before relying on one.

A marker shows that an agent took part in a commit. A change the developer wrote and only asked the agent to commit can carry the same trailer, so the list below holds every commit an agent touched. That is the set this how-to checks: telling which of them an agent mostly wrote takes a judgement git can't make, and every check in step 3 asks for the same review either way.

Then list the changes to those paths, newest first, with the author and any co-authors. To follow along, clone Claude Code's repository and start the history at the commit I used (102fafb), so that your output matches mine.

git clone --filter=blob:none https://github.com/anthropics/claude-code.git
cd claude-code
git checkout 102fafb
git log -n 4 --date=short \
  --format='%h %ad %an | %(trailers:key=Co-authored-by,valueonly,separator=%x2C )' \
  -- "${paths[@]}"
b5cbc65 2026-11-20 Mohamed Hegazy | Claude <noreply@anthropic.com>
08165a3 2026-11-01 Claude | bpasero <bpasero@anthropic.com>
0b5c91d 2026-11-01 Claude | bpasero <bpasero@anthropic.com>
7dbaea2 2026-09-29 Claude |

The newest agent-authored change is b5cbc65, to the workflow that runs Claude itself: its author is a person, and the trailer names Claude as co-author. The three below it name Claude as the author, two of them with a person as co-author.

Two cases make this harder.

The agent commits as the developer. An agent in an editor or a terminal uses the developer's git identity. Without a trailer, git can't tell its commits from the developer's. Answer the question for the last change to any pipeline file, and record that agent-authored changes can't be identified in this repository. That is a finding in its own right.

Squash merges. A squash commit keeps only the message the merge produced. A GitHub repository can default to the pull request title alone, whoever merges can edit the message, and GitLab's default is the merge request title. Step 3 reads the pull request's own commits on GitHub; on GitLab, open the merge request's Commits tab.

3. Find who approved it

The commands for both platforms read the commit from SHA. In the worked example it is b5cbc65:

SHA=$(git rev-parse b5cbc65)

On GitHub, gh fills in {owner} and {repo} from the clone's remote. Start by finding the pull request that merged the commit: its number, its author and when it merged. An empty result means a direct push.

gh api "repos/{owner}/{repo}/commits/$SHA/pulls" \
  --jq '.[] | [.number, .user.login, .merged_at] | @tsv'
111198  mhegazy  2026-11-21T01:20:20Z

Then read pull request #111198 itself: who opened it, its head commit, and who merged it and when.

PR=111198
gh api "repos/{owner}/{repo}/pulls/$PR" \
  --jq '[.user.login, .head.sha[0:7], .merged_by.login, .merged_at] | @tsv'
mhegazy  dff9462  mhegazy  2026-11-21T01:20:20Z

Next, list every review on it: the reviewer, the account type, the review's state, the commit it covers and when it was submitted.

gh api "repos/{owner}/{repo}/pulls/$PR/reviews" --paginate \
  --jq '.[] | [.user.login, .user.type, .state, .commit_id[0:7], .submitted_at] | @tsv'
morganl-ant       User  APPROVED  dff9462  2026-11-20T22:58:46Z
ant-kurt          User  APPROVED  dff9462  2026-11-21T01:19:46Z
SAM-LATITUDE5500  User  APPROVED  dff9462  2026-11-21T04:54:14Z

After a squash merge, the pull request's own commits still list their co-authors:

gh pr view "$PR" --json commits \
  --jq '.commits[] | [.oid[0:7], (.authors | map(.login // .name) | join(","))] | @tsv'
dff9462  claude,mhegazy

For a Copilot pull request, the timeline names who started each session:

gh api "repos/{owner}/{repo}/issues/$PR/timeline" --paginate \
  --jq '.[] | select(.event == "copilot_work_started") | .actor.login' | sort -u

On #111198 it prints nothing: no Copilot session appears on its timeline.

A review marked APPROVED, or a name in approved_by, proves only that someone pressed Approve. It is the review this question asks about only when a person who neither wrote the change nor started the agent approved its final version before the merge, and nobody bypassed the rules to merge it. Each of the four checks below tests one part of that. An approval counts only if it passes all four, and the change needs one approval that does.

  1. A person approved it. Bots, apps and the agent don't count. GitHub reports an app as Bot in user.type. A machine user, an ordinary account that a script logs in as, reports as User, so you need to know your own. GitHub says neither which account is a machine user nor who started the agent, and write access also comes from outside the organization: an outside collaborator, a deploy key, or an app installed on the repository. The list is your organization's members with their roles, the outside collaborators, and the apps and deploy keys that can write, read once and kept.
  2. The approver is neither the author nor whoever started the agent. GitHub blocks the author's own approval with branch protection and rulesets. The second half it enforces only inside its own Copilot integration: the person who started the task can press Approve, and the review appears in the list, but it doesn't count toward the required approvals. No rule you write knows who started an agent; a ruleset can require an approval from a named reviewer or team, which is as close as it gets. An agent that opens pull requests under its own bot identity leaves the gap open: the bot is the author, so the person who started it can approve. GitLab has a setting for each half, Prevent approval by merge request creator and Prevent approvals by users who add commits. For any other harness, this check is evidence for one change, not a setting.
  3. The approval covers the last commit, before the merge. A fix the agent pushed after the approval hasn't been reviewed, and an approval submitted after merged_at gated nothing. On GitHub, an APPROVED review's commit_id must match the pull request's head.sha.
  4. Nobody bypassed the rules to merge. On GitHub, rule insights (Settings → Rules → Insights) show each bypass of a ruleset, and the organisation audit log records an override of classic branch protection as protected_branch.policy_override.

On pull request #111198 the record is consistent with the first three. Two accounts other than the author's approved dff9462, the head commit, before the merge, and the third approval came after it. The Claude trailer is on the author's own commit, which makes the author the likeliest person to have started the agent. Nothing in git settles it: only the harness's own record does, as a Copilot timeline does. Until someone says who did, treat it as an inference. Check 1 needs the repository's own list of machine users and check 4 needs admin rights, and an outsider has neither. An outsider's answer for #111198 is a fail on 1 and 4, a pass on 2 and 3, and a fail in all, because unknown counts as a fail.

Then read the setting behind the answer. One commit is a sample, and the setting decides the next one. Look for:

On GitHub, the ruleset rules for a branch are readable with read access:

gh api "repos/{owner}/{repo}/rules/branches/main" --jq '.[]
  | select(.type == "pull_request")
  | {ruleset_id, ruleset_source_type, ruleset_source}
    + (.parameters | {required_approving_review_count, require_code_owner_review,
       dismiss_stale_reviews_on_push, require_last_push_approval})'
{"dismiss_stale_reviews_on_push":false,"require_code_owner_review":true,"require_last_push_approval":false,"required_approving_review_count":1,"ruleset_id":4126768,"ruleset_source":"anthropics","ruleset_source_type":"Organization"}
{"dismiss_stale_reviews_on_push":false,"require_code_owner_review":false,"require_last_push_approval":false,"required_approving_review_count":0,"ruleset_id":4916728,"ruleset_source":"anthropics/claude-code","ruleset_source_type":"Repository"}

On Claude Code's default branch, two rulesets carry a pull request rule: one from the organisation and one from the repository. Where rulesets overlap, GitHub applies the most restrictive version of a rule, and here that is the organisation's. Its name, which gh api "repos/{owner}/{repo}/rulesets" lists, ends in (terraform managed), so it is one of the definitions from step 1 that live outside the repository. It asks for one approval and for code-owner review, but code-owner review only applies to paths with an owner, and the repository has no CODEOWNERS file. The repository's own rule asks for no approval. Neither dismisses approvals when new commits arrive. Pull request #111198 met the organisation's rule with approvals on its head commit, and the setting would also have accepted a push made after them.

Classic branch protection and rule insights need admin rights, and the API returns 404 without them; ask whoever administers the repository.

Step 3 on GitLab

These are the same steps with glab api and jq, worked on GitLab's own repository. Commit b4aa1774 changed .gitlab/ci/workhorse.gitlab-ci.yml, and its Co-Authored-By trailer names Claude. P holds the project and SHA the commit. In a clone of your own project, set P=:fullpath, which glab fills in from the remote, and take SHA from step 2.

P=gitlab-org%2Fgitlab
SHA=b4aa1774facd37fa1bd329cbfa3057638c5d706b

Start with the merge request that merged the commit. An empty result means a direct push.

glab api "projects/$P/repository/commits/$SHA/merge_requests?state=merged" \
  | jq -r '.[] | [.iid, .author.username, .merged_at] | @tsv'
269790  stanhu  2026-11-11T04:45:35.179Z

Then read merge request !269790 itself: who opened it, its head commit, and who merged it and when.

MR=269790
glab api "projects/$P/merge_requests/$MR" \
  | jq -r '[.author.username, .sha[0:7], .merge_user.username, .merged_at] | @tsv'
stanhu  b4aa177  nao.hashizume  2026-11-11T04:45:35.179Z

Next, every approval and when it was given. approved_by lists them all, whether or not they satisfied a rule.

glab api "projects/$P/merge_requests/$MR/approvals" \
  | jq -r '.approved_by[] | [.user.username, .approved_at] | @tsv'
GitLabDuo      2026-11-10T21:24:38.302Z
nao.hashizume  2026-11-11T00:35:36.546Z

GitLabDuo is the account of GitLab Duo, GitLab's AI assistant, which the author asked for a review. To answer check 1, ask GitLab's user list which accounts are internal ones, where GitLab Duo and GitLab's alert and support bots sit.

glab api "users?username=nao.hashizume&exclude_internal=true" | jq -r '.[].username'
nao.hashizume

The same query for GitLabDuo prints nothing. A bot for a project or group access token is not an internal account and still appears, so this rules out GitLab's own assistants, not every bot you run.

For check 3, list each push to the merge request, newest first. On a public project the API serves the calls before it without a token; this one it doesn't.

glab api "projects/$P/merge_requests/$MR/versions" \
  | jq -r '.[] | [.created_at, .head_commit_sha[0:7]] | @tsv'
2026-11-10T21:20:01.327Z  b4aa177

One push, at 21:20, and both approvals came later, so they cover b4aa177.

The setting behind the answer takes three more calls. approval_state lists the rules that applied to the merge request, how many approvals each needed and whose approvals satisfied it, and glab mr approvers "$MR" prints the same as a table. The protected branch says who can push without a merge request. The project's own approval configuration holds the settings from step 6, and needs a member of the project to read it: a token from outside gets 403 Forbidden, which is what I got here. It is for the team that owns the project to run, not for you.

glab api "projects/$P/merge_requests/$MR/approval_state" \
  | jq -r '.approval_rules_overwritten,
      (.rules[] | [.name, .rule_type, .approvals_required, .approved,
         ([.approved_by[].username] | join(","))] | @tsv)'
false
All Members   any_approver  0  true  nao.hashizume
/.gitlab/     code_owner    1  true  nao.hashizume
/.gitlab/ci/  code_owner    0  true  nao.hashizume
glab api "projects/$P/protected_branches/master" \
  | jq -c '{allow_force_push, code_owner_approval_required,
      push: [.push_access_levels[].access_level_description],
      merge: [.merge_access_levels[].access_level_description]}'
{"allow_force_push":false,"code_owner_approval_required":true,"push":["🤖 GitLab Bot 🤖","GitLab Release Tools Bot"],"merge":["managers","GitLab Release Tools Bot","🤖 GitLab Bot 🤖","Maintainers"]}
glab api "projects/$P/approvals" \
  | jq -r '.merge_requests_author_approval, .merge_requests_disable_committers_approval,
      .reset_approvals_on_push'

Those three lines are the settings step 6 asks for, in the order of the query: merge_requests_author_approval and merge_requests_disable_committers_approval must read false and true to close check 2, and reset_approvals_on_push must read true so a new commit drops the approvals before it. A false on the first line of approval_state also says that the merge request kept the project's rules. Put your default branch's name in place of master.

On !269790, approval_state credits only the person. The agent's approval satisfied no rule, and check 1 rules it out as well. The code-owner rule on /.gitlab/ needed one approval and got it from someone who is neither the author nor, going by the trailer on the author's commit, whoever started the agent. The merge request's activity on GitLab shows no push after it opened, so that approval covers b4aa177, and it came before the merge. Checks 1 to 3 hold. Check 4 does not: GitLab's audit events need the Maintainer role, which an outsider doesn't have, and the protected branch shows two bot accounts allowed to push to master without a merge request. Two pipelines starting from such a push skip the review this step tests.

4. What ran before anyone approved

An approval happens at merge time, and a pipeline can run long before that. On push and pull_request, GitHub runs the branch's version of a workflow, so a workflow changed on a branch runs as soon as the branch is pushed, with every secret that branch can read.1 Pull requests from the same repository get those secrets too; pull requests from forks and from Dependabot go without.

Check four things:

Copilot's cloud agent waits by default for someone with write access to click Approve and run workflows. The Copilot settings can switch that off, so check that nobody did. On GitLab, protected variables reach only pipelines on protected branches and tags; check which of your deploy variables aren't protected.

The change in the worked example is a decision of this kind: b5cbc65 sets allow_fork_prs: "false" on the step that runs Claude, so the action skips pull requests from forks, whoever mentions @claude on them.

This leads to three more of the twelve controls, which this how-to leaves out: credentials short-lived and scoped to one repository, no long-lived cloud key in a job an agent can start, and untrusted input kept away from anything that can write workflow files.

5. Reading the answer

The change passes if the four checks in step 3 hold and you can link to the setting that required the approval. A direct push fails, and so does any check that doesn't hold. Unknown counts as a fail in your own repository: if you can't see who approved it, you can't show an auditor either.

Write it down the way I record answers in an assessment: pass or fail, the link that proves it, and the person who owns the setting.

6. Fixes, one setting each

GitHub

Step 6 on GitLab

Approval settings and code owner approval need Premium.

Last, agree as a team that the harness's attribution stays on. Without it, step 2 has nothing to find.

7. Taking it to your lead

Five lines are enough:

Repository: <owner/name>
Change:     <SHA>, <date>, <file>; agent-authored because <marker>
Approval:   <pull request link>, approved by <person> at <SHA>, or why there is none
Setting:    <ruleset, branch protection or policy> that required it, with a link
Fix:        <one setting>, owned by <person>

Commit SHAs and usernames only. Leave out secrets, tokens and any log line that might hold one.

Close with one question for your lead: should this hold for every repository on the deploy path?

Who wrote this

This is the first question I ask. I'm Alejandro Andreu, and SecOps Lab is my one-person security engineering practice in Spain. I led the CI/CD platform team at Kraken as a client engagement from 2021 to 2024, and the CI/CD team at N26 as an employee from 2019 to 2021. If you'd rather have someone else look at your pipeline, the teardown is one delivery day on one CI system, one agent harness and up to three repositories. It ends with a written summary of the three things to fix first, each with the file that proves it and an owner. Its scope and price are in the Engagements table.

Vendor behaviour checked on 19 November 2026, GitHub's workflow events on 26 November and Copilot's pull requests on 27 November. Example output captured on 27 November 2026, with the history at 102fafb.


  1. GitHub's list of events gives the commit each one runs from. pull_request_review and pull_request_review_comment run the pull request's version as well. issues, issue_comment, schedule and pull_request_target run the default branch's, so a change to a workflow on those events waits for the merge. The worked example has both kinds: claude.yml runs on comments and issues with main's version, and on reviews and review comments with the pull request's, so an edit to it on a branch is what runs when someone reviews the pull request. ↩︎