Loading
Record dependency firewall policy bypasses as audit events
What does this MR do and why?
A request that bypassed an enforced dependency firewall policy wrote no audit event when another linked policy warned about or blocked the package. EnforcementService#enforce_policy audits one outcome per request, and a warn or block result wins over a bypass result, so the bypass was dropped. A Beta customer hit this with a warn baseline policy and an enforced subgroup policy.
- Each bypassed policy now writes its own audit event, whatever the request's outcome:
dependency_firewall_access_token_bypassordependency_firewall_user_bypass. - The events follow the merge request approval policy bypass pattern: they reuse
Security::ScanResultPolicies::PolicyBypassAuditorwith a newBypassContexts::DependencyFirewallContext. Scope is the security policy project, target is the policy, and details include the project ID, policy, bypass type, token or user IDs, PURL, operation, and session ID. AuditBypassesServicemaps each bypass reason to an auditor call. Supporting another bypass kind needs onewhenbranch and one event type YAML.PolicyEvaluatorresults now carry theSecurity::Policyrecord.BypassSettings#bypassing_access_token_idsreturns the IDs that matched.- Existing
dependency_firewall_allowed,_warned, and_blockedevents, activity stats, and the response are unchanged. A pure bypass-allowed request now writes both the existingallowedevent in the project and the new bypass event in the security policy project. - A failure while writing a bypass event is tracked and does not block the package, same as
CreateAuditEventsService.
Resolves https://gitlab.com/gitlab-org/gitlab/-/work_items/639638
How to set up and validate locally
- Link two dependency firewall policies to a project: a
warnpolicy and anenforcedpolicy, both matching the same package. Put a project access token in the enforced policy'sbypass_settings.access_tokens. - Request the package with that token.
- In the security policy project, select Secure > Audit events. A
dependency_firewall_access_token_bypassevent names the enforced policy and the package.
Tests
ee/spec/services/security/dependency_firewall/enforcement_service_spec.rb: new end-to-end example with real policies (warn baseline plus enforced policy bypassed by a token). It failed onmaster(received: 0 times) and passes with the fix.ee/spec/services/security/dependency_firewall/audit_bypasses_service_spec.rb: token and user bypass, several bypasses mixed with other outcomes, no bypass, one failing audit not skipping the rest, and an unstubbed auditor persisting the event in the security policy project.ee/spec/lib/security/scan_result_policies/bypass_contexts/dependency_firewall_context_spec.rb,bypass_settings_spec.rb,policy_evaluator_spec.rb.- Mutation checks: removing the
audit_bypassescall or therescuefails a spec.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.
Edited by Hannah Baker
