Enforce the 64 KiB limit on Duo context exclusion rules

What does this MR do and why?

!265774 (merged) capped a project's Duo context exclusion rules at 64 KiB, behind the duo_context_exclusion_settings_size_limit flag, which is off. This MR removes the flag, so the limit applies everywhere. The rules are only validated when they change, so a project that already stores more can still save its other settings. The docs now mention the limit.

Why no rollout first

Production today (Database Lab, project_settings on main, 2026-10-28):

Projects with at least one rule 290
Largest stored rules 21 KiB
Most rules in one project 863 (p99: 95)
Longest single rule 252 characters
Projects over 64 KiB 0

So 64 KiB is three times the largest real value, and no project on GitLab.com is affected.

  • Existing rule sets are only checked when they're edited, so a rollback is a revert. On self-managed, an instance with more than 64 KiB of rules keeps them, but has to shorten them to save a change to them.
  • The validation itself, including the spec that a stored oversized value doesn't block other saves, was reviewed in !265774 (merged).

References

Closes https://gitlab.com/gitlab-org/gitlab/-/work_items/636070

Screenshots or screen recordings

No UI change. Saving rules over 64 KiB now returns this error:

Before After
Saved Duo context exclusion settings is too large. Maximum size allowed is 64 KiB

How to set up and validate locally

Steps and what I got

Run against GDK with Duo enabled, as root (a maintainer of flightjs/Flight).

  1. Create a personal access token with the api scope and set up these helpers:

    export GDK=http://gdk.test:3000 TOKEN=<token>
    
    gql() {
      ruby -rjson -e 'puts({ query: "mutation($i: ProjectSettingsUpdateInput!) { projectSettingsUpdate(input: $i) { errors } }", variables: { i: JSON.parse(ARGV[0]) } }.to_json)' "$1" |
        curl -s "$GDK/api/graphql" -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' --data-binary @-
      echo
    }
    rule() { ruby -rjson -e 'puts({ fullPath: "flightjs/Flight", duoContextExclusionSettings: { exclusionRules: ["a" * ARGV[0].to_i] } }.to_json)' "$1"; }
    stored() {
      ruby -rjson -e 'puts({ query: "{ project(fullPath: \"flightjs/Flight\") { duoContextExclusionSettings { exclusionRules } } }" }.to_json)' |
        curl -s "$GDK/api/graphql" -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' --data-binary @- |
        ruby -rjson -e 'r = JSON.parse($stdin.read).dig("data", "project", "duoContextExclusionSettings", "exclusionRules") || []; puts "stored: #{r.size} rule(s), #{r.sum(&:size)} characters"'
    }
  2. Save one 80,000-character rule. On master this saves. On this branch it is rejected and nothing is stored:

    gql "$(rule 80000)"
    stored

    What I got:

    {"data":{"projectSettingsUpdate":{"errors":["Duo context exclusion settings is too large. Maximum size allowed is 64 KiB"]}}}
    stored: 0 rule(s), 0 characters
  3. Store a 70,000-character rule directly, as a project that saved it before this change would have:

    Project.find_by_full_path('flightjs/Flight').project_setting.update_column(:duo_context_exclusion_settings, { exclusion_rules: ['a' * 70_000] })
  4. Change a different setting. It still saves:

    gql '{"fullPath": "flightjs/Flight", "duoFeaturesEnabled": false}'

    What I got:

    {"data":{"projectSettingsUpdate":{"errors":[]}}}
  5. Shrink the rules. That saves too:

    gql "$(rule 100)"
    stored

    What I got:

    {"data":{"projectSettingsUpdate":{"errors":[]}}}
    stored: 1 rule(s), 100 characters
  6. Clean up:

    project = Project.find_by_full_path('flightjs/Flight')
    project.project_setting.update!(duo_context_exclusion_settings: {}, duo_features_enabled: true)

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.

Merge request reports

Loading
Loading