Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ All code authored in or evaluated by DevOps CLI must strictly adhere to the foll
5. **Least Privilege Runtime**: Kubernetes pods, Docker containers, and CI jobs run under unprivileged, non-root user contexts (`USER 1000:1000`).
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) and the host paths in `CONST_TOOL_HOST_READ_ONLY_PATHS` (the CA certificates for Semgrep). A directory that the tool writes, the cache of mypy or of Ruff 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.
- `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) 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.
- 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.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-29
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Design

## Decisions

### `go env` names the toolchain and the module cache

The scanner starts `go env -json GOROOT GOMODCACHE` once before each scan, on the host. It starts in the temporary directory, so the `go.mod` of no reviewed tree selects another toolchain, and with `GOTOOLCHAIN=local`, so a `GOTOOLCHAIN` of the host fetches no toolchain. The variables of the host that select the toolchain and the cache (`GOROOT`, `GOPATH`, `GOMODCACHE`, `GOENV`, `XDG_CONFIG_HOME`) reach it, so it names the module cache that `go mod download` fills on this host. The scanner keeps the answer for the scan that follows. The answer depends only on the host, so two scans on two threads write the same value.

### The request of golangci-lint

- `data_dirs` gives `GOROOT` and `GOMODCACHE`. The base binds each one read-only when it exists, and names it to the tool by its variable. A host with no module cache gives no `GOMODCACHE`.
- `cache_dirs` gives `GOCACHE` and `GOLANGCI_LINT_CACHE`, in the directory of the tree in the data cache directory, as the Ruff cache is. No tree writes the cache of another tree (#972).
- `tool_env`, a new hook of the base, gives `GOPROXY=off`, `GOTOOLCHAIN=local`, and a `PATH` that starts with `<GOROOT>/bin` and continues with the `PATH` of the host.

### A module that is not in the module cache is a coverage gap

`coverage_gap`, a new hook of the base, reads the run of the tool before the base reads its output. golangci-lint answers with a reason when the run ended with an exit code that is not zero and its standard error holds `module lookup disabled by GOPROXY=off`. The scan is then a coverage gap with no findings. The reason names the module cache and `go mod download`.

## Rejected alternatives

- **`GOFLAGS=-mod=mod`, as the issue proposed.** The `go` command then ignores a `vendor` directory and writes `go.mod` and `go.sum` when they need a change. The tree in the sandbox is read-only, so the write fails, and a vendored module needs a module cache that it does not need with the default (go.dev/ref/mod, "Build commands").
- **Find the toolchain and the cache from the variables of the host.** `GOMODCACHE`, else the first entry of `GOPATH` with `pkg/mod`, else `$HOME/go/pkg/mod`, misses a value that `go env -w` wrote to the Go configuration file. `go env` reads both.
- **Check the module cache before the run.** That needs a parser of `go.mod` and a copy of the layout of the module cache, or a second tool run (`go mod edit -json`, `go list -m all`) on the untrusted tree. The `go` command already stops with the name of the missing module.
- **Read the error from the reason of the failed scan.** `masked_reason` cuts a reason at 256 characters (`CONST_MAX_ERROR_DETAIL_LENGTH`). golangci-lint puts the error of the `go` command after about 200 characters of its own text, so a module path of normal length pushes the marker out of the reason.
- **One Go build cache for every tree.** A tool that a reviewed tree breaks could write entries that the review of another tree then reads. The Ruff and mypy caches have one directory for each tree for the same reason (#972).
- **The `PATH` of the sandbox policy after the toolchain.** The direct executor starts the tool with the environment of the request, so a `PATH` with only system directories would lose the programs of the host, such as the golangci-lint that `devops install-tools` puts in `~/.local/bin`. In the sandbox, a directory of the host `PATH` that the sandbox does not bind does not exist.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Proposal

## Why

Issue #2129, part of #772: since #2096, a review runs its tools in a sandbox with no network, a read-only tree and a private HOME. golangci-lint was not proven there. It loads the packages of a module through the `go` command, and in the sandbox:

- `go` is not on the `PATH` when the toolchain is outside `/usr/local/bin`, `/usr/bin` and `/bin`, such as in `/usr/local/go/bin`. A toolchain outside `/usr` is not bound at all.
- The module cache of the host is not bound, and the sandbox has no network to fetch a module.
- The Go build cache and the golangci-lint cache fall in the private HOME, a tmpfs of 64 MiB, and are lost after each run.

## What Changes

- Before a golangci-lint scan, the scanner reads `go env -json GOROOT GOMODCACHE` on the host. `go env` starts in the temporary directory with `GOTOOLCHAIN=local` and the Go variables of the host environment.
- The request of golangci-lint:
- names the toolchain in `GOROOT`, binds it read-only, and puts its `bin` first on the `PATH`. The `PATH` of the host follows, so the direct executor finds its programs as before;
- names the module cache in `GOMODCACHE` and binds it read-only, when it exists;
- names a Go build cache in `GOCACHE` and a golangci-lint cache in `GOLANGCI_LINT_CACHE`. Both are directories of the tree, outside the tree, and the request binds them read-write;
- sets `GOPROXY=off` and `GOTOOLCHAIN=local`, so the `go` command fetches no module and no toolchain;
- sets no `GOFLAGS`. The `go` command then uses the `vendor` directory of a module that has one, and otherwise reads `go.mod` and `go.sum` and never writes them (`-mod=readonly`). The issue proposed `GOFLAGS=-mod=mod`, and `## Feasibility` gives the reason that the change does not set it.
- A run that stops because a module is not in the module cache (`module lookup disabled by GOPROXY=off`) is a coverage gap with no findings. Its reason names the module cache and `go mod download`.
- A `go env` that fails gives a failed scan whose reason names `go env`.
- `BaseSecurityScanner` gets two hooks, each empty by default: `tool_env`, the variables that a tool needs besides those of its data and cache directories, and `coverage_gap`, the reason why a run left its targets unscanned for a cause outside the tool.
- The direct executor of `devops scan` gets the same request. So a scan outside a review also fetches no module, and gives the same coverage gap.
- Behavior that a consumer observes changes, so the change carries three ADDED requirements in `review-tool-sandbox`.
- This change fits one pull request.

