Skip to content

Constraint external status checks to protected branches

Max Woolf requested to merge 332587-constraint-status-check-branches into master

What does this MR do?

  • Fixes an error where listing the status checks for a merge request would display all status checks for a project regardless of whether or not a check was appropriate.
    • Status checks only apply to a projects MR if one of the following is true:
      • The check's branch is set to "Any branch"
      • The check's branch is specified and the MR's target branch is that branch.
  • Fixes an error where external status checks would be triggered for all MRs in a project, even if the status check was not appropriate (see above.)

Database Review

New scope - MergeRequests::ExternalStatusCheck.applicable_to_branch(branch_name)

Query

SELECT
        "external_status_checks" . "id" AS t0_r0
        ,"external_status_checks" . "project_id" AS t0_r1
        ,"external_status_checks" . "created_at" AS t0_r2
        ,"external_status_checks" . "updated_at" AS t0_r3
        ,"external_status_checks" . "external_url" AS t0_r4
        ,"external_status_checks" . "name" AS t0_r5
        ,"protected_branches" . "id" AS t1_r0
        ,"protected_branches" . "project_id" AS t1_r1
        ,"protected_branches" . "name" AS t1_r2
        ,"protected_branches" . "created_at" AS t1_r3
        ,"protected_branches" . "updated_at" AS t1_r4
        ,"protected_branches" . "code_owner_approval_required" AS t1_r5
        ,"protected_branches" . "allow_force_push" AS t1_r6
    FROM
        "external_status_checks" LEFT OUTER JOIN "external_status_checks_protected_branches"
            ON "external_status_checks_protected_branches" . "external_status_check_id" = "external_status_checks" . "id" LEFT OUTER JOIN "protected_branches"
            ON "protected_branches" . "id" = "external_status_checks_protected_branches" . "protected_branch_id"
    WHERE
        (
            protected_branches.id IS NULL
            OR protected_branches.name = 'test'
        )

Plan

 Merge Left Join  (cost=0.74..5484.05 rows=1 width=129) (actual time=0.003..0.004 rows=0 loops=1)
   Merge Cond: (external_status_checks.id = external_status_checks_protected_branches.external_status_check_id)
   Filter: ((protected_branches.id IS NULL) OR ((protected_branches.name)::text = 'test'::text))
   Rows Removed by Filter: 0
   Buffers: shared hit=1
   I/O Timings: read=0.000 write=0.000
   ->  Index Scan using external_status_checks_pkey on public.external_status_checks  (cost=0.15..26.40 rows=650 width=96) (actual time=0.002..0.002 rows=0 loops=1)
         Buffers: shared hit=1
         I/O Timings: read=0.000 write=0.000
   ->  Materialize  (cost=0.59..5432.48 rows=1570 width=41) (actual time=0.000..0.000 rows=0 loops=0)
         I/O Timings: read=0.000 write=0.000
         ->  Nested Loop Left Join  (cost=0.59..5428.55 rows=1570 width=41) (actual time=0.000..0.000 rows=0 loops=0)
               I/O Timings: read=0.000 write=0.000
               ->  Index Scan using index_esc_protected_branches_on_external_status_check_id on public.external_status_checks_protected_branches  (cost=0.15..40.20 rows=1570 width=16) (actual time=0.000..0.000 rows=0 loops=0)
                     I/O Timings: read=0.000 write=0.000
               ->  Index Scan using protected_branches_pkey on public.protected_branches  (cost=0.44..3.43 rows=1 width=33) (actual time=0.000..0.000 rows=0 loops=0)
                     Index Cond: (protected_branches.id = external_status_checks_protected_branches.protected_branch_id)
                     I/O Timings: read=0.000 write=0.000

Database Lab

Time: 1.469 ms  
  - planning: 1.357 ms  
  - execution: 0.112 ms  
    - I/O read: 0.000 ms  
    - I/O write: 0.000 ms  
  
Shared buffers:  
  - hits: 1 (~8.00 KiB) from the buffer pool  
  - reads: 0 from the OS file cache, including disk I/O  
  - dirtied: 0  
  - writes: 0  

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #332587 (closed)

Edited by Max Woolf

Merge request reports