Let gitlab-bot approve product code for Medium-risk MRs

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/638236 (item 4) and https://gitlab.com/gitlab-org/gitlab/-/work_items/634847

What does this MR do and why?

What changes. In the required [Maintainers] section, GitLab Bot becomes a co-owner of 17 product-code entries, next to the human owners already there:

  • app, EE and lib code (including lib/api/ and lib/gitlab/), the metrics server, assets and views;
  • locale files;
  • feature-flag, metrics and events definitions.

Two HAML entries are also added. GitLab Bot's approval can then count as the maintainer approval on files where one of those entries is the last [Maintainers] match. No path loses or changes a human owner.

Why Nov 16. From Nov 16, 10% of Medium-risk merge requests written by a maintainer of this project will merge on Duo review plus GitLab Bot's approval, with the author as the one human (#638236 item 4). Today GitLab Bot is a code owner only of spec paths. Its approval on those merge requests therefore satisfies no rule, and every one of them still waits for a second maintainer.

Of the 39 Medium-rated merge requests maintainers wrote between Oct 20 and Nov 9, a GitLab Bot approval would clear every code owner rule on 6 today and on 25 with this change.

What stays human.

  • This file and the approval machinery. .gitlab/CODEOWNERS, CI and the review agent's configuration (.gitlab/), and the code that enforces code owner rules, merge request approval rules and settings, and security policies.
  • Tooling and dependencies. Lint suppression lists, tooling and scripts, dependency manifests and lockfiles, and release files.
  • Sensitive code. Migrations and schema (/db/, /ee/db/), /config/ and /ee/config/ (secrets, encryption, database config, routes and schedules), and rake tasks.
  • Every other required section, including [Database], [Authorization], [Authentication], [Application Security], [Compliance], [Seat Management] (SOX-scoped paths) and [Verify]. Merge requests touching those paths still need those owners.

