Namespace level statuses for DB based settings
The SD and CS have project-level database persistent security settings stored under ProjectSecuritySetting, namely Secret Push Protection (SPP) and Container Scanning for Registry (CSfR). For project-level analyzer coverage, we currently use these fields as-is (see issues 1, 2, 3).
However, for Group-level analyzer statuses, we currently don't have this data available. What we need is a counter representing the number of projects within a namespace where SD or CS is enabled. Specifically, SD is considered enabled when SPP is on or when a pipeline has a secret detection job. Similarly, CS is enabled when CSfR is on or when a pipeline includes a container scanning job.
Suggested Solution:
-
Add new
analyzer_typesand separate SPP and CSfR into distinct pills in the security inventory UI:
This would make the data we already have more accurate and allow for a clear separation between pipeline-based data and DB setting-based counters. We would need to introduce types for SPP and CSfR and backfill the data based on the existing security settings. Additionally, we should ensure that this data is maintained and its changes are propagated up to project ancestors on every setting update. -
Add update logic to determine the actual counter:
Since we only need a counter, we can implement logic to check whether a counter update is necessary for a namespace based project settings and pipeline jobs. This logic should be triggered after a pipeline execution and when a setting was changed in the database for SPP and CSfR. For example, the number of SD-enabled projects for a given project ancestor should not decrease as long as SPP is enabled, even if the latest pipeline didn’t contain any SD jobs. This approach will maintain the current types, but the SD and CS types will reflect an aggregated count based on calculations and logic that take into account the DB settings.Key changes:
-
Adjustment service: The
AnalyzerNamespaceStatuses::AdjustmentServiceshould takeproject_settinginto account when calculating SD and CS statuses. -
Post pipeline update service: The
AnalyzersStatus::UpdateServicelogic should consider the existingproject_settingvalues before propagating diffs to project's ancestors. -
Setting SPP and CSfR values:: All the existing places that set these values should trigger
AnalyzerNamespaceStatusrecords creation. This potentially includes creating a new project. -
Project and group events handlers: Existing project and group events handlers should consider project setting when updating and adjusting counters. This might already be taken care of by changing the
AdjustmentService.
-
Adjustment service: The
-
Add new aggregated types (based on solution 2, but with new types):
Instead of using the existingsecret_detectionandcontainer_scanningtypes to hold the aggregated counters for groups (like in solution 2), we can introduce new types for these aggregated counts. This way we can keep a correlation between the project-level counters and the group-level counters of the same existing types, while having to implement the same logic parts suggested in solution 2. This can also potentially enhance the granularity level of our data, allowing for easier separation of setting-based and pipeline-based counters in the future.Key changes:
-
Add new analyzer types: Add new
analyzer_types:secret_push_protection,container_scanning_for_registry,aggregated_secret_detectionandaggregated_container_scanning. Those types should be used forAnalyzerNamespaceStatusesonly, while the two latter will hold the number of projects covered with either pipeline or setting-based security tools. -
Adjustment service: The
AnalyzerNamespaceStatuses::AdjustmentServiceshould maintain those new types while takingproject_settinginto account when calculating. -
Post pipeline update service: The
AnalyzersStatus::UpdateServicelogic should consider the existingproject_settingvalues before propagatingaggregated_container_scanningoraggregated_secret_detectionto project's ancestors. -
Setting SPP and CSfR values: All the existing places that set these values should trigger calculation of
AnalyzerNamespaceStatuswith the new relevant type. The aggregated types might need to be updated based on the existing project-level statuses. This potentially includes having records created when creating a new project. -
Project and group events handlers: Existing project and group events handlers should consider project setting when updating and adjusting counters. This might already be taken care of by changing the
AdjustmentService.
-
Add new analyzer types: Add new
-
Add new analyzer types to project only (based on solution 2 and 3)
This approach builds on suggestion 3. With this solution, we will be storing the new analyzer type records at the project level, in addition to the existing analyzer types (for example, a project will have 3 analyzer status records related to secret detection: general secret detection, secret push protection, pipeline based secret detection). In this example, the general secret detection status will feed into the group level status for secret detection. Storing the setting based records in the analyzer status table means we will be able to avoid a number of calls to theproject_security_settingstable when we need to determine the status for general secret detection for a project and it's group(s).Key changes:
-
Add new analyzer types: Add new
analyzer_types:secret_detection_secret_push_protection,secret_detection_pipeline_based,container_scanning_for_registry, andcontainer_scanning_pipeline_based. Those types should be used forAnalyzerStatusesonly, while the existingsecret_detectionandcontainer_scanningwill hold the number of projects covered with either pipeline or setting-based security tools. -
Adjustment service: No changes to the
AnalyzerNamespaceStatuses::AdjustmentServicewill be required, accept possibly to exclude calculating the new analyzer types. -
Post pipeline update service: The
AnalyzersStatus::UpdateServicelogic should consider the existingproject_settingvalues before propagatingcontainer_scanningorsecret_detectionto project's ancestors. -
Setting SPP and CSfR values: All the existing places that set these values should trigger calculation of
AnalyzerStatuswith the new relevant type. The aggregated types might need to be updated based on the existing project-level statuses. This potentially includes having records created when creating a new project. - Project and group events handlers: Existing project and group events handlers should consider project setting when updating and adjusting counters.
-
Backfill migration Currently, our records for
secret_detectionandcontainer_scanningonly represent the status of pipeline based scans. We will need to backfill records so thatAnalyzerProjectStatuscontains 3 records, as well as re-calculateAnalyzerNamespaceStatusto properly reflect the updated count based on pipeline-based data and DB setting-based counters.
-
Add new analyzer types: Add new