Prevent edits to MRAP approval rules
Summary
It should not be possible to bypass merge request rules originating from Merge request approval policies. But by default, edits to approval rules are not prevented, and this includes edits to MRAP approval rules.
Although we hide MRAP approval rules in the user interface, we do not prevent edits.
Steps to reproduce
- Create a new group
- Navigate to
Security > Policiesand create the following Merge request approval policy:
approval_policy:
- name: Policy Rule
enabled: true
rules:
- type: any_merge_request
branch_type: protected
commits: any
actions:
- type: require_approval
approvals_required: 1
role_approvers: [owner]
- type: send_bot_message
enabled: true
approval_settings:
block_branch_modification: true
block_group_branch_modification: true
prevent_pushing_and_force_pushing: true
prevent_approval_by_author: true
prevent_approval_by_commit_author: true
remove_approvals_with_new_commit: true
require_password_to_approve: false
- Create a new contained project
- Navigate to
Manage > Membersand add a new Developer - Impersonate the Developer
- Open a merge request targeting
mainand verify it requires approval - Identify the approval rule ID through the GraphQL API:
query {
project(fullPath: "fast-sun-1328/fast-flower-2021") {
mergeRequest(iid: "1") {
approvalState {
rules {
name
id
}
}
}
}
}
- On the merge request page, click
Edit - At this point it's easiest to open your browser's web inspector and substitute the ID of the default
Any eligible userrule in the markup with the ID of the policy approval rule:
- Click
Save changesand verify no approval is required
Example Project
n/a
What is the current bug behavior?
PUT/PATCH /$FULL_PATH/-/merge_requests/$IID accepts edits to MRAP approval rules with default approval settings.
What is the expected correct behavior?
PUT/PATCH /$FULL_PATH/-/merge_requests/$IID rejects edits to MRAP approval rules with default approval settings.
Relevant logs and/or screenshots
n/a
Output of checks
n/a
Results of GitLab environment info
n/a
Possible fixes
Either reject edits to MRAP approval rules regardless of approval settings, or provide an approval_settings.prevent_editing_approval_rules property to override the behaviour.
Patch release information for backports
n/a
High-severity bug remediation
n/a
Edited by Dominic Bauer