What this MR doesn't do. It approves nothing by itself. GitLab Bot approves only on the MR approval flow's verdict, and the Medium path ships separately in triage-ops: maintainer authors only, a 10% sample, re-checked on every push, and no auto-merge. Compliance confirmed this model on Nov 5 (#638502).

Why more than /app/? CODEOWNERS applies the last matching entry, and assets, views, locale and EE code each have their own entry. Granting only /app/ would clear 7 of the 39 merge requests; /app/, /lib/ and /ee/ alone would clear 9. 23 of the 39 touch ee/.

Reviewers

  • @ayufan: development-leaders approval for the .gitlab/CODEOWNERS rule.
  • @mattkorich: review.
  • @mittalsunny93: for visibility, as the development process asks for CODEOWNERS changes. Please also confirm that no granted path is on Internal Audit's SOX in-scope list.
  • @gitlab-com/gl-security/appsec: please review the scope of the grant and the human-only entries.
  • FYI @tkuah, who is reworking [Maintainers] in #594402 (closed) and reviewed !263290 (closed).

I'm happy to drop any granted entry you'd rather keep human, or to add more human-only entries.

Details for reviewers: evidence, exact entries, controls, compliance mapping, rollback, validation

Background

Today GitLab Bot's approval on these merge requests lands only on the All Members any-approver rule, which requires zero approvals. This is the same gap that !260344 (merged) closed for /spec/ and /ee/spec/, !262311 (merged) for /spec/frontend/, and !266783 (merged) for the view specs.

The MR Risk Labeler's Medium verdict carries gitlab-bot::manual-approve, and nothing in triage-ops approves on it yet. That path is gitlab-org/quality/triage-ops!4550 (merged). It is stacked on gitlab-org/quality/triage-ops!4549 (merged) and gitlab-org/quality/triage-ops!4551 (merged), which move GitLab Bot's approvals onto the MR Risk Labeler's rating.

Evidence

Sample: the 39 merge requests in this project written by a direct Maintainer of gitlab-org/gitlab that carried test-gitlab-bot::risk::medium, Oct 20 to Nov 9.

Method: each merge request's changed files were matched against this file, using the last match per section and honouring ! exclusions. A merge request counts as cleared when every [Maintainers] entry it hits lists @gitlab-bot and it hits no other required section.

Merge requests
A GitLab Bot approval clears every code owner rule, today 6 of 39
A GitLab Bot approval clears every code owner rule, with this MR 25 of 39
Still needs a human, by design 14

Why the 14 still need a human:

Reason Merge requests
Lint todo lists (they switch checks off) !263674 (merged), !268608 (merged), !268611 (merged), !268621 (merged)
Other required sections: [Verify], [Duo Chat], [Category:Duo Chat], [Analytics Dashboards definitions] !268731 (merged), !267416 (merged), !268803 (merged), !268973 (merged)
Technical writing tooling: /doc/.vale/ and [Technical writing - documentation guidelines] !268309 (merged), !268313 (merged)
This file and its rake task !268428 (merged)
/qa/ !268709 (merged)
package.json, yarn.lock, *.js outside the app !269157 (merged)
/config/ (an initializer) !269258 (merged)

Documentation needs no change here: [Maintainers] already exempts doc/**/*.md, images, OpenAPI YAML and data/**/*.yml with ! patterns.

Scope

All changes are in [Maintainers]. I checked them against all 116,969 file paths on master. No path's human owners change in any section.

17 entries gain @gitlab-bot. Pattern tokens are byte-identical, so validate-codeowners-coverage sees the same /dir/ tokens.

Area Entries
Backend product code /app/ /ee/ /lib/ /metrics_server/ /locale/
Views /app/views/**/*.erb /ee/app/views/**/*.erb
Frontend product code /app/assets/ /ee/app/assets/
Instrumentation and flags /config/metrics/ /ee/config/metrics/ /config/events/ /ee/config/events/ /config/feature_flags/ /ee/config/feature_flags/
Generated path helpers /app/assets/javascripts/lib/utils/path_helpers/*.js and its EE twin

2 anchored HAML entries are added right after *.haml. They have the same owners as *.haml, plus the bot. 2,426 of the 2,428 HAML files on master live under app/ and ee/app/, so granting the unanchored *.haml would reach more than that. *.haml keeps its owners.

35 human-only entries are added right after /shared/. They override /app/, /ee/ and /lib/ for the paths below. Each keeps today's effective owner, @gitlab-org/maintainers/rails-backend, and every later, more specific entry still applies.

What Entries
Rake tasks: lint, CI, password, secrets and permission checks /lib/tasks/ /ee/lib/tasks/
Code owner and approval rule engine: what decides whether a merge request is approved /ee/lib/gitlab/code_owners.rb /ee/lib/gitlab/code_owners/ /ee/app/models/approval*.rb /ee/app/models/approval_rules/ /ee/app/models/approvals/ /ee/app/models/merge_requests/approval*.rb /ee/app/models/concerns/approval_rule*.rb /ee/app/models/concerns/ee/approvable.rb /ee/app/models/concerns/visible_approvable.rb /ee/app/models/concerns/deprecated_approvals_before_merge.rb /app/models/approval.rb /app/models/concerns/approvable.rb /app/models/merge_request/approval*.rb /ee/app/services/approval_rules/ /ee/app/services/concerns/approval_rules/ /ee/app/services/concerns/merge_requests/approval_rules_attribute_mapping.rb /ee/app/workers/approval_rules/
Security policies, including merge request approval policies, and approval settings /ee/app/services/security/scan_result_policies/ /ee/app/services/security/security_orchestration_policies/ /ee/app/workers/security/scan_result_policies/ /ee/app/workers/security/delete_approval_policy_rules_worker.rb /ee/app/models/security/approval_policy*.rb /ee/app/models/security/scan_result_policy*.rb /ee/app/models/concerns/security/approval_policy_filtering.rb /ee/app/models/**/*merge_request_approval_setting.rb /ee/app/services/merge_request_approval_settings/
EE merge request services and workers, including the approval reset logic in base_service.rb. Their [Merge Requests backend] entries lack a trailing / and match no file. Approval services and workers in the other merge_requests/ directories aren't listed: [Merge Requests backend] already needs a Code Review approval for them. /ee/app/services/ee/merge_requests/ /ee/app/workers/ee/merge_requests/
EE boot files and config: initializers, routes, cron schedules, audit event types, SaaS and Dedicated features. The later /ee/config/metrics/, events/ and feature_flags/ entries keep the bot. /ee/bin/ /ee/config/
Security paths whose required-section entries no longer match them /lib/gitlab/sanitizers/ /lib/banzai/iframe_providers.rb /lib/banzai/iframe_providers/

Comment blocks explain where @gitlab-bot is an owner and why the human-only entries exist. The header line "At least one maintainer who is not the author must approve" is unchanged.

Deliberately left alone (stay human-only):

  • This file and agent configuration. .gitlab/CODEOWNERS and its rake task; /.gitlab/, which holds CI and the review agent's .gitlab/duo/ configuration; the AI harness entries. The generated .ai/principles block and the rake-managed docs block are untouched.
  • /config/ itself. It holds the secret token and encryption initializers, the database.yml templates, database_change_lock.yml, environments and routes. Only /config/metrics/, /config/events/ and /config/feature_flags/ are granted.
  • Tooling and lint. Lint todo lists, /scripts/, /tooling/, /bin/, /keeps/, /rubocop/, /haml_lint/, /storybook/, /qa/, root config files, /lib/gitlab/ci/templates/.
  • File-type globs. *.rb, *.rake, *.erb, *.builder, *.js, *.mjs, *.vue, *.scss, *.graphql and *.haml. Under last-match-wins these are the deciding entries for Ruby and JavaScript in scripts/, tooling/, .gitlab/ and webpack config.
  • Dependencies and vendored code. Gemfile*, package.json, yarn.lock, /vendor/, and /gems/, which decides gem CI files, lockfiles and gemspecs. These belong to !263290 (closed)'s track, and this MR doesn't touch its lines.
  • Other paths:
    • /domains/: code moved there isn't covered by [Authorization] or [Database], which are anchored to /app/ and /lib/.
    • Also /db/**, ClickHouse, /workhorse/, /public/, /sidekiq_cluster/, *_VERSION and the release-bot entries, /.license_encryption_key.pub, and the * and /* fallbacks.
  • Every other section. [Database], [Authorization], [Authentication], [Application Security], [Compliance], [Seat Management], [Verify], [Source Code Backend], [Webhooks] and the rest still need their human owners on the paths they match.

What GitLab Bot can and cannot approve

The grant is broader than the behaviour it enables. CODEOWNERS can't express "Medium, maintainer-written, 10%"; that gate lives in triage-ops.

  • Who can approve. This MR merges after gitlab-org/quality/triage-ops!4551 (merged), which moves this project's approvals onto the MR Risk Labeler's rating. From then, the MR approval flow approves here only through ReconcileApproval, on the rating record for the head commit. The record counts only in an internal note that the flow's account wrote and nobody has edited, in live mode, with the labels it names still on the merge request, and from a session triage-ops started for that merge request on the default branch. gitlab-org/quality/triage-ops!4549 (merged) lists every check. Labels added by hand authorize nothing.
  • Backstops. ReconcileApproval withdraws the approval on every push. It decides again when a label the rating names is removed, when an excluded label or the community contribution label is added, and when the merge request becomes a draft. Triage::VerifyBotApprovals revokes any GitLab Bot approval in gitlab-org that a fresh read of that decision doesn't justify, and posts a warning.
  • What the rater refuses or floors. The MR Risk Labeler rates agents, db and authz paths High at minimum, and sensitive paths once components/agents-and-flows/gitlab-merge-request!137 (merged) merges. It refuses to rate:
    • a Markdown page or licence file whose path names licensing, privacy, compliance, pricing, subscriptions, billing, seats, purchases or a release. Until components/agents-and-flows/gitlab-merge-request!136 (merged) is released it refuses every path that names one, code included. After that such code is rated, and the sensitive floor keeps the SOX seat-count files High;
    • merge requests with 20 or more files or more than four areas;
    • forks and community contributions.
  • The Medium path, gitlab-org/quality/triage-ops!4550 (merged). It ships switched off. It takes merge requests written by a direct Maintainer of this project and rated low or medium, in a 10% sample by IID, once GitLab Duo has approved the rated commit. It takes none where someone requested changes, a human reviewer is requested, a commit is by GitLab Bot or GitLab Duo, or the source is a fork.
    • The approval is pinned to the rated commit and withdrawn on every push.
    • There is no auto-merge; the author merges.
    • Anyone can opt out of a single merge request by requesting a human reviewer, or by adding ~"automation:prevent-risk-flow".

What changes when this merges, before the Medium path is switched on: SecuritySyncApprove already approves security-to-canonical sync merge requests as GitLab Bot. Those approvals will now count on these entries. The changes in them have already been reviewed on the security mirror.

Paths whose only required rule is [Maintainers]. Once the Medium path is on, the risk rating is what keeps these with a human:

  • approval code outside merge request approval rules, such as deployment approvals and member and user approval services;
  • database-adjacent code that [Database] doesn't cover, such as app/workers/database/, app/services/database/, lib/gitlab/pagination/keyset/ and lib/gitlab/database_importers/;
  • app/models/user.rb, app/models/application_setting.rb, app/controllers/application_controller.rb;
  • lib/gitlab/crypto_helper.rb, lib/gitlab/encryption/, the token authenticatable strategies;
  • lib/api/api.rb.

The sensitive-area High floors (SOX, DB, Auth, Infra) are due Nov 14 on #638236. Proposed go/no-go condition for the 10% slice: those floors are live and cover these paths. They are in components/agents-and-flows/gitlab-merge-request!137 (merged), which covers the paths above except two: the member approval services, and app/models/application_setting.rb, which it leaves out because a floor there would rate routine settings work High.

Stale entries in other sections. While checking this, I found entries in other required sections that no longer match the files they were written for:

  • [Merge Requests backend] and [Application Security] contain directory patterns without a trailing /, which match nothing: for example /lib/gitlab/sanitizers, and the ee/.../merge_requests services and workers.
  • Some [Application Security] and [Authentication] entries name files that have moved: the iframe providers, lib/gitlab/utils.rb, gitlab_http.rb and 01_secret_token.rb.

The human-only entries above cover the security paths and the two EE merge request directories among them inside [Maintainers]. The section owners may want to fix the originals.

Policy and compliance

The handbook's Code Review Guidelines let maintainers delegate approval to an independent review agent under stated requirements:

Requirement Where it stands
Maintainer-approved risk criteria instructions/278964/ in components/agents-and-flows/gitlab-merge-request. CODEOWNERS on that repository is in progress (#638236).
Decision and rationale recorded per merge request, for its current commit The MR Risk Labeler's rating note records the rating, the reason and the commit rated. It doesn't yet record the rules version and model; that is in progress (#638502 row 7).
Author and source project trust boundary The Medium path is limited to direct Maintainers and same-project merge requests. Forks and community contributions are excluded.
Review agents cover every affected domain Other required sections are untouched, so domain owners still approve their paths.
New commits invalidate the decision ReconcileApproval withdraws the approval on every push.
SOX, FedRAMP and community changes stay human Required sections, including [Seat Management] for SOX-scoped paths; the rater's refusals and floors; the community exclusion.
A person approves CODEOWNERS changes This MR needs @gitlab-org/development-leaders approval.
Accountable maintainer and post-merge review deadline documented in the project Open; to be documented in a follow-up.

Compliance confirmed the model on Nov 5 (#638502 rows 1, 4 and 8): the bot may approve Medium-risk changes, a human merges, and ratings change only through the rules file. The walkthrough shown to the auditor included GitLab Bot as an approver through CODEOWNERS.

Rollout and rollback

  • Rollout. Merge by Fri Nov 13 (%19.6), after gitlab-org/quality/triage-ops!4551 (merged) is merged and deployed; this MR is blocked on it. The Medium slice turns on no earlier than Mon Nov 16, at 10%, by setting the variable below.
  • Kill switch. The Medium path approves only while the triage-ops CI/CD variable MR_RISK_MAINTAINER_PATH is 1, which triage-ops reads every minute. Setting it to anything else stops the path with no merge request and no deploy. A merge request's next decision then withdraws an approval given on the path; one that sees no further event keeps its approval until someone removes it. approve: false for this project in triage-ops' config/mr_approval_flow.yml stops every approval on a rating, and is a triage-ops MR.
  • Revert. Reverting this MR needs a development-leaders approval again.

How to set up and validate locally

Not reproducible locally: code owner rules are evaluated on GitLab.com against the target branch's CODEOWNERS.

  • Syntax. GitLab's CODEOWNERS check should report the same total for this branch as for master:

    glab api graphql -f query='{ project(fullPath:"gitlab-org/gitlab") { repository { validateCodeownerFile(ref:"jecsanders-codeowners-gitlab-bot-product-code", path:".gitlab/CODEOWNERS") { total validationErrors { code lines } } } } }'
  • Coverage. validate-codeowners-coverage checks that every top-level directory still has its /dir/ entry.

  • After merge. On the next Medium-rated merge request written by a maintainer, approval_state should list gitlab-bot among the eligible approvers on product-code rules, and not on .gitlab/CODEOWNERS or the human-only entries:

    glab api "projects/gitlab-org%2Fgitlab/merge_requests/<iid>/approval_state"

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

No changelog entry: CODEOWNERS is repository tooling and isn't user-facing. No tests or docs change, because CODEOWNERS has no test harness here beyond validate-codeowners-coverage.

🤖 Generated with Claude Code

Edited by Connor Sanders

Merge request reports

Loading
Loading