## Capabilities

### Modified Capabilities

- `review-tool-sandbox`: golangci-lint gets the Go toolchain, the module cache and its caches, and no network. A module whose modules are not in the module cache is a coverage gap.

## Impact

- `src/devops_cli/security/golangci_lint.py`, `src/devops_cli/security/base.py`, `src/devops_cli/config/constants.py`, `src/devops_cli/config/commands.py`.
- `src/devops_cli/security/ruff.py`: the directory of the cache of a tree moves to `tree_cache_dir` in `base.py`, which golangci-lint uses too. The directory does not change.
- `tests/test_golangci_lint_scanner.py`.
- `SECURITY.md`, item 7.

## Feasibility

- golangci-lint 1.64.6, which `tools.lock` pins, is installed on the host of this change. With no `go` on the `PATH`, `golangci-lint run --out-format sarif` in a small module printed `failed to load with go/packages: err: go command required, not found: exec: "go": executable file not found in $PATH`. It also tried `go env -json GOCACHE GOROOT`. So golangci-lint starts the `go` of the `PATH` (measured on 2026-10-29).
- `GOLANGCI_LINT_CACHE=<dir> golangci-lint cache status` printed `Dir: <dir>`. The variable moves the cache of golangci-lint.
- The documentation of the `go` command (`go help environment`, `go help cache` and the module reference at go.dev/ref/mod):
- `GOPROXY=off` disallows downloading modules from any source. A module that is not in the cache gives `module lookup disabled by GOPROXY=off`, the text of `errProxyOff` in `cmd/go/internal/modfetch/proxy.go`.
- `GOTOOLCHAIN=local` runs the bundled toolchain and never downloads another one.
- `GOCACHE` names the build cache and `GOMODCACHE` names the module cache. The `go` command makes the files of the module cache read-only, and it reads a module that is extracted there without a write.
- `-mod=mod` makes the `go` command ignore the `vendor` directory and update `go.mod` and `go.sum` when they need a change. The tree in the sandbox is read-only. So `GOFLAGS=-mod=mod`, as the issue proposed, makes a module with a `vendor` directory need the module cache, and makes a run that must update `go.mod` fail on the write. The default of the `go` command (`-mod=vendor` when the `vendor` directory exists, else `-mod=readonly`) needs neither, so the change sets no `GOFLAGS`.
- The sandbox of #2096 binds a read-only directory that a scanner names in `data_dirs` (`ToolDataDir`) and a writable directory that it names in `cache_dirs` (`ToolCacheDir`). Its `PATH` is `/usr/local/bin:/usr/bin:/bin` (`CONST_HOST_SANDBOX_DEFAULT_ENV`), and it binds only `/usr` of the system. A toolchain in `/usr/local/go` is bound but is not on the `PATH`, so the request puts `<GOROOT>/bin` first. A toolchain or a module cache outside `/usr` passes the bind guard of the sandbox unless it holds the home directory or the tree, or passes through a credential directory.
- Not proven on the host of this change: it has no Go toolchain, so golangci-lint did not run in the sandbox. The tests drive the request and the outcome through `ToolExecutorFake` and the process fake.

