Gal Katz (4ed20a6f) at 19 Mar 14:01
Merge branch 'vpedak-fix-assigned-feature-categories-metrics' into ...
... and 1 more commit
Fix feature category in the metrics related to Security Scan Profiles
Earlier we identified that scan profiles related components were incorrectly assigned wrong feature category ( #592069 ). This commit assigns the correct feature category to the corresponding metrics.
Fixes: #592069
Discussion: !227536 (comment 3164478674)
We have confirmed with product manager and product analyst.
N/A non functional maintenance change.
N/A non functional maintenance change.
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Fix feature category in the metrics related to Security Scan Profiles
Earlier we identified that scan profiles related components were incorrectly assigned wrong feature category ( #592069 ). This commit assigns the correct feature category to the corresponding metrics.
Fixes: #592069
Discussion: !227536 (comment 3164478674)
We have confirmed with product manager and product analyst.
N/A non functional maintenance change.
N/A non functional maintenance change.
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
LGTM
@mbenayoun Looks much better. I added two small comments, and I agree with @tigerwnz's point about a potential additional N+1, similar to my previous comment in !222292 (comment 3156191644)
Suggestion: This method is doing too much. It's mixing validation, authorization, record lookups, and the actual business logic all in one place.
I usually prefer having basic validation like params[:guidelines].size > MAX_GUIDELINES, Component not found in this project in the mutation level, together with raise_resource_not_available_error! and graphql validation errors.
If you think this service will be reused, we can structure it like:
def execute
validation_error = validate
return validation_error if validation_error
create_security_context
rescue ActiveRecord::RecordInvalid => e
ServiceResponse.error(...)
end
def validate
validate_permission ||
validate_component ||
validate_scan ||
...
end
def validate_permission
return if Ability.allowed?(current_user, :create_ascp_security_context, project)
ServiceResponse.error(message: 'Insufficient permissions', reason: :forbidden)
end
...
Might also apply to create_component_service.rb
def validate_guidelines
params[:guidelines].each_with_index do |guideline, i|
error = guideline_error(guideline, i)
return error if error
end
endDid you consider using BaseService in this MR?
This will allow you to get initialize(project, user = nil, params = {}) and UnauthorizedError = ServiceResponse.error(message: 'You are not authorized to perform this action') for free, and will be consistent with other errors.
Thanks @nrotaru!
Hi @rossfuhrman
LGTM!
The scan profile related components were incorrectly categorised under the security_asset_inventories feature category, wheres they should be under the security_testing_configuration.
Fix the assigned feature category for scan profile backend components
security_asset_inventories to security_testing_configuration to properly reflect their functionality and purposebundle exec rake gitlab:custom_roles:compile_docs
Fixes: #592069
N/A. It is a maintenance backend change.
N/A. It is a maintenance backend change.
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Adds the security_scan_profile_project_statuses table and Security::ScanProfileProjectStatus model to persist profile-specific scan status per project per scan type.
The existing analyzer_project_statuses table tracks inventory-level status across all enablement methods and must not be modified. This new table stores profile-scoped status separately, enabling scanner health indicators for security profiles.
Closes #593131
security_scan_profile_project_statuses on the gitlab_sec database with:
[project_id, scan_type] (upsert target for future status update service)security_scan_profile_id (FK lookup)build_id (required for loose FK cleanup)security_scan_profiles with cascade delete (same database)project_id (async_delete) and build_id (async_nullify) for cross-database references, matching the pattern used by analyzer_project_statuses
SecApplicationRecord and provides three computed helpers:
stale? — true when status is not not_configured, last_scan_at is present, and older than 90 daysactive? — true when success? and not staleprofile_failed? — true when failed? and consecutive_failure_count >= 3
Security::ScanProfile — has_many :security_scan_profile_project_statuses
EE::Project — has_many :security_scan_profile_project_statuses
security_scan_profile_project_statuses in all_models.yml (not exported, status is runtime data)| Column | Target DB | Strategy |
|---|---|---|
project_id |
gitlab_main |
Loose FK with async_delete
|
build_id |
gitlab_ci |
Loose FK with async_nullify (via CiPipelinesBuildsCleanupCronWorker) |
security_scan_profile_id |
gitlab_sec |
Direct FK with on_delete: :cascade
|
create_table, no data migration, no locks on existing tables)spec/lib/gitlab/database/loose_foreign_keys_spec.rb passes)build_id, project_id, security_scan_profile_id)all_models.yml for Import/Export awarenessanalyzer_project_statuses or inventory behaviorChangelog: added
EE: true
Thanks @nrotaru! Looks better. I added two small comments
Looks much better!
it 'sets security_scan_profiles source for non-policy jobs' do
pipeline = execute.payload
sources = pipeline.builds.map do |build|
Ci::BuildSource.find_by!(build_id: build.id, project_id: project.id).source
end
non_policy_sources = sources - %w[pipeline_execution_policy scan_execution_policy]
expect(non_policy_sources).to be_present
expect(non_policy_sources).to all(eq('security_scan_profiles'))
endSuggestion: Can be removed as this feature is already enabled by default.
Suggestion: What do you think about moving the service initialization into the context? I believe it will be cleaner and make things easier to extend in the future
Question: Why do we need attr_accessor :scan_profile_eligibility_service? scan_profile_context holds the eligibility service now
Thanks for the input @rossfuhrman! Sounds good.