feat(duo-workflows): Add Base validator class and program validators

What does this MR do and why?

  • Promotes shared validation logic from GitValidator into a declarative Base class using a template method pattern
  • Refactors GitValidator to constants-only (all methods now inherited from Base)
  • Adds validators for npm, docker, bundle, make, and curl
  • Registers all 6 programs in the Registry so 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

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

Merge request reports

Loading
Loading