Expose prevented package stats on dependencyFirewallActivitySummary

What does this MR do and why?

This is Part 5, the last backend MR of the Dependency Firewall dashboard stats series, work item https://gitlab.com/gitlab-org/gitlab/-/work_items/627538. It exposes the prevented-package counts in GraphQL for the dashboard cards.

The frontend that consumes these fields is !255295 (merged).

It adds six fields on DependencyFirewallActivitySummary (the dependencyFirewallActivitySummary field on Group and Project), marked experiment, milestone 19.5: vulnerabilitiesPrevented, vulnerabilitiesPreventedBySeverity (a list of the new DependencyFirewallSeverityCount type: severity and count), maliciousPackagesPrevented, maliciousPackagesWarnedOnly, licenseRisksPrevented, licenseRisksWarnedOnly.

Counts are distinct packages over the same from window as the existing event counts; the ledger window always ends at now. The severity breakdown counts each package once at its highest severity, so it sums to vulnerabilitiesPrevented.

DependencyFirewallRuleActivityFinder#activity_summary reads them through Security::DependencyFirewall::PreventedStats::DataCollector (from the read-path MR). DependencyFirewallSeverityCount authorizes through its parent (authorize_granular_token skip_reason: :parent_authorizes).

This regenerates doc/api/graphql/reference/_index.md and public/-/graphql/introspection_result.json.

When the fields are null

Situation Prevented fields Other summary fields
Project, dependency_firewall_dashboard_v2 on, packages prevented the counts unchanged
Project, flag on, nothing prevented 0 (breakdown []) unchanged
Group null unchanged
Flag off null unchanged
Dependency firewall unavailable null zeros, as today

null means the data is not available, so 0 always means available and nothing prevented. Group reads are planned to come from the ClickHouse Siphon replica later; when they land, groups get numbers instead of null without an API change. Rollout of that work: #631122. Group summaries keep returning their existing counts.

No schema changes and no new queries. The reads are the read-path MR's project queries (about 0.2 to 0.3 ms each on Database Lab), reviewed in !253946 (merged). Groups run no ledger queries. Project.dependencyFirewallActivitySummary can be resolved for only one project per request, so a query across many projects can't multiply these reads.

How to set up and validate locally

  1. Prerequisites: you need an Ultimate license and the dependency firewall setting turned on for the group. In bin/rails console, enable both flags on the top-level group. The flags are checked against the project's top-level group (root ancestor), so enabling them on the project alone has no effect:

    group = Group.find_by_full_path('<top-level group path>')
    Feature.enable(:dependency_firewall_phase1, group)
    Feature.enable(:dependency_firewall_dashboard_v2, group)
  2. In the same console, create a ledger row for a project, or trigger enforcement instead:

    project = Project.find_by_full_path('<project path>')
    Security::DependencyFirewallPreventedPackage.create!(project: project, rule_type: :license,
      identifier: 'pkg:npm/left-pad@1.3.0', first_seen_at: 1.day.ago, last_blocked_at: 1.day.ago)

    Each (project, rule_type, identifier) can exist once, so use a new identifier to add more rows.

  3. In GraphiQL (/-/graphql-explorer), run this query, which requests every summary field:

    query DependencyFirewallSummary($fullPath: ID!, $from: Date, $to: Date) {
      project(fullPath: $fullPath) {
        dependencyFirewallActivitySummary(from: $from, to: $to) {
          # Event and rule counts (projects and groups)
          blocked
          warned
          allowed
          totalTriggers
          activeRules
          blockingRules
          warningRules
    
          # Prevented packages (experiment, null for groups for now)
          vulnerabilitiesPrevented
          vulnerabilitiesPreventedBySeverity {
            severity
            count
          }
          maliciousPackagesPrevented
          maliciousPackagesWarnedOnly
          licenseRisksPrevented
          licenseRisksWarnedOnly
        }
      }
    }

    with variables:

    { "fullPath": "<project path>" }

    Expected with only the row from step 2: licenseRisksPrevented is 1, the other prevented counts are 0, and vulnerabilitiesPreventedBySeverity is [].

    Without arguments, the window is the last 7 days. from applies to both kinds of field, so a ledger row older than from is not counted. For example, "from": "2026-09-01". to applies only to the event counts. The prevented counts always run up to now.

  4. blocked, warned, allowed, and totalTriggers count enforcement events from dependency_firewall_activity_stats, an existing table. The prevented fields count distinct packages from the new ledger. This is why they can differ: three blocks of the same package give blocked: 3 and licenseRisksPrevented: 1. The row created in step 2 alone does not change blocked.

  5. For a group, replace project(fullPath: $fullPath) with group(fullPath: $fullPath) and pass the group path. The seven event and rule fields return values, as they did before this MR. The six prevented fields return null, because group reads are not available yet.

  6. Disable dependency_firewall_dashboard_v2 on the group (Feature.disable(:dependency_firewall_dashboard_v2, group)) and repeat the project query. The six prevented fields now return null, and the other fields are unchanged.

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.

References

Edited by Arpit Gogia

Merge request reports

Loading
Loading