Loading
feat(duo-workflows): Add Base validator class and program validators
What does this MR do and why?
- Promotes shared validation logic from
GitValidatorinto a declarativeBaseclass using a template method pattern - Refactors
GitValidatorto constants-only (all methods now inherited fromBase) - Adds validators for npm, docker, bundle, make, and curl
- Registers all 6 programs in the
Registryso pattern approvals work in prod for non-git programs - This is the user-facing fix: previously, pattern approvals silently failed for non-git programs because only git was registered
Validator architecture
Subclasses configure behavior by declaring constants:
| Constant | Purpose |
|---|---|
ALLOWED_SUBCOMMANDS |
Set of allowed subcommands (nil = simple tool) |
ALLOWED_GLOBAL_OPTIONS |
Set of allowed pre-subcommand flags |
DANGEROUS_FLAGS |
Dangerous flag exact matches (defense-in-depth) |
DANGEROUS_FLAG_PREFIXES |
Dangerous flag prefixes |
DANGEROUS_COMPOUND_COMMANDS |
Dangerous compound commands like bisect run |
Two modes: Subcommand-based (git, npm, docker, bundle) and Simple (make, curl).
New validators summary
| Program | Mode | Blocked | Key dangerous flags |
|---|---|---|---|
| npm | Subcommand | exec | --prefix, --script-shell, --userconfig |
| docker | Subcommand | -- | --privileged, --cap-add, --network=host |
| bundle | Subcommand | -- | --gemfile, --shebang |
| make | Simple | -- | -f, -C, --directory |
| curl | Simple | -- | -o, -T, -K, --proxy |
References
- Parent epic: Duo should remember command/tool approvals (gitlab-org#20519)
- Resolves: https://gitlab.com/gitlab-org/gitlab/-/work_items/602494+
- Depends on: !240928 (merged) (constrained wildcard matching)
- Pattern approval MR: !233672 (merged)
- Command validators MR: !239862 (merged)
How to set up and validate locally
Run all validator specs:
bin/rspec ee/spec/models/ai/duo_workflows/command_validators/256 examples covering Base class behavior, GitValidator (unchanged), and all 5 new validators.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.
Edited by Dylan Bernardi