## Existing Tool Considered

- `go env` names the toolchain and the module cache, with the Go configuration file and the variables of the host. The change builds no reader of the Go configuration file and no parser of `go.mod`.
- The `go` command itself says which module is missing. The change reads its error and does not check the module cache before the run.
- The hooks `data_dirs` and `cache_dirs` of #2096 bind the directories. The change deletes `_ruff_cache_dir`, which `tree_cache_dir` replaces.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## ADDED Requirements

### Requirement: A golangci-lint scan reads the Go toolchain and the module cache from go env
Before a golangci-lint scan, the scanner SHALL read the toolchain and the module cache of the host with `go env -json GOROOT GOMODCACHE`, started outside the tree with `GOTOOLCHAIN=local`. A `go env` that fails SHALL give a failed scan that starts no golangci-lint.

#### Scenario: The go env of a scan
- **WHEN** golangci-lint scans a Go module
- **THEN** `go env -json GOROOT GOMODCACHE` starts outside the module with `GOTOOLCHAIN=local`

#### Scenario: A host whose go env fails
- **WHEN** `go env` exits with an error before a golangci-lint scan
- **THEN** the scan fails, starts no golangci-lint, and its reason names `go env`

### Requirement: golangci-lint gets the Go toolchain, the module cache and its caches, and no network
The request of golangci-lint SHALL name the toolchain in `GOROOT`, bind it read-only, and put its `bin` first on the `PATH`. It SHALL name the module cache in `GOMODCACHE` and bind it read-only when it exists. It SHALL name a Go build cache in `GOCACHE` and a golangci-lint cache in `GOLANGCI_LINT_CACHE`, both outside the tree, in `writable_dirs`. It SHALL set `GOPROXY=off` and `GOTOOLCHAIN=local`, SHALL set no `GOFLAGS`, and SHALL select no network profile.

#### Scenario: A scan of a Go module
- **WHEN** golangci-lint scans a Go module on a host whose `go env` names a toolchain and a module cache that exist
- **THEN** the request binds the toolchain and the module cache read-only, names them in `GOROOT` and `GOMODCACHE`, and puts the `bin` of the toolchain first on the `PATH`
- **AND** the request names `GOCACHE` and `GOLANGCI_LINT_CACHE`, two directories outside the module, in `writable_dirs`
- **AND** the request sets `GOPROXY=off` and `GOTOOLCHAIN=local`, sets no `GOFLAGS`, and selects no network profile

### Requirement: A Go module whose modules are not in the module cache is a coverage gap
A golangci-lint run that ends with an error because the `go` command finds a module neither in the module cache nor on a proxy (`module lookup disabled by GOPROXY=off`) SHALL give a coverage gap with no findings. Its reason SHALL name the module cache and `go mod download`. Another error that stops the run SHALL still give a failed scan.

#### Scenario: A host with no module cache
- **WHEN** golangci-lint scans a Go module that requires another module, on a host whose module cache does not exist, and the run ends with `module lookup disabled by GOPROXY=off`
- **THEN** the request binds no module cache
- **AND** the scan reports a coverage gap with no findings, and its reason names the module cache and `go mod download`

#### 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
Loading