security.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """``hermes security`` subcommand parser."""
  2. from __future__ import annotations
  3. from typing import Callable
  4. from hermes_cli.subcommands._shared import add_json_flag
  5. def build_security_parser(subparsers, *, cmd_security: Callable) -> None:
  6. """Attach the ``security`` subcommand to ``subparsers``."""
  7. security_parser = subparsers.add_parser(
  8. "security", help="Supply-chain audit (OSV.dev) for venv, plugins, and MCP servers",
  9. description="On-demand vulnerability scan against OSV.dev. Covers the Hermes "
  10. "venv (installed PyPI dists), Python deps declared by plugins under "
  11. "~/.hermes/plugins/, and pinned npx/uvx MCP servers in config.yaml. "
  12. "Does NOT scan globally-installed packages or editor/browser extensions.")
  13. security_subparsers = security_parser.add_subparsers(
  14. dest="security_command", metavar="<subcommand>")
  15. audit_parser = security_subparsers.add_parser(
  16. "audit", help="Run a one-shot supply-chain audit",
  17. description="Query OSV.dev for known vulnerabilities in installed components.")
  18. add_json_flag(audit_parser, "Emit machine-readable JSON instead of human-readable text")
  19. audit_parser.add_argument(
  20. "--fail-on", default="critical", choices=["low", "moderate", "high", "critical"],
  21. help="Exit non-zero when any finding meets this severity (default: critical)")
  22. audit_parser.add_argument(
  23. "--skip-venv", action="store_true", help="Skip scanning the Hermes Python venv")
  24. audit_parser.add_argument(
  25. "--skip-plugins", action="store_true", help="Skip scanning plugin requirements files")
  26. audit_parser.add_argument(
  27. "--skip-mcp", action="store_true", help="Skip scanning pinned MCP servers in config.yaml")
  28. audit_parser.set_defaults(func=cmd_security)
  29. security_parser.set_defaults(func=cmd_security)