diff --git a/SECURITY.md b/SECURITY.md index 37c29a10fa..1ddc0f3af2 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -22,7 +22,7 @@ All code authored in or evaluated by DevOps CLI must strictly adhere to the foll 6. **Host Sandbox Confinement**: Executable verification criteria and model-generated shell commands are confined within Linux unprivileged namespaces via `bubblewrap` (`bwrap`), enforcing unshared namespaces, cleared environment, read-only repository and system mounts, zero network egress, and isolated POSIX process groups. The host sandbox's `/tmp` is a private 64 MiB tmpfs mounted nosuid and nodev, which the confined command can write to and execute from, because bubblewrap has no noexec option for a tmpfs. 7. **Review Tool Execution**: A review starts its tools through a `ToolExecutor` (`src/devops_cli/security/tool_executor.py`). The tools are Bandit, Gitleaks, Semgrep, Trivy, kube-linter, Pluto, osv-scanner, golangci-lint, Ruff, mypy and the canary of each. The record of each run names the executor in force. It is the `executor` field in `tool_runs` of `profile.json`, and the Executor column of the Tool Runs table in `review.md`. The record also names the network of the tool in the `network` field: `host` for the direct executor, `none` for the sandbox, and `kube-api` for the sandbox with that network profile. Two executors exist: - `sandbox` is `SandboxToolExecutor`, and it is the default of `devops review path`, `branch` and `pr` and of their MCP tools. It runs the tool in a `bubblewrap` sandbox with no network, a cleared environment, a read-only tree and a private HOME. The sandbox shows the system directories, the tree and only what the request names: the program of the tool (its virtualenv, with the Python installation that the virtualenv links to, behind the guard of `HostSandbox`), its config and ruleset files, the data that a fetch step got before (the Trivy cache and the osv-scanner database, read-only; `devops review fetch-databases` is that step, and a scan that lacks a database, or finds the osv-scanner database older than 24 hours, gives a coverage gap that names it) and the host paths in `CONST_TOOL_HOST_READ_ONLY_PATHS` (the CA certificates for Semgrep). golangci-lint also gets the Go toolchain and the module cache that `go env` names on the host, read-only, with the `bin` of the toolchain first on its `PATH`. Its `go` command fetches no module and no toolchain (`GOPROXY=off`, `GOTOOLCHAIN=local`), so a module whose modules are not in the module cache gives a coverage gap that tells the person to run `go mod download`. A directory that the tool writes, the cache of mypy or of Ruff, or the Go build cache and the golangci-lint cache, for the tree, is bound read-write. The sandbox refuses a bind that holds the home directory or the tree, or passes through a credential directory. Each process of the tool has the CPU limit `CONST_TOOL_CPU_LIMIT_SECONDS` and the address-space limit `CONST_TOOL_MIN_ADDRESS_SPACE_BYTES`. Gitleaks and Semgrep get the larger value that `CONST_TOOL_ADDRESS_SPACE_BYTES` names, and Semgrep runs `CONST_SEMGREP_JOBS` jobs. A Go tool gets `GOMEMLIMIT` set to `CONST_TOOL_GO_MEMORY_LIMIT`. The wall-clock limit applies as well. The sandbox sets no limit on the number of processes, because `RLIMIT_NPROC` counts every process of the user and would starve the host. - - `direct` is `DirectToolExecutor`. It starts the tool as a child process of devops-cli. It has no confinement: the tool has the network, the environment and the files of the user. It has no limit except the wall-clock time of the scan, `DEFAULT_SECURITY_SCANNER_TIMEOUT_SECONDS`. A review never uses it: no option, config key or MCP tool turns the sandbox off (decision 1 of #772). The scans of `devops scan` and of the agent tools are not reviews, and each scanner except Popeye uses this executor there. + - `direct` is `DirectToolExecutor`. It starts the tool as a child process of devops-cli. It has no confinement: the tool has the network, the environment and the files of the user. It has no limit except the wall-clock time of the scan, `DEFAULT_SECURITY_SCANNER_TIMEOUT_SECONDS`. A review uses it only in the pod of a runner Job, where the seccomp profile refuses the user namespace that the sandbox needs and the pod is the isolation boundary (ADR 0031, #3827). There a scanner that the image lacks fails the review (`ReviewScannerMissingError`). Everywhere else no option, config key or MCP tool turns the sandbox off (decision 1 of #772). The scans of `devops scan` and of the agent tools are not reviews, and each scanner except Popeye uses this executor there. - The sandbox has one network profile, `kube-api`, and only Popeye can select it (decision 2 of #772). `devops k8s audit`, the agent tool `scan_popeye` and the scanner registry run Popeye in the sandbox with this profile, from an empty directory. The sandbox keeps no network of its own (`--unshare-all`). Outside the sandbox, `kubectl proxy` listens on a Unix socket in a scratch directory for one context. It reads the kubeconfig and the credentials of the user, and refuses the methods POST, PUT, PATCH and DELETE (`CONST_KUBE_API_REJECTED_METHODS`) and the exec, attach, port-forward and proxy paths (`CONST_KUBE_API_REJECTED_PATHS`). `setpriv --pdeathsig KILL` ends the proxy with the run. In the sandbox, `socat` relays `127.0.0.1:8001` to the socket, and Popeye reads a kubeconfig that names the relay and holds no credentials. The sandbox binds the scratch directory and `/etc/passwd` read-only. So Popeye reaches only the API server of the context, only to read, with the RBAC of the user. The limits: the path filter is a deny list, so a new subresource that reaches past the API server passes until `CONST_KUBE_API_REJECTED_PATHS` lists it, and Popeye reads each response that the user can read, such as a Secret. The direct executor refuses a request that selects the profile. A host without `sh`, `socat`, `kubectl` or `setpriv`, or one that cannot start the sandbox, runs no Popeye scan: the scan reports a coverage gap with the cause, and `devops k8s audit` exits 1. Before its first tool runs, a review checks that the host can start the sandbox: bubblewrap and `prlimit` are installed, and bubblewrap can make a sandbox. On Ubuntu 24.04 and later, AppArmor refuses unprivileged user namespaces to a program that has no profile with the `userns` rule (`kernel.apparmor_restrict_unprivileged_userns`). A host that fails the check fails closed: no tool runs, in the sandbox or outside it, each scan reports a coverage gap with the cause, and the review says the cause and what a person can change on the host one time. The record is read before the tool starts. Under the `direct` executor, a tool that fetches its rules during the run, such as Trivy with an old cache, may use newer rules than the record names, and Ruff also applies a config file above the tree and its user config file, which the record does not name. diff --git a/docs/CLUSTER.md b/docs/CLUSTER.md index af4e7adeba..2c0640ecc2 100644 --- a/docs/CLUSTER.md +++ b/docs/CLUSTER.md @@ -65,7 +65,7 @@ This rollout is an exception to RL1 of the [service patterns](SERVICE_PATTERNS.m The implement job runs tests, `ruff`, `mypy` and OpenSpec, which the Service image does not hold. A step runs `ruff check` on every changed Python file. It runs `mypy` with the options of `devops ci typecheck` on the changed files under `src/`, and no type check on a test file, because the gate checks `src` only (`src/devops_cli/ci/typecheck.py` is the one definition). Its steps run in a runner Job (#2667). `devops roadmap implement --item --confirm`, run on a workstation, makes one by hand for that item and follows its log (`--no-wait` prints the Job's name, `--dry-run` prints the Job). It refuses an item that an agent or a person claimed, an item that is neither Ready nor Planned, and a repository that has a runner Job that has not ended. It makes the Job with the code of `devops k8s run-job --template runner --repo -- roadmap implement --repo --item --confirm`, which is the way to pass `--filter` or `--limit` to the job. Both commands label the Job and its pod `implement-repo=`, the label that the row `implement` lists its Jobs by, and make no Job while a Job with that label has not ended. The label is a digest of the lower-case repository name. The lock is best effort: each command lists the Jobs just before it creates one, so a Job that starts between the two calls is not seen. If the App is not installed on the repository, the Job fails in its pod, and the error in its log names the repository. `--repo` is required with the runner template: it sets `service.github_app.token_repository` on the Job, and the job runs no step unless that setting equals the repository it acts on. The Service makes one for each Staged or Planned item in the row `implement` (Roadmap service, step 16). -- **Image.** Stage `runner` of the `Dockerfile` builds on stage `runner-deps`, which builds FROM the devtools image (`ghcr.io/dan-petty/devtools`, #4361). The `Dockerfile` names that image by tag and digest, the same image as `.devcontainer/Dockerfile`, and Renovate moves both each week in the `devtools` group. The runner uses the OpenSpec of the devtools image. The OpenSpec pin of the project reaches a runner Job through the coder bootstrap (#6517) after #6409. The devtools image gives the tools that the steps, the gate and the hooks need: git, gh, uv, Python, Node, npm, OpenSpec, actionlint, promtool, Trivy, OpenTofu, shellcheck, curl, jq, kubectl, kube-linter, osv-scanner and others. Its README names the source of each tool. `runner-deps` adds the user `devops` (uid 1000) and a venv with the runtime and the dev requirements of `uv.lock` (pytest, ruff, mypy, bandit, deptry, ast-grep, zizmor, pre-commit). The dependencies lie in their own layers (#4550). Stage `lock` exports the requirements from `uv.lock` with `--no-emit-project`, and a release changes only `src/` and the project version, so it keeps those layers. Stage `runner` adds only the project: the `devops_cli` package, its dist-info and `bin/devops`, in one `COPY --link` layer. The devtools image runs `apt-get upgrade` of sid in its own build, and the runner takes a new devtools image each week through Renovate. So the runner runs no `apt-get upgrade` of its own, and its build sets no `no-cache-filters`. The Service and MCP server images stay on `python:3.14-slim-trixie` with the `apt-get upgrade` of their last stage, and they copy gh, kubectl and helm from the devtools image and OpenSpec from the `openspec` stage, which installs the root `package-lock.json`. Each image build reads the registry cache of its target (`service`, `runner` or `mcp-server`), `ghcr.io/dan-petty/devops-cli/:buildcache`, so a build of one image does not replace the cache index of another (#4928). Only the release writes the cache, with `mode=max`, and a pull request reads it with no login, because the packages are public (#4646, #6404). Measured with local builds on 2026-11-20: a change of `src/` builds one new layer of 35 MB in each of the three images. The table `RUNNER_TOOLS` in `src/devops_cli/roadmap/runner_tools.py` lists every program that a Job needs, with the reason it is there and its version command. `NOT_IN_RUNNER` lists each program that a step of a Job does not count on, with the reason (no cluster token, no gate row that runs it). The table holds no tool version: the devtools image gives the version of each tool, and `uv.lock` the version of each dev dependency (#5585). Tests fail when a `devops ci` row, a hook of `.pre-commit-config.yaml`, a required job of `ci.yml` or a live-marked test needs a program that is in neither table. The smoke test of `ci.yml` runs `python -m devops_cli.roadmap.runner_tools` on the loaded image, and the same smoke test of the release runs it on the pushed digest before a tag names it (`release-image.yml`). So an image that lacks a tool, or holds a tool whose version command fails, fails the job. The smoke test also runs `uv run --locked ruff --version` in a copy of the checkout. For OpenSpec it checks only that `openspec --version` exits 0, and it compares the version with no pin. A dev dependency and the project must also print the version of their installed distribution. The smoke test fails when `docker image inspect` reports more than 7000000000 bytes (6.38 GB measured with Podman, 2.42 GB before #4361). The first pull on a node takes the layers of the devtools image, 1.8 GB compressed. The Trivy scan of the Runner Image job (the action `.github/actions/image-scan` with `exit-code: "0"`) sends its findings to code scanning under `trivy-image-runner` and stops no build. [SECURITY.md](../SECURITY.md#dedicated-development-resources-and-sandboxes) records this exception and its compensating controls. The release publishes the image as `ghcr.io/dan-petty/devops-cli/runner`, next to the Service image, and Image Updater keeps it on the digest of `latest` (Service Image Updates). Each Job runs `uv run` in its own worktree, with the uv cache on the home volume. `UV_PYTHON` names the Python of the devtools image, because the `.python-version` of a checkout can name a patch release that the image lacks. +- **Image.** Stage `runner` of the `Dockerfile` builds on stage `runner-deps`, which builds FROM the devtools image (`ghcr.io/dan-petty/devtools`, #4361). The `Dockerfile` names that image by tag and digest, the same image as `.devcontainer/Dockerfile`, and Renovate moves both each week in the `devtools` group. The runner uses the OpenSpec of the devtools image. The OpenSpec pin of the project reaches a runner Job through the coder bootstrap (#6517) after #6409. The devtools image gives the tools that the steps, the gate and the hooks need: git, gh, uv, Python, Node, npm, OpenSpec, actionlint, promtool, Trivy, OpenTofu, shellcheck, curl, jq, kubectl, kube-linter, osv-scanner and others. It also gives the scanners of `devops review`: Gitleaks, Pluto, golangci-lint and Semgrep, with osv-scanner and Trivy (#3827). The review in the pod of a Job runs them with the direct executor, and it exits 1 and lists a scanner that PATH lacks as not installed (ADR 0031). Its README names the source of each tool. `runner-deps` adds the user `devops` (uid 1000) and a venv with the runtime and the dev requirements of `uv.lock` (pytest, ruff, mypy, bandit, deptry, ast-grep, zizmor, pre-commit). The dependencies lie in their own layers (#4550). Stage `lock` exports the requirements from `uv.lock` with `--no-emit-project`, and a release changes only `src/` and the project version, so it keeps those layers. Stage `runner` adds only the project: the `devops_cli` package, its dist-info and `bin/devops`, in one `COPY --link` layer. The devtools image runs `apt-get upgrade` of sid in its own build, and the runner takes a new devtools image each week through Renovate. So the runner runs no `apt-get upgrade` of its own, and its build sets no `no-cache-filters`. The Service and MCP server images stay on `python:3.14-slim-trixie` with the `apt-get upgrade` of their last stage, and they copy gh, kubectl and helm from the devtools image and OpenSpec from the `openspec` stage, which installs the root `package-lock.json`. Each image build reads the registry cache of its target (`service`, `runner` or `mcp-server`), `ghcr.io/dan-petty/devops-cli/:buildcache`, so a build of one image does not replace the cache index of another (#4928). Only the release writes the cache, with `mode=max`, and a pull request reads it with no login, because the packages are public (#4646, #6404). Measured with local builds on 2026-11-20: a change of `src/` builds one new layer of 35 MB in each of the three images. The table `RUNNER_TOOLS` in `src/devops_cli/roadmap/runner_tools.py` lists every program that a Job needs, with the reason it is there and its version command. `NOT_IN_RUNNER` lists each program that a step of a Job does not count on, with the reason (no cluster token, no gate row that runs it). The table holds no tool version: the devtools image gives the version of each tool, and `uv.lock` the version of each dev dependency (#5585). Tests fail when a `devops ci` row, a hook of `.pre-commit-config.yaml`, a required job of `ci.yml` or a live-marked test needs a program that is in neither table. The smoke test of `ci.yml` runs `python -m devops_cli.roadmap.runner_tools` on the loaded image, and the same smoke test of the release runs it on the pushed digest before a tag names it (`release-image.yml`). So an image that lacks a tool, or holds a tool whose version command fails, fails the job. The smoke test also runs `uv run --locked ruff --version` in a copy of the checkout. For OpenSpec it checks only that `openspec --version` exits 0, and it compares the version with no pin. A dev dependency and the project must also print the version of their installed distribution. The smoke test fails when `docker image inspect` reports more than 7000000000 bytes (6.38 GB measured with Podman, 2.42 GB before #4361). The first pull on a node takes the layers of the devtools image, 1.8 GB compressed. The Trivy scan of the Runner Image job (the action `.github/actions/image-scan` with `exit-code: "0"`) sends its findings to code scanning under `trivy-image-runner` and stops no build. [SECURITY.md](../SECURITY.md#dedicated-development-resources-and-sandboxes) records this exception and its compensating controls. The release publishes the image as `ghcr.io/dan-petty/devops-cli/runner`, next to the Service image, and Image Updater keeps it on the digest of `latest` (Service Image Updates). Each Job runs `uv run` in its own worktree, with the uv cache on the home volume. `UV_PYTHON` names the Python of the devtools image, because the `.python-version` of a checkout can name a patch release that the image lacks. - **Template.** Suspended CronJob `devops-cli-runner` has 2 CPU, 4 Gi of memory requested and 8 Gi at most (the default of a manual run; the Service sets the size of its Jobs, see Size), an `emptyDir` home of 8 Gi, an `emptyDir` `/tmp` of 1 Gi, `ephemeral-storage` of 4 Gi requested and 10 Gi at most, `activeDeadlineSeconds: 7200` and `backoffLimit: 0`. It sets `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER=true`, which no other pod sets, and `PYTEST_XDIST_AUTO_NUM_WORKERS=2`, the CPU limit, because `pytest-xdist` counts the CPUs of the node and not of the pod (about 280 MB for each worker). It uses ServiceAccount `devops-cli`, which mounts no token. It takes 2 keys of Secret `devops-cli` through `secretKeyRef`, each in the variable of its name, and no `envFrom`: `DEVOPS_CLI_SERVICE_GITHUB_APP_PRIVATE_KEY` and `DEVOPS_CLI_AI_API_KEY`, the keys of a stage Job (`CONST_ROADMAP_STAGE_JOB_SECRET_KEYS`, #6518). The implement and fix-checks jobs read no other key: the job process acts as the App and calls the gateway, a child process gets no key (`build_subprocess_env`), and the shell of a step gets only the variables of `shell_environment`. It has no MCP token, because `roadmap.implement.mcp` is off; the change that turns the client on adds the key. A Job is made from the template and changes only the args, the name, the labels, the environment values `DEVOPS_CLI_SERVICE_GITHUB_APP_TOKEN_REPOSITORY` and `PYTEST_XDIST_AUTO_NUM_WORKERS`, the deadline and the CPU and memory values of `resources` (see Size and Deadline). - **Role.** ServiceAccount `roadmap-service` is the account of the Service pod. Role `roadmap-service-jobs` in namespace `devops` allows `create`, `delete`, `get`, `list` and `patch` on `jobs`, `get` on CronJobs `devops-cli-runner` and `roadmap-stage`, `get` on Deployment `roadmap-service` (#2917), `list` on `pods` and `get` on `pods/log`, and nothing else. Kubernetes limits `create`, `delete` and `list` to no name, and the name of each Job is new, so those three and `patch` cover the namespace. The `patch` moves the deadline of a Job (see Deadline); the admission policy checks a patch as it checks a create. The policy `roadmap-service-job-deletes` admits the `delete` of a stage Job ([Stage Jobs](#stage-jobs)) and of a fix-checks Job that waits suspended (#6018), and refuses the `delete` of any other Job. A holder of the Role can make any pod that Pod Security `restricted` admits in namespace `devops`, and such a pod can take Secret `devops-cli`. The Service pod holds that Secret already, so the Role gives no new secret. That holds only while namespace `devops` holds no Secret but `devops-cli`, so the admission policy below pins the Jobs of the Service. The Service pod mounts a projected token that expires after one hour; the client reads it again as the kubelet renews it. A Job pod mounts no token. - **Admission policy.** ValidatingAdmissionPolicy `roadmap-service-jobs` and its binding (`k8s/devops/roadmap-service/admissionpolicy.yaml`, #2696) refuse a `CREATE` or an `UPDATE` of a runner Job in namespace `devops` unless the Job has: one container and no init container, with no `command`; the image `ghcr.io/dan-petty/devops-cli/runner`, alone or followed by `:` or `@`; ServiceAccount `devops-cli` with `automountServiceAccountToken: false`; no `envFrom` in a `CREATE`, and only Secret `devops-cli` in `envFrom` in an `UPDATE` (a Job made from the template before #6518 has it, and the Service patches that Job; a Job keeps its pod template, so an `UPDATE` cannot add `envFrom`), and no `valueFrom` in `env` but the 2 keys of the template, each in the variable of its name; only the volumes `tmp`, `home` and `config` of the template; no `hostNetwork`, `hostPID` or `hostIPC`; no `priorityClassName`, `nodeName`, `imagePullSecrets` or `manualSelector`; the pod label `app.kubernetes.io/name: devops-cli-job`, because the NetworkPolicies select pods by that label and a Job pod with the label of the Service would take its egress to the API server, and no pod label `app.kubernetes.io/component: roadmap-stage`; `completions` and `parallelism` of 1 or not set; `backoffLimit: 0` and no `podFailurePolicy`; an `activeDeadlineSeconds` of 14400 at most (`CONST_ROADMAP_IMPLEMENT_DEADLINE_CAP_SECONDS`, the most that the setting `roadmap.implement.deadline_ceiling_seconds` may be; a test holds both); and a CPU request that equals the CPU limit and is 1 with a memory request of 2Gi, or 4 with 6Gi (the table of Size), a memory limit, and a `PYTEST_XDIST_AUTO_NUM_WORKERS` that equals the CPU limit. The policy applies only to the user `system:serviceaccount:devops:roadmap-service`. It never evaluates a Job of another identity, such as the CLI user (`devops k8s run-job`), Argo CD or the CronJob controller. It runs in the API server, so no webhook can be down. `failurePolicy` is `Fail`: if an expression errors, the Job of the Service is refused, the create raises an error, and the next round tries again. Argo CD syncs the policy with the other manifests of the stack, and AppProject `homelab` already admits the two cluster-scoped kinds. A Job whose name starts with `devops-cli-stage-` is a stage Job, which the policy checks with the rules of [Stage Jobs](#stage-jobs) (the variable `stage` of the policy). The gate check `tests/gate/k8s_checks/job_admission_policy.py` (row `k8s` of `devops ci`) runs the expressions against the Jobs that CronJobs `devops-cli-runner` and `roadmap-stage` make, so a change of a template that the policy refuses fails in CI. To check the live policy, make a Job as the Service with `kubectl --as=system:serviceaccount:devops:roadmap-service create --dry-run=server -f `. These are not pinned: the tag or digest of the image, the `args`, the plain `env` values but the worker count, the memory limit, `nodeSelector`, `tolerations`, `hostUsers`, the security context (Pod Security `restricted` checks the pod) and the number of Jobs. A person with an admin role can delete the policy, and Argo CD restores it. diff --git a/docs/ERRORS.md b/docs/ERRORS.md index 96ca9a7a56..b972f755e0 100644 --- a/docs/ERRORS.md +++ b/docs/ERRORS.md @@ -111,6 +111,7 @@ Each exception class declares its `error_code` and `exit_code`. A command that a | `ResponseTooLargeError` | `RESPONSE_TOO_LARGE` | `1` | Security | Raised when the body of a response passes the byte cap of its client. | | `ReviewHandOffRefusedError` | `REVIEW_HAND_OFF_REFUSED` | `1` | Ai | Raised when `devops review intake` refuses a session that is not on merged code. | | `ReviewPoolError` | `REVIEW_POOL_ERROR` | `1` | Ai | Raised when an error occurs during parallel review worker pool execution. | +| `ReviewScannerMissingError` | `REVIEW_SCANNER_MISSING` | `1` | Ai | Raised when a review in the pod of a runner Job needs a scanner that its image lacks. | | `ReviewSessionExistsError` | `REVIEW_SESSION_EXISTS` | `1` | Ai | Raised when a review is published under the name of a session that is already published. | | `ReviewStateError` | `REVIEW_STATE_ERROR` | `1` | Devops_cli.review.state | Exception raised for invalid review finding state or state transition. | | `RoadmapAlternativesError` | `ROADMAP_ALTERNATIVES_FAILED` | `1` | Roadmap | Raised after an alternatives run that tried items and checked none of them. | diff --git a/docs/adr/0031-review-scanners-run-in-the-runner-pod.md b/docs/adr/0031-review-scanners-run-in-the-runner-pod.md new file mode 100644 index 0000000000..34d5911847 --- /dev/null +++ b/docs/adr/0031-review-scanners-run-in-the-runner-pod.md @@ -0,0 +1,37 @@ +--- +status: accepted +date: 2026-11-21 +decision-makers: [owner] +issue: 3827 +body-hash: "5febb00ef1d7fffdd364b6cf6ddda8e330a8349ae4fac8c47d908861c46fe130" +--- + +# Review scanners run in the runner pod + +## Context and Problem Statement + +`devops review` starts each scanner in a `bubblewrap` sandbox (ADR 0005). The sandbox needs a user namespace, and a user namespace needs `unshare`. The `RuntimeDefault` seccomp profile of a runner pod refuses `unshare` (`src/devops_cli/core/process_hardening.py`). So a review cannot run in the shell of a runner Job. + +The runner table `NOT_IN_RUNNER` named Gitleaks, Pluto, golangci-lint and Semgrep, as scanners that no step of a Job counts on. A review in the runner found nothing, and a scanner that is not installed read as no finding. + +## Considered Options + +- **The direct executor in the pod of the runner Job**: `DirectToolExecutor` starts each scanner with no sandbox. The pod is the isolation boundary: it holds no Kubernetes token, the step shell holds none of the job variables, and the job process is not dumpable. Chosen. +- **`bubblewrap` in the pod**: the pod refuses the `unshare` that the sandbox needs. Rejected. +- **A rootless container runtime in the pod**: the Job has no container engine, and `docker` is in `NOT_IN_RUNNER` for that reason. Rejected. +- **A second pod for the scanners**: the Job has no cluster token, so it cannot start a pod. Rejected. + +## Decision Outcome + +Chosen option: "The direct executor in the pod of the runner Job", because the pod is already the isolation boundary and no other option can run in the pod. + +- The review chooses its executor from the setting `roadmap.implement.in_runner`. Only the pod of a runner Job sets it. A workstation and the Service pod keep the sandbox. +- The runner image holds Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep, which its base, the devtools image, installs. The `Dockerfile` of this project pins no scanner. Each one is an entry of `RUNNER_TOOLS` with the source `ToolSource.DEVTOOLS`, and the smoke test of the image runs its version command. +- A review in the runner pod fails closed when an analyzer that its files need is not installed. The report lists that scanner as not installed, and the command exits 1. A workstation review stays advisory. + +## Consequences + +- A review in the runner finds what the five scanners find, and a missing scanner is a broken image and not a clean review. +- The scanners come with a new devtools image, so a scanner version changes there and not in this project. The image scan of the runner stays report-only (`docs/CLUSTER.md`). +- Isolation of a scanner depends on the pod. A change to the pod that gives it a Kubernetes token or the job variables in the step shell must come with a new record. +- ADR 0005 stays as it is. This record is the one exception, and it applies only to the pod of a runner Job. diff --git a/docs/adr/README.md b/docs/adr/README.md index 41a1627dbc..eed2c70174 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -175,5 +175,6 @@ The links to the OpenSpec change, the spec, the settings and the issue. | [0028](0028-a-research-agent-composes-open-tools-and-a-research-index.md) | A research agent composes open tools and a research index | accepted | 2026-11-17 | | | [0029](0029-the-roadmap-service-serves-a-read-only-api.md) | The roadmap Service serves a read-only API | accepted | 2026-11-17 | | | [0030](0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md) | Roadmap steps run their agent apart from the App key | proposed | 2026-11-21 | | +| [0031](0031-review-scanners-run-in-the-runner-pod.md) | Review scanners run in the runner pod | accepted | 2026-11-21 | | diff --git a/openspec/changes/3827-devops-review-runs-in-the-runner/.openspec.yaml b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/.openspec.yaml similarity index 100% rename from openspec/changes/3827-devops-review-runs-in-the-runner/.openspec.yaml rename to openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/.openspec.yaml diff --git a/openspec/changes/3827-devops-review-runs-in-the-runner/design.md b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/design.md similarity index 92% rename from openspec/changes/3827-devops-review-runs-in-the-runner/design.md rename to openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/design.md index a00ef7f6e0..ecb4f2f80f 100644 --- a/openspec/changes/3827-devops-review-runs-in-the-runner/design.md +++ b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/design.md @@ -8,8 +8,8 @@ - **A missing scanner fails the review after the scanners that ran, and not before the review starts.**: The findings of the scanners that ran stay in the report, and the exit code still says that the review is not clean. - **The fail-closed rule applies only to a review in the pod of a runner Job.**: The image is the contract there: a scanner that the image lacks is a broken image. A workstation may lack a scanner, and its review stays advisory. - **The new error class goes in `src/devops_cli/exceptions/ai.py` beside the other review errors, and `docs/ERRORS.md` is regenerated in the same group.**: `docs/ERRORS.md` is the generated catalog of the CLI's error classes, and the docs check refuses a catalog that is not the output of its generator. -- **The change adds Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep, and leaves Kube-linter out.**: #3562 and its split #5394 own Kube-linter, and #3108 already returned actionlint, shellcheck and Trivy; the fourth acceptance criterion forbids adding a tool that either item adds. -- **The executor choice is recorded in `docs/adr/0028-review-scanners-run-in-the-runner-pod.md` rather than as an amendment of ADR 0005.**: The runner exception is specific to the pod, and an amendment of the tool-anchored review ADR would hide it from a reader. +- **The change lists Gitleaks, Pluto, golangci-lint and Semgrep as runner tools, and adds no tool to the image.**: The devtools image installs the scanners, and `RUNNER_TOOLS` already lists `kubectl`, `kube-linter` and osv-scanner (#3562, #5394, #3108), so the table change adds none of the tools that those items add and the `Dockerfile` of this project does not change. +- **The executor choice is recorded in `docs/adr/0031-review-scanners-run-in-the-runner-pod.md` rather than as an amendment of ADR 0005.**: The runner exception is specific to the pod, and an amendment of the tool-anchored review ADR would hide it from a reader. - **The group that writes the new ADR also regenerates the index of `docs/adr/README.md` with `uv run devops docs generate`.**: `src/devops_cli/docs/generator.py:1328:synced = sync_index(` writes that table, and `tests/invariants/test_adr_records.py:25:assert sync_index(page, read_record_texts(ADR_DIRECTORY)) == page` fails on a record whose row the table lacks, so the ADR and its index row land in one step. ## Rejected alternatives diff --git a/openspec/changes/3827-devops-review-runs-in-the-runner/proposal.md b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/proposal.md similarity index 83% rename from openspec/changes/3827-devops-review-runs-in-the-runner/proposal.md rename to openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/proposal.md index 42d1a6b768..52e1926ae1 100644 --- a/openspec/changes/3827-devops-review-runs-in-the-runner/proposal.md +++ b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/proposal.md @@ -9,10 +9,10 @@ The review command cannot run in the runner shell (#3827): its default executor - Add `review_tool_executor` to `src/devops_cli/security/tool_executor.py`: it answers the direct executor in the pod of a runner Job, else the sandbox executor. - Thread `in_runner` through `execute_review_workflow` in `src/devops_cli/ai/review/runner.py`, and pass the setting `roadmap.implement.in_runner` at each of the five calls in `src/devops_cli/commands/review.py`. - Raise `ReviewScannerMissingError` from `src/devops_cli/exceptions/ai.py` when a review in the runner pod finds an analyzer that its files need and the image lacks: the report lists that scanner as not installed and the command exits 1. -- Move Gitleaks 8.30.1, Pluto 5.24.4, osv-scanner 2.6.0, golangci-lint 1.64.8 and Semgrep 1.179.0 from `NOT_IN_RUNNER` to `RUNNER_TOOLS` in `src/devops_cli/roadmap/runner_tools.py`, and install each in the `runner-tools` stage of `Dockerfile`. -- Keep `kubectl` and `kube-linter` out of the image: #3562 and its split #5394 own them, and #3108 already returned actionlint, shellcheck and Trivy. +- Move Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep from `NOT_IN_RUNNER` to `RUNNER_TOOLS` in `src/devops_cli/roadmap/runner_tools.py` as entries of `ToolSource.DEVTOOLS`. The devtools image holds the five (its `mise.toml` pins four, and its `Dockerfile` installs Semgrep), so the `Dockerfile` of this project gets no install line and no version pin. +- Add nothing that #3562, #5394 or #3108 add: `RUNNER_TOOLS` already lists `kubectl`, `kube-linter`, osv-scanner, actionlint, shellcheck and Trivy, so this change lists only the four scanners that it moves out of `NOT_IN_RUNNER`. - Regenerate `docs/ERRORS.md` for the new error class, and name the added scanners and the image scan in `docs/CLUSTER.md`. -- Record the executor choice in `docs/adr/0028-review-scanners-run-in-the-runner-pod.md`, and regenerate the ADR index in `docs/adr/README.md` with `uv run devops docs generate`, so the table holds the row of the new record. +- Record the executor choice in `docs/adr/0031-review-scanners-run-in-the-runner-pod.md`, and regenerate the ADR index in `docs/adr/README.md` with `uv run devops docs generate`, so the table holds the row of the new record. - The change carries a spec delta: the review executor, the fail-closed rule and the runner image tool set are behavior that a consumer observes. - The change fits one pull request. @@ -29,8 +29,8 @@ None. ## Impact -- Code: `src/devops_cli/security/tool_executor.py`, `src/devops_cli/ai/review/runner.py`, `src/devops_cli/commands/review.py`, `src/devops_cli/exceptions/ai.py`, `src/devops_cli/roadmap/runner_tools.py`, `Dockerfile` -- Documents: `docs/ERRORS.md`, `docs/CLUSTER.md`, `docs/adr/0028-review-scanners-run-in-the-runner-pod.md`, `docs/adr/README.md` +- Code: `src/devops_cli/security/tool_executor.py`, `src/devops_cli/ai/review/runner.py`, `src/devops_cli/commands/review.py`, `src/devops_cli/exceptions/ai.py`, `src/devops_cli/roadmap/runner_tools.py` +- Documents: `docs/ERRORS.md`, `docs/CLUSTER.md`, `docs/adr/0031-review-scanners-run-in-the-runner-pod.md`, `docs/adr/README.md` - Tests: `tests/ai/review/test_review_runner_executor.py`, `tests/roadmap/test_roadmap_runner_tools.py` ## Feasibility @@ -43,21 +43,20 @@ None. - `read_file` of `src/devops_cli/ai/review/runner.py` lines 1360-1435 shows `src/devops_cli/ai/review/runner.py:1369:def execute_review_workflow(`, the docstring line `src/devops_cli/ai/review/runner.py:1398:The review runs its tools in the sandbox, and in no other place.` and `src/devops_cli/ai/review/runner.py:1421:executor = SandboxToolExecutor()`, so a review builds one sandbox executor today and the change threads the runner profile into that one call. - `search_code` for `execute_review_workflow(` shows five calls in `src/devops_cli/commands/review.py`, at lines 300, 658, 683, 741 and 764, such as `src/devops_cli/commands/review.py:300:execute_review_workflow(`, so the command passes the setting at five places and the default keeps the sandbox. - `search_code` for `in_runner` shows `docs/CONFIGURATION.md:311:effort=['low', 'medium'] in_runner=False`, `docs/ENV_VARS.md:227:Whether this process is the pod of a runner Job.` and `src/devops_cli/config/settings.py:1459:Whether this process is the pod of a runner Job.`, so the setting exists and only the runner template sets it. -- `read_file` of `src/devops_cli/ai/review/pipeline.py` lines 915-950 shows `src/devops_cli/ai/review/pipeline.py:927:ANALYZER_NOT_INSTALLED = "not installed"` and `src/devops_cli/ai/review/pipeline.py:932:STATIC_ANALYZERS: tuple[tuple[str, str, str], ...] = (` with 8 entries at lines 933-941: Bandit, Kube-linter, Pluto, Trivy, Semgrep, Gitleaks, osv-scanner and golangci-lint. Each member has a decision: Bandit and Trivy stay because `RUNNER_TOOLS` already holds them, Kube-linter stays out because #3562 and #5394 own it, and the other five join the image. +- `read_file` of `src/devops_cli/ai/review/pipeline.py` lines 915-950 shows `src/devops_cli/ai/review/pipeline.py:927:ANALYZER_NOT_INSTALLED = "not installed"` and `src/devops_cli/ai/review/pipeline.py:932:STATIC_ANALYZERS: tuple[tuple[str, str, str], ...] = (` with 8 entries at lines 933-941: Bandit, Kube-linter, Pluto, Trivy, Semgrep, Gitleaks, osv-scanner and golangci-lint. Each member has a decision: Bandit and Trivy stay because `RUNNER_TOOLS` already holds them, Kube-linter and osv-scanner are already runner tools, and the other three are the entries that this change moves into `RUNNER_TOOLS`. - `read_file` of `src/devops_cli/ai/review/pipeline.py` lines 977-990 shows `src/devops_cli/ai/review/pipeline.py:985:if not files_by_kind.get(kind):` and `src/devops_cli/ai/review/pipeline.py:986:states[name] = ANALYZER_NO_FILES`, and `file_symbols` of the same file shows `src/devops_cli/ai/review/pipeline.py:def static_analyzer_states` at line 977 and `src/devops_cli/ai/review/pipeline.py:def classify_scanner_files` at line 1530, so the fail-closed rule reads the review's own analyzer states and a Python diff leaves Kube-linter at `no files`. - `RUNNER_TOOLS` of `src/devops_cli/roadmap/runner_tools.py` lists Pluto, Gitleaks, osv-scanner and golangci-lint as entries of `ToolSource.DEVTOOLS`: the devtools image installs them, and each version is the version of the installed tool (#4363). - Semgrep is also an entry of `ToolSource.DEVTOOLS`, and its version is the version of the installed Semgrep. -- `read_file` of `Dockerfile` lines 70-180 shows `Dockerfile:89:FROM builder AS runner-tools`, `Dockerfile:91:--tool promtool --target-dir /opt/devops-tools/bin` and `Dockerfile:165:RUN DEVOPS_CLI_USER_DATA_ROOT=/opt/devops-tools python -m devops_cli.roadmap.runner_tools`, the install form that the change repeats for each added scanner and the last step that checks every tool of the table. - `read_file` of `docs/CLUSTER.md` lines 55-70 shows `docs/CLUSTER.md:66:no tool that fails the image scan` and `docs/CLUSTER.md:66:trivy image --scanners vuln --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 --ignorefile .trivyignore`, so the scan of the built image is the check of the image criterion. - `read_file` of `src/devops_cli/roadmap/runner_tools.py` shows the constants the plan relies on: the table `RUNNER_TOOLS` and the source `ToolSource.DEVTOOLS`. The runner image builds FROM the devtools image, so the plan adds no install line. -- The verify programs are `uv` (source `IMAGE_PIN`, the pin `UV_VERSION` of 0.13.8), `devops` (source `PROJECT`), `pytest` (source `DEV_GROUP`) and `git` (source `APT`), each an entry of `src/devops_cli/roadmap/runner_tools.py:94:RUNNER_TOOLS: tuple[RunnerTool, ...] = (`; the runner pod sets `seccompProfile: RuntimeDefault`, `readOnlyRootFilesystem: true`, `capabilities.drop: ALL`, `allowPrivilegeEscalation: false` and `runAsNonRoot: true`. +- The verify programs are `devops` (source `PROJECT`), `pytest` (source `CHECKOUT`) and `git` (source `DEVTOOLS`), each an entry of `src/devops_cli/roadmap/runner_tools.py:94:RUNNER_TOOLS: tuple[RunnerTool, ...] = (`; the runner pod sets `seccompProfile: RuntimeDefault`, `readOnlyRootFilesystem: true`, `capabilities.drop: ALL`, `allowPrivilegeEscalation: false` and `runAsNonRoot: true`. - A failing test is failure class `test` with action `repair`; a program that a step may not start is `refused_tool` with action `wait`; a command that runs past its limit is `timeout` with action `retry`. - `docker` is an entry of `src/devops_cli/roadmap/runner_tools.py:202:NOT_IN_RUNNER: dict[str, str] = {` with the reason that no check, hook, test or job of the gate runs it, and `trivy` is an entry of `RUNNER_TOOLS` at `gate:static`; a container build of the image is no runner step, so the image build and its scan are the manual process of group 4. -- `list_files` of `docs/adr` shows the newest record is `docs/adr/0027-dependency-updates-come-from-self-hosted-renovate.md`, so the new record is 0028, and `read_file` of `docs/adr/README.md` lines 18-45 shows the key row `docs/adr/README.md:26:The number of the issue that asked for the decision.` and the approval step `docs/adr/README.md:39:gives the hash of the body when the front matter has none`. +- `list_files` of `docs/adr` shows the newest record on main is `docs/adr/0030-roadmap-steps-run-their-agent-apart-from-the-app-key.md`, so the new record is 0031, and `read_file` of `docs/adr/README.md` lines 18-45 shows the key row `docs/adr/README.md:26:The number of the issue that asked for the decision.` and the approval step `docs/adr/README.md:39:gives the hash of the body when the front matter has none`. - `read_file` of `docs/adr/README.md` lines 140-176 shows the generated index that the new record must join: `docs/adr/README.md:142:writes this table from the front matter of each record, and` and `docs/adr/README.md:174:| [0027](0027-dependency-updates-come-from-self-hosted-renovate.md) | Dependency updates come from self-hosted Renovate | proposed | 2026-11-16 |`, so the test `tests/invariants/test_adr_records.py:25:assert sync_index(page, read_record_texts(ADR_DIRECTORY)) == page` fails on a record whose row the table lacks; the correction of the review finding adds `docs/adr/README.md` to the `changes` of group 4 and regenerates the index there. - `read_file` of `src/devops_cli/docs/generator.py` lines 1318-1333 shows `src/devops_cli/docs/generator.py:1326:index_page = docs / ADR_INDEX_PAGE` and `src/devops_cli/docs/generator.py:1328:synced = sync_index(`, so `uv run devops docs generate` writes the table of `docs/adr/README.md` and no hand edit of it survives the docs check. - `list_files` of `docs` shows `docs/ERRORS.md`, and `list_files` of `tests/docs` shows `tests/docs/test_exceptions.py`, the catalog and the test that holds each error class to its row. -- `read_issue` of #3562 shows it open for `kubectl` and `kube-linter`, with `kube-linter` split to #5394, and `read_issue` of #3108 shows it closed after actionlint 1.17.1, shellcheck and Trivy passed the image scan; the change adds no tool that those items add. +- `read_issue` of #3562 shows it open for `kubectl` and `kube-linter`, with `kube-linter` split to #5394, and `read_issue` of #3108 shows it closed after actionlint 1.17.1, shellcheck and Trivy passed the image scan; `RUNNER_TOOLS` of main already lists `kubectl`, `kube-linter` and osv-scanner from the devtools image, so the change adds none of them. - `execute_review_workflow` and `review_tool_executor` need a checkout of the repository at the staged commit for their tests, and no client and no network: the tests double the process edges and set PATH, so they reach no network, no cluster and no real scanner. - `uv run devops docs generate` needs a checkout of the repository and no network; the image build takes the scanners from the devtools image, so no group installs a tool. - The first checks of the implementation are `uv run devops ci test tests/ai/review/test_review_runner_executor.py`, `uv run devops ci test tests/roadmap/test_roadmap_runner_tools.py`, `uv run devops docs generate` followed by `uv run devops ci test tests/invariants/test_adr_records.py`, and on a workstation with a container engine `docker build --target runner -t runner-review .`, `trivy image --scanners vuln --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 runner-review` and `docker run --rm -e DEVOPS_CLI_USER_DATA_ROOT=/opt/devops-tools --entrypoint python runner-review -m devops_cli.roadmap.runner_tools`. diff --git a/openspec/changes/3827-devops-review-runs-in-the-runner/specs/review-tool-sandbox/spec.md b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/specs/review-tool-sandbox/spec.md similarity index 100% rename from openspec/changes/3827-devops-review-runs-in-the-runner/specs/review-tool-sandbox/spec.md rename to openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/specs/review-tool-sandbox/spec.md diff --git a/openspec/changes/3827-devops-review-runs-in-the-runner/specs/roadmap-implement-runner/spec.md b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/specs/roadmap-implement-runner/spec.md similarity index 62% rename from openspec/changes/3827-devops-review-runs-in-the-runner/specs/roadmap-implement-runner/spec.md rename to openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/specs/roadmap-implement-runner/spec.md index 0b298c527c..6baebc51a1 100644 --- a/openspec/changes/3827-devops-review-runs-in-the-runner/specs/roadmap-implement-runner/spec.md +++ b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/specs/roadmap-implement-runner/spec.md @@ -1,12 +1,12 @@ ## ADDED Requirements ### Requirement: The runner image holds the scanners of a review -The runner image SHALL hold Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep from the devtools image, at the versions of the installed tools. Each of the five SHALL be an entry of `RUNNER_TOOLS` with the source `ToolSource.DEVTOOLS` and SHALL NOT be an entry of `NOT_IN_RUNNER`. `kubectl` and `kube-linter` SHALL stay out of the runner image, because #3562 and #5394 own them. +The runner image SHALL hold Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep from the devtools image, at the versions of the installed tools. Each of the five SHALL be an entry of `RUNNER_TOOLS` with the source `ToolSource.DEVTOOLS` and SHALL NOT be an entry of `NOT_IN_RUNNER`. Each binary of the analyzer table of the review SHALL be an entry of `RUNNER_TOOLS`. #### Scenario: Each added scanner in the table - **WHEN** the runner tool table is read after the change -- **THEN** Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep are entries of `RUNNER_TOOLS` at their lock versions, and none of the five is an entry of `NOT_IN_RUNNER` +- **THEN** Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep are entries of `RUNNER_TOOLS`, and none of the five is an entry of `NOT_IN_RUNNER` -#### Scenario: The cluster tools stay out +#### Scenario: Each analyzer binary in the table - **WHEN** the runner tool table is read after the change -- **THEN** `kubectl` and `kube-linter` are entries of `NOT_IN_RUNNER` +- **THEN** each binary of `STATIC_ANALYZERS` is an entry of `RUNNER_TOOLS` diff --git a/openspec/changes/3827-devops-review-runs-in-the-runner/tasks.md b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/tasks.md similarity index 62% rename from openspec/changes/3827-devops-review-runs-in-the-runner/tasks.md rename to openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/tasks.md index 20fc0c7dad..5c16f9636e 100644 --- a/openspec/changes/3827-devops-review-runs-in-the-runner/tasks.md +++ b/openspec/changes/archive/2026-11-21-3827-devops-review-runs-in-the-runner/tasks.md @@ -15,30 +15,29 @@ Adds: `review_tool_executor` Kind: behavior. Reads: `src/devops_cli/ai/review/runner.py`, `src/devops_cli/ai/review/pipeline.py`, `src/devops_cli/exceptions/ai.py`, `docs/ERRORS.md`, `tests/docs/test_exceptions.py`, `tests/ai/review/test_runner.py`, `tests/ai/agents/test_pydantic_ai_exceptions.py`. Changes: `src/devops_cli/ai/review/runner.py`, `src/devops_cli/exceptions/ai.py`, `docs/ERRORS.md`, `tests/ai/review/test_review_runner_executor.py`. Adds: `ReviewScannerMissingError` -- [ ] 2.1 `test_a_review_in_the_runner_pod_that_lacks_a_scanner_lists_it_as_not_run_and_exits_nonzero` in `tests/ai/review/test_review_runner_executor.py` +- [x] 2.1 `test_a_review_in_the_runner_pod_that_lacks_a_scanner_lists_it_as_not_run_and_exits_nonzero` in `tests/ai/review/test_review_runner_executor.py` - Verification: `$ uv run devops ci test tests/ai/review/test_review_runner_executor.py` fails on the base -- [ ] 2.2 Write the failing case in `tests/ai/review/test_review_runner_executor.py` first: with the runner flag set, a sample diff that holds a Python file and Gitleaks absent from PATH, the review keeps the findings of the scanners that ran, lists Gitleaks as not installed, and raises `ReviewScannerMissingError`. Then add `ReviewScannerMissingError` to `src/devops_cli/exceptions/ai.py` beside the other review errors, with error code `REVIEW_SCANNER_MISSING` and exit status 1. In `src/devops_cli/ai/review/runner.py`, in the runner profile and after the review has printed its report, build the file kinds with `src/devops_cli/ai/review/pipeline.py:def classify_scanner_files`, take the states with `src/devops_cli/ai/review/pipeline.py:def static_analyzer_states`, and raise the error naming each analyzer whose state is `src/devops_cli/ai/review/pipeline.py:927:ANALYZER_NOT_INSTALLED = "not installed"`. Regenerate `docs/ERRORS.md` in the same step, so the catalog holds the row of the new class +- [x] 2.2 Write the failing case in `tests/ai/review/test_review_runner_executor.py` first: with the runner flag set, a sample diff that holds a Python file and Gitleaks absent from PATH, the review keeps the findings of the scanners that ran, lists Gitleaks as not installed, and raises `ReviewScannerMissingError`. Then add `ReviewScannerMissingError` to `src/devops_cli/exceptions/ai.py` beside the other review errors, with error code `REVIEW_SCANNER_MISSING` and exit status 1. In `src/devops_cli/ai/review/runner.py`, in the runner profile and after the review has printed its report, build the file kinds with `src/devops_cli/ai/review/pipeline.py:def classify_scanner_files`, take the states with `src/devops_cli/ai/review/pipeline.py:def static_analyzer_states`, and raise the error naming each analyzer whose state is `src/devops_cli/ai/review/pipeline.py:927:ANALYZER_NOT_INSTALLED = "not installed"`. Regenerate `docs/ERRORS.md` in the same step, so the catalog holds the row of the new class - Verification: `$ uv run devops ci test tests/ai/review/test_review_runner_executor.py` passes -- [ ] 2.3 Regenerate `docs/ERRORS.md` with `uv run devops docs generate`, so it holds the row of `ReviewScannerMissingError` +- [x] 2.3 Regenerate `docs/ERRORS.md` with `uv run devops docs generate`, so it holds the row of `ReviewScannerMissingError` - Verification: `$ uv run devops ci docs` passes ## 3. Hold the review scanners in the runner image -Kind: behavior. Reads: `src/devops_cli/roadmap/runner_tools.py`, `src/devops_cli/ai/review/pipeline.py`, `Dockerfile`, `tests/roadmap/test_roadmap_runner_tools.py`, `docs/CLUSTER.md`, `tests/invariants/test_runner_image.py`, `tests/invariants/test_runner_hooks.py`, `tests/roadmap/stage/test_roadmap_stage_context.py`, `tests/core/test_renovate_config.py`. Changes: `src/devops_cli/roadmap/runner_tools.py`, `Dockerfile`, `tests/roadmap/test_roadmap_runner_tools.py`, `docs/CLUSTER.md`. +Kind: behavior. Reads: `src/devops_cli/roadmap/runner_tools.py`, `src/devops_cli/ai/review/pipeline.py`, `Dockerfile`, `tests/roadmap/test_roadmap_runner_tools.py`, `docs/CLUSTER.md`, `tests/invariants/test_runner_image.py`, `tests/invariants/test_runner_hooks.py`, `tests/roadmap/stage/test_roadmap_stage_context.py`, `tests/core/test_renovate_config.py`. Changes: `src/devops_cli/roadmap/runner_tools.py`, `tests/roadmap/test_roadmap_runner_tools.py`, `docs/CLUSTER.md`. -- [ ] 3.1 `test_the_review_scanners_are_runner_tools_and_the_cluster_tools_stay_out` in `tests/roadmap/test_roadmap_runner_tools.py`, which asserts that Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep are entries of `RUNNER_TOOLS` at their lock versions, that none of the five is an entry of `NOT_IN_RUNNER`, and that `kubectl` and `kube-linter` stay in `NOT_IN_RUNNER` +- [x] 3.1 `test_the_review_scanners_are_runner_tools_from_the_devtools_image` in `tests/roadmap/test_roadmap_runner_tools.py`, which asserts that Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep are entries of `RUNNER_TOOLS`, that none of the five is an entry of `NOT_IN_RUNNER`, and that each binary of `STATIC_ANALYZERS` is an entry of `RUNNER_TOOLS` - Verification: `$ uv run devops ci test tests/roadmap/test_roadmap_runner_tools.py` fails on the base -- [ ] 3.2 Write the failing case in `tests/roadmap/test_roadmap_runner_tools.py` first: the five scanners are entries of `RUNNER_TOOLS` with the source `ToolSource.DEVTOOLS` and are absent from `NOT_IN_RUNNER`, while `kubectl` and `kube-linter` stay in `NOT_IN_RUNNER`; the case also fails when one of the 8 entries of `STATIC_ANALYZERS` of `src/devops_cli/ai/review/pipeline.py` is in neither table. Then move the five names in `src/devops_cli/roadmap/runner_tools.py` from `NOT_IN_RUNNER` to `RUNNER_TOOLS` as entries of `ToolSource.DEVTOOLS`, each with the reason `job` and its `--version` check, which reads the version of the installed tool. The devtools image installs them, so `Dockerfile` gets no install line. The step stops when the devtools image lacks a scanner or a scanner brings a fixed HIGH finding in the image scan, and adds no tool that #3562, #5394 or #3108 already adds +- [x] 3.2 Write the failing case in `tests/roadmap/test_roadmap_runner_tools.py` first: the five scanners are entries of `RUNNER_TOOLS` with the source `ToolSource.DEVTOOLS` and are absent from `NOT_IN_RUNNER`, and the case also fails when one of the 8 entries of `STATIC_ANALYZERS` of `src/devops_cli/ai/review/pipeline.py` is not an entry of `RUNNER_TOOLS`. Then move the names in `src/devops_cli/roadmap/runner_tools.py` from `NOT_IN_RUNNER` to `RUNNER_TOOLS` (osv-scanner is already an entry) as entries of `ToolSource.DEVTOOLS`, each with the reason `job` and its `--version` check, which reads the version of the installed tool. The devtools image installs them, so `Dockerfile` gets no install line. The step stops when the devtools image lacks a scanner or a scanner brings a fixed HIGH finding in the image scan, and adds no tool that #3562, #5394 or #3108 already adds - Verification: `$ uv run devops ci test tests/roadmap/test_roadmap_runner_tools.py` passes -- [ ] 3.3 Edit `docs/CLUSTER.md` to name Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep among the tools of the runner image, and to record that `kubectl` and `kube-linter` stay out through #3562 and #5394 +- [x] 3.3 Edit `docs/CLUSTER.md` to name Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep among the tools of the runner image - Verification: `$ uv run devops ci docs` passes -## 4. Record the executor choice and check the built image +## 4. Record the executor choice -Kind: other. Reads: `docs/adr/0005-review-findings-come-from-tools-not-models.md`, `docs/adr/README.md`, `src/devops_cli/docs/adr_records.py`, `src/devops_cli/core/process_hardening.py`, `docs/CLUSTER.md`, `tests/invariants/test_adr_records.py`. Changes: `docs/adr/0028-review-scanners-run-in-the-runner-pod.md` (new), `docs/adr/README.md`. +Kind: other. Reads: `docs/adr/0005-review-findings-come-from-tools-not-models.md`, `docs/adr/README.md`, `src/devops_cli/docs/adr_records.py`, `src/devops_cli/core/process_hardening.py`, `docs/CLUSTER.md`, `tests/invariants/test_adr_records.py`. Changes: `docs/adr/0031-review-scanners-run-in-the-runner-pod.md` (new), `docs/adr/README.md`. -- [ ] 4.1 Write `docs/adr/0028-review-scanners-run-in-the-runner-pod.md` in the MADR 4 form that `docs/adr/README.md` and `docs/adr/0005-review-findings-come-from-tools-not-models.md` show: a front matter with `status: accepted`, `date`, `decision-makers: [owner]`, `issue: 3827` and `body-hash`; the decision is the direct executor in the pod of a runner Job; the considered options name the refused `unshare` that `src/devops_cli/core/process_hardening.py` records, the rootless container runtime and a second pod; the consequences name the five scanners, the pod as the isolation boundary and the image scan. Then run `uv run devops docs generate`, so the index between the markers of `docs/adr/README.md` holds the row of record 0028, because `tests/invariants/test_adr_records.py` compares that table with the records of `docs/adr/`. Then run the manual check below, which the image-scan requirement of the runner image makes binding, and run this check by hand: Run `uv run devops docs generate`, so the index of `docs/adr/README.md` holds the row of record 0028. Then run `uv run devops ci test tests/invariants/test_adr_records.py` and put the body hash it prints into the front matter of the record. Then, on a workstation with a container engine, run `docker build --target runner -t runner-review .`, then `trivy image --scanners vuln --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 runner-review`, then `docker run --rm -e DEVOPS_CLI_USER_DATA_ROOT=/opt/devops-tools --entrypoint python runner-review -m devops_cli.roadmap.runner_tools`. Expect the index to hold the new row, the ADR test to pass, the build to pass its runner tool check, the scan to exit 0, and the tool check to exit 0. Stop when an added scanner brings a fixed HIGH finding and name that scanner in the pull request. -- [ ] 4.2 Write `docs/adr/0028-review-scanners-run-in-the-runner-pod.md` as an accepted MADR record that names the direct executor, the `unshare` that the pod's RuntimeDefault seccomp profile refuses, and the pod as the isolation boundary, and regenerate the index of `docs/adr/README.md` with `uv run devops docs generate`, so the table holds the row of the new record +- [x] 4.1 Write `docs/adr/0031-review-scanners-run-in-the-runner-pod.md` as an accepted MADR record that names the direct executor, the `unshare` that the pod's RuntimeDefault seccomp profile refuses, and the pod as the isolation boundary, and regenerate the index of `docs/adr/README.md` with `uv run devops docs generate`, so the table holds the row of the new record - Verification: `$ uv run devops ci docs` passes ## Criteria @@ -46,7 +45,7 @@ Kind: other. Reads: `docs/adr/0005-review-findings-come-from-tools-not-models.md - Group 1: A test: in the runner profile, `devops review` runs on a sample diff and returns findings. - Group 2: A test: with a scanner missing, the review reports the tool as not run and does not return a clean result. - Group 4: The image scan and the gate tests pass with the added tools (the reason for `NOT_IN_RUNNER`). -- Group 3: The change cites #3562 and #3108 for the tool set and adds nothing they already add. +- Group 3: The change cites #3562 and #3108 for the tool set and adds nothing they already add. `RUNNER_TOOLS` already lists their tools. ## Workflow follow-up diff --git a/openspec/specs/review-tool-sandbox/spec.md b/openspec/specs/review-tool-sandbox/spec.md index 6696d7a067..b942c21fff 100644 --- a/openspec/specs/review-tool-sandbox/spec.md +++ b/openspec/specs/review-tool-sandbox/spec.md @@ -5,18 +5,21 @@ A review runs the tools that read the reviewed tree in a sandbox with no network ## Requirements -### Requirement: A review runs its tools in the sandbox and in no other place -`devops review path`, `devops review branch` and `devops review pr`, and their MCP tools, SHALL run every analyzer, evidence tool and canary of the review in `SandboxToolExecutor`. An orchestrator, a mypy scan and a canary that get no executor SHALL run their tools in `SandboxToolExecutor`. No option, config key or MCP parameter SHALL turn the sandbox off. The record of each run SHALL name the executor `sandbox`. +### Requirement: A review runs its tools in the sandbox, or directly in the runner pod +`devops review path`, `devops review branch`, `devops review pr` and their MCP tools SHALL run every analyzer, evidence tool and canary in `SandboxToolExecutor`, except in the pod of a runner Job, where they SHALL run in `DirectToolExecutor`. An orchestrator, a mypy scan and a canary that get no executor SHALL use the sandbox. Each run SHALL record its executor, `sandbox` or `direct`. No option, config key or MCP parameter SHALL turn the sandbox off. #### Scenario: A review that gets no executor - **WHEN** an orchestrator that got no executor scans a Python file on a host that can start the sandbox -- **THEN** each command that starts a tool starts bubblewrap with the tool in it -- **AND** the record of each run names the executor `sandbox` +- **THEN** each command that starts a tool starts bubblewrap with the tool in it, and the record of each run names the executor `sandbox` #### Scenario: A dry run - **WHEN** a scan of Bandit, Gitleaks, Semgrep, Trivy, kube-linter, Pluto, osv-scanner, Ruff or mypy runs in a dry run - **THEN** it starts no tool and gives its dry-run outcome +#### Scenario: A review in the runner pod +- **WHEN** `devops review` runs on a sample diff with the setting `roadmap.implement.in_runner` true +- **THEN** each scanner starts as a child of the review with no bubblewrap, the record of each run names the executor `direct`, and the report holds the findings of the scanners + ### Requirement: The sandbox executor checks the host one time and fails closed Before its first run, the sandbox executor SHALL check one time that bubblewrap and `prlimit` are installed and that bubblewrap can start `prlimit -- true` in a sandbox. On a host that fails the check, each run SHALL raise `SandboxUnavailableError` with the cause, and no tool SHALL start, in the sandbox or outside it. @@ -208,3 +211,14 @@ A golangci-lint run that ends with an error because the `go` command finds a mod #### Scenario: A typecheck error - **WHEN** the run of golangci-lint ends with a typecheck error - **THEN** the scan fails, and its reason quotes the error + +### Requirement: A review in the runner pod fails closed when a scanner is missing +`devops review` in the pod of a runner Job SHALL list each review scanner that its files need and that the image does not hold as not installed, SHALL keep the findings of the scanners that ran, and SHALL exit 1. A review in that pod whose needed scanners all ran SHALL exit 0 and SHALL list no scanner as not installed. + +#### Scenario: A scanner absent from the runner image +- **WHEN** `devops review` runs on a sample diff in the pod of a runner Job and Gitleaks is not on PATH +- **THEN** the report lists Gitleaks as not installed, the command exits 1, and the findings of the scanners that ran are still in the report + +#### Scenario: Every scanner in the runner image +- **WHEN** `devops review` runs on a sample diff in the pod of a runner Job with every review scanner on PATH +- **THEN** the command exits 0 and the report lists no review scanner as not installed diff --git a/openspec/specs/roadmap-implement-runner/spec.md b/openspec/specs/roadmap-implement-runner/spec.md index d9af6d97a1..c549878b91 100644 --- a/openspec/specs/roadmap-implement-runner/spec.md +++ b/openspec/specs/roadmap-implement-runner/spec.md @@ -471,3 +471,14 @@ A refused setting at the push of a checkpoint SHALL stop the item with the class #### Scenario: A setting that an exit check writes - **WHEN** an exit check of the step writes `credential.helper` into the configuration of the clone and fails, and no repair round is left - **THEN** the item stops with the class `git_config`, and the comment names `credential.helper` and holds no value + +### Requirement: The runner image holds the scanners of a review +The runner image SHALL hold Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep from the devtools image, at the versions of the installed tools. Each of the five SHALL be an entry of `RUNNER_TOOLS` with the source `ToolSource.DEVTOOLS` and SHALL NOT be an entry of `NOT_IN_RUNNER`. Each binary of the analyzer table of the review SHALL be an entry of `RUNNER_TOOLS`. + +#### Scenario: Each added scanner in the table +- **WHEN** the runner tool table is read after the change +- **THEN** Gitleaks, Pluto, osv-scanner, golangci-lint and Semgrep are entries of `RUNNER_TOOLS`, and none of the five is an entry of `NOT_IN_RUNNER` + +#### Scenario: Each analyzer binary in the table +- **WHEN** the runner tool table is read after the change +- **THEN** each binary of `STATIC_ANALYZERS` is an entry of `RUNNER_TOOLS` diff --git a/src/devops_cli/ai/review/runner.py b/src/devops_cli/ai/review/runner.py index 3f83fb6c2d..e2d32a6e9a 100644 --- a/src/devops_cli/ai/review/runner.py +++ b/src/devops_cli/ai/review/runner.py @@ -1394,6 +1394,25 @@ def _report_sandbox_refusal(executor: SandboxToolExecutor) -> None: ) +def _raise_for_missing_scanners(orchestrator: ReviewPipelineOrchestrator) -> None: + """Fail a review in the pod of a runner Job closed when the image lacks a scanner (#3827). + + The image is the contract in the runner pod: a scanner that the review's own analyzer table + lists as not installed is a broken image, and a review that skipped it cannot read as clean. + The findings of the scanners that ran stay in the report, which is printed before this runs. + """ + from devops_cli.ai.review.pipeline import ANALYZER_NOT_INSTALLED + from devops_cli.exceptions.ai import ReviewScannerMissingError + + missing = [ + name + for name, state in orchestrator.static_analyzers.items() + if state == ANALYZER_NOT_INSTALLED + ] + if missing: + raise ReviewScannerMissingError(missing) + + def execute_review_workflow( pages: list[str], title: str, @@ -1426,9 +1445,10 @@ def execute_review_workflow( `in_runner` says that the review runs in the pod of a runner Job, whose seccomp profile refuses the user namespace that the sandbox needs. There the tools start with the direct - executor, and the pod is the isolation boundary (#3827). Everywhere else the review runs its - tools in the sandbox, and when the host cannot start it, no tool runs and the review says why - when it ends (#2096, decision 1 of #772). + executor, and the pod is the isolation boundary (#3827). A scanner that the image lacks is + listed as not installed and raises `ReviewScannerMissingError`, so the review does not read + as clean. Everywhere else the review runs its tools in the sandbox, and when the host cannot + start it, no tool runs and the review says why when it ends (#2096, decision 1 of #772). """ from devops_cli.lang import MESSAGES @@ -1468,6 +1488,7 @@ def execute_review_workflow( routed_files=routed_files, session_id=session_id, partial_context=partial_context, + in_runner=in_runner, ) finally: if isinstance(executor, SandboxToolExecutor): @@ -1491,6 +1512,7 @@ def _run_review_with_executor( routed_files: Sequence[str], session_id: str | None, partial_context: bool, + in_runner: bool, ) -> list[ReviewResult | str]: """Build the orchestrator of the review with `executor` and run the review of `all_files`.""" from devops_cli.ai.review.history import review_subject @@ -1518,7 +1540,10 @@ def _run_review_with_executor( tool_executor=executor, ) if not all_files: - return _review_routed_files_only(orchestrator, stage_flags) + routed_results = _review_routed_files_only(orchestrator, stage_flags) + if in_runner: + _raise_for_missing_scanners(orchestrator) + return routed_results n_af = len(all_files) with trace_span( @@ -1540,4 +1565,6 @@ def _run_review_with_executor( stage_flags, base_revision, ) + if in_runner: + _raise_for_missing_scanners(orchestrator) return results or [] diff --git a/src/devops_cli/exceptions/ai.py b/src/devops_cli/exceptions/ai.py index b1de1fdc56..c38b416d73 100644 --- a/src/devops_cli/exceptions/ai.py +++ b/src/devops_cli/exceptions/ai.py @@ -166,6 +166,20 @@ def __init__(self, message: str, *, session: str) -> None: super().__init__(message, details={"session": session[:CONST_MAX_ERROR_DETAIL_LENGTH]}) +class ReviewScannerMissingError(DevOpsCLIError): + """Raised when a review in the pod of a runner Job needs a scanner that its image lacks.""" + + error_code = "REVIEW_SCANNER_MISSING" + + def __init__(self, scanners: list[str]) -> None: + names = ", ".join(scanners) + super().__init__( + f"The review is not clean: the runner image lacks {names}, so the files it scans " + "went unscanned. Add each scanner to the devtools image (#3827).", + details={"scanners": list(scanners)}, + ) + + class LibraryIngestionError(DevOpsCLIError): """Base exception for package introspection and library ingestion errors.""" @@ -297,6 +311,7 @@ def __getattr__(name: str) -> Any: "PageTextError", "RagIngestError", "ReviewPoolError", + "ReviewScannerMissingError", "SearchFailed", "SearchQueryRefused", "SkipToolExecution", diff --git a/src/devops_cli/roadmap/runner_tools.py b/src/devops_cli/roadmap/runner_tools.py index da07aa14ec..c67d8a8771 100644 --- a/src/devops_cli/roadmap/runner_tools.py +++ b/src/devops_cli/roadmap/runner_tools.py @@ -158,6 +158,12 @@ def _base(name: str, *needed_by: str) -> RunnerTool: _devtools("npm", "ci:audit"), _devtools("zsh", "test:live"), _devtools("ps", "test:live"), + # The scanners of the review, which the direct executor runs in the pod of the Job (#3827). + # Pluto has no `--version` flag: its `version` command prints the version. + _devtools("gitleaks", "job"), + _devtools("pluto", "job", check=("pluto", "version")), + _devtools("golangci-lint", "job"), + _devtools("semgrep", "job"), _base("nice", "ci:security"), _base( "env", @@ -234,14 +240,8 @@ def hooks_without_programs(search_path: str | None = None) -> tuple[str, ...]: "minikube": _NO_CLUSTER, "docker": "The image holds no Docker engine and no `docker` program. " + _NO_CLUSTER, "popeye": _SCANNER, - "pluto": _SCANNER, "kubeconform": _SCANNER, "tflint": _SCANNER, - "gitleaks": _SCANNER, - "golangci-lint": _SCANNER, - "semgrep": ( - "Only the workflow `rule-pack.yml` installs it, and only when a rule file changes." - ), "ansible-core": ( "No gate row, hook or job starts Ansible. Only `devops infra` starts it, on a workstation." ), diff --git a/tests/ai/review/test_review_runner_executor.py b/tests/ai/review/test_review_runner_executor.py index f3009cd656..3664c11462 100644 --- a/tests/ai/review/test_review_runner_executor.py +++ b/tests/ai/review/test_review_runner_executor.py @@ -15,8 +15,10 @@ import json import os +import shutil from collections.abc import Callable from pathlib import Path +from typing import Any import pytest @@ -24,6 +26,7 @@ from devops_cli.ai.review.runner import ReviewClients, execute_review_workflow from devops_cli.ai.review_schema import ReviewResult from devops_cli.config.constants import CONST_CANARY_WORKDIR_PREFIX +from devops_cli.exceptions.ai import ReviewScannerMissingError from tests.support.fakes.process import ProcessAnswer, ProcessCall, ProcessFake from tests.support.paths import FIXTURES @@ -57,6 +60,19 @@ def bwrap(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: return stand_in +@pytest.fixture +def gitleaks_absent(monkeypatch: pytest.MonkeyPatch) -> None: + """PATH holds no Gitleaks: the runner image lacks the scanner, so the review cannot run it.""" + installed = shutil.which + + def which(command: str, *args: Any, **kwargs: Any) -> str | None: + if Path(command).name == "gitleaks": + return None + return installed(command, *args, **kwargs) + + monkeypatch.setattr(shutil, "which", which) + + @pytest.fixture def review_tree(tmp_path: Path) -> Path: """A tree outside any checkout, with one Python file to review.""" @@ -207,3 +223,27 @@ def test_a_review_outside_the_runner_pod_keeps_the_sandbox( {argv[0] for argv in commands}, {"bandit", "gitleaks", "semgrep"} <= {_confined_program(argv) for argv in commands}, ) == ({str(bwrap)}, True) + + +def test_a_review_in_the_runner_pod_that_lacks_a_scanner_lists_it_as_not_run_and_exits_nonzero( + review_tree: Path, + process_fake: ProcessFake, + gitleaks_absent: None, + capsys: pytest.CaptureFixture[str], +) -> None: + """The runner image is the contract: a scanner that it lacks is listed as not installed, the + findings of the scanners that ran stay in the report, and the review exits nonzero (#3827).""" + _answer_analyzers(process_fake, review_tree) + + with pytest.raises(ReviewScannerMissingError) as raised: + _review(review_tree, in_runner=True) + + printed = " ".join(capsys.readouterr().out.split()) + assert ( + raised.value.error_code, + raised.value.exit_code, + "Gitleaks" in str(raised.value), + "Not installed, so not run: Gitleaks" in printed, + "B602" in printed, + "example.lang.security.first.first" in printed, + ) == ("REVIEW_SCANNER_MISSING", 1, True, True, True, True) diff --git a/tests/roadmap/test_roadmap_runner_tools.py b/tests/roadmap/test_roadmap_runner_tools.py index 66ac78f4ed..fa43743438 100644 --- a/tests/roadmap/test_roadmap_runner_tools.py +++ b/tests/roadmap/test_roadmap_runner_tools.py @@ -588,3 +588,29 @@ def test_a_hook_is_missing_its_program_when_the_program_is_not_on_the_search_pat tuple(HOOK_PROGRAMS), (), ) + + +# ── The review scanners run in the pod of a runner Job (#3827) ────────────────────────────── + +REVIEW_SCANNERS = ("gitleaks", "pluto", "osv-scanner", "golangci-lint", "semgrep") + + +def test_the_review_scanners_are_runner_tools_from_the_devtools_image() -> None: + """The direct executor runs each scanner of the review in the pod, so the runner holds the five + that the devtools image installs, and the runner holds the binary of each analyzer of the + review. No scanner is in `NOT_IN_RUNNER`.""" + from devops_cli.ai.review.pipeline import STATIC_ANALYZERS + + held = {tool.name: tool for tool in RUNNER_TOOLS} + analyzers = {binary for _, binary, _ in STATIC_ANALYZERS} + + assert ( + [name for name in REVIEW_SCANNERS if name not in held], + sorted( + name + for name in REVIEW_SCANNERS + if name in held and held[name].source is not ToolSource.DEVTOOLS + ), + sorted(set(REVIEW_SCANNERS) & set(NOT_IN_RUNNER)), + sorted(analyzers - HELD), + ) == ([], [], [], [])