Respect scan profiles when updating analyzer statuses

What does this MR do and why?

Keeps configured analyzer status (success or failed) as long as there is a profile attached to a project. This should prevent changing the SAST and DS statuses from transforming to not_configured when jobs are not part of the latest pipeline but there is an attached project.

Changelog: added
EE: true

How to set up and validate locally

  1. Create a root group root and subgroup g with project p.
  2. Enable SAST scan profile FF:
     ::Feature.enable(:security_scan_profiles_sast)
  3. Attach the default SAST scan profile to project p from security inventory.
  4. Run a pipeline from the pipelines page.
  5. Once the pipeline is finished, verify the project's SAST analyzer status is now :success with a build_id in the UI or using:
    p.analyzer_statuses.sast.first
  6. Apply this patch to disable profile job injection:
    diff --git a/ee/app/services/security/scan_profiles/pipeline_eligibility_service.rb b/ee/app/services/security/scan_profiles/pipeline_eligibility_service.rb
    index 87f5377224ce..d1f8ab3a83f4 100644
    --- a/ee/app/services/security/scan_profiles/pipeline_eligibility_service.rb
    +++ b/ee/app/services/security/scan_profiles/pipeline_eligibility_service.rb
    @@ -37,6 +37,7 @@ def build_applicable_triggers
           end
     
           def scan_profiles_allowed?
    +        false &&
             project.present? &&
               project.licensed_feature_available?(:security_scan_profiles)
           end
  7. Run another pipeline from the pipelines page. This pipeline should not have SAST job.
  8. Once the pipeline is finished, verify the project's SAST analyzer status didn't change to not_configured.

Query plan

Raw SQL
SELECT DISTINCT
    "security_scan_profiles"."scan_type"
FROM
    "security_scan_profiles"
    INNER JOIN "security_scan_profiles_projects" ON "security_scan_profiles_projects"."security_scan_profile_id" = "security_scan_profiles"."id"
WHERE
    "security_scan_profiles_projects"."project_id" = 69782162
LIMIT 4
Plan

See this.

 Limit  (cost=6.49..6.50 rows=1 width=2) (actual time=0.567..0.569 rows=0 loops=1)
   Buffers: shared hit=6 read=2
   ->  Unique  (cost=6.49..6.50 rows=1 width=2) (actual time=0.565..0.566 rows=0 loops=1)
         Buffers: shared hit=6 read=2
         ->  Sort  (cost=6.49..6.49 rows=1 width=2) (actual time=0.565..0.566 rows=0 loops=1)
               Sort Key: security_scan_profiles.scan_type
               Sort Method: quicksort  Memory: 25kB
               Buffers: shared hit=6 read=2
               ->  Nested Loop  (cost=0.43..6.48 rows=1 width=2) (actual time=0.543..0.544 rows=0 loops=1)
                     Buffers: shared hit=3 read=2
                     ->  Index Only Scan using index_security_scan_profiles_projects_on_unique_project_profile on public.security_scan_profiles_projects  (cost=0.28..3.30 rows=1 width=8) (actual time=0.543..0.543 rows=0 loops=1)
                           Index Cond: (security_scan_profiles_projects.project_id = 69782162)
                           Heap Fetches: 0
                           Buffers: shared hit=3 read=2
                     ->  Index Scan using security_scan_profiles_pkey on public.security_scan_profiles  (cost=0.15..3.17 rows=1 width=10) (actual time=0.000..0.000 rows=0 loops=0)
                           Index Cond: (security_scan_profiles.id = security_scan_profiles_projects.security_scan_profile_id)
Settings: effective_cache_size = '338688MB', jit = 'off', random_page_cost = '1.5', work_mem = '100MB', seq_page_cost = '4'

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #591256 (closed)

Edited by Gal Katz

Merge request reports

Loading
Loading