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
50 changes: 50 additions & 0 deletions .github/workflows/trivy-config-alerts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# File one issue for each open Trivy-config code scanning alert group that has none (#4401).
# The Security Scan step of the CI workflow uploads the results of `trivy config`, and no job
# turned an alert into work. SECURITY.md ("Judging a Trivy-config Alert") names who judges the
# issue and in what time. The job is no step of CI: a step of a pull request run must not write
# issues. It has no `workflow_run` trigger either: zizmor reports that trigger as a HIGH finding
# (dangerous-triggers), which would add one more alert that nobody judged. The CI run on `main`
# uploads the alerts, and this job files their issues on the next day.
name: Trivy Config Alerts

on:
schedule:
# Once a day at 06:00 UTC.
- cron: "0 6 * * *"
workflow_dispatch:

permissions:
contents: read
security-events: read
issues: write

concurrency:
group: trivy-config-alerts
cancel-in-progress: false

env:
# uv runs only its own CPython builds, never the runner image's Python (#1494).
UV_MANAGED_PYTHON: "1"

jobs:
file-alert-issues:
name: File Alert Issues
runs-on: ubuntu-26.04
# The filer reads two listings and posts at most 5 issues. The step limit is shorter.
timeout-minutes: 10

steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false

- name: Set up uv toolchain
uses: ./.github/actions/setup-toolchain

- name: File the issues
timeout-minutes: 5
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
run: uv run devops scan alerts --repo "$REPOSITORY"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ and excessive permissions fail it, and every other finding is shown. |
| | `devops scan injection [OPTIONS] <target>` | Scan target files for prompt-injection smuggling vectors and canary tokens. |
| | `devops scan report [OPTIONS] <target>` | Run every registered scanner and report deduplicated, correlated findings. |
| | `devops scan sarif [OPTIONS] <document>` | Ingest a SARIF document from any tool and report it in the unified taxonomy. |
| | `devops scan alerts [OPTIONS]` | File one issue for each open Trivy-config code scanning alert group that has none. |
| [**ai**](docs/commands/ai.md) | `devops ai config [OPTIONS]` | Show or update AI provider configuration. |
| | `devops ai models [OPTIONS]` | List available models for the configured provider. |
| | `devops ai preload [OPTIONS]` | Preload configured model into VRAM across all configured Ollama servers. |
Expand Down
11 changes: 11 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ A scanner can name a finding that no update of the pinned package solves yet. Th

**Report.** The pull request comment lists each ignore that the agent added, its expiry and its tracking issue. The final message of the agent says the same.

## Judging a Trivy-config Alert

The `Security Scan` step of CI uploads the results of `trivy config` to code scanning. Each result is an alert of the tool `Trivy-config`. The workflow `.github/workflows/trivy-config-alerts.yml` runs `devops scan alerts` each day, after the CI run on `main` that uploaded the alerts. The command files one issue for each rule and file that has open alerts and no open issue: at most 5 in one run, the worst severity first. The title is `fix(security): judge Trivy-config <rule-id> in <path>`.

**Who judges, and in what time.** The owner judges a CRITICAL alert within 24 hours. An agent judges an alert of severity HIGH, MEDIUM or LOW within 14 days. After 14 days the owner decides.

**What judging means.** Do one of these, and close the issue with it:
1. Fix the file in a pull request that closes the issue. This is the first choice.
2. If the fix breaks the workload or needs a change that is not released yet, add an entry to `.trivyignore.yaml`. Give it the rule `id`, the `paths` of the file, a `statement` that holds the reason and the tracking issue, and an `expired_at` date. `devops scan report` names this file, and Trivy stops applying an entry after its date. An agent follows the limits of "A Finding with No Fix": 3 days, renewed at most up to 14 days in all, never for a CRITICAL alert, never for a secret. A longer date is the decision of the owner, and the `statement` names that decision.
3. A person dismisses the alert in code scanning, with a reason. An agent does not dismiss an alert.

## Reporting a Vulnerability

We deeply appreciate responsible security disclosures. If you discover a security vulnerability within DevOps CLI:
Expand Down
16 changes: 16 additions & 0 deletions docs/CLI_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3721,6 +3721,22 @@ devops scan sarif [OPTIONS] <document>
| `--format`, `-f` | `string` | `table` | Output format type (table, json, yaml, markdown). |
| `--json` | `boolean` | - | Output findings or metrics as JSON. |

### `devops scan alerts`

**File one issue for each open Trivy-config code scanning alert group that has none.**

```bash
devops scan alerts [OPTIONS]
```

**Options:**

| Option / Flag | Type | Default | Description |
|---|---|---|---|
| `--repo`, `-R` | `string` | - | Repository (owner/name); the origin of the current directory by default. |
| `--limit` | `integer` | `5` | The most issues that one run files; the worst severity goes first. |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

---

## devops ai
Expand Down
18 changes: 18 additions & 0 deletions docs/commands/scan.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,21 @@ devops scan sarif [OPTIONS] <document>
| `--json` | `boolean` | - | Output findings or metrics as JSON. |

---

## `devops scan alerts`

**File one issue for each open Trivy-config code scanning alert group that has none.**

```bash
devops scan alerts [OPTIONS]
```

**Options:**

| Option / Flag | Type | Default | Description |
|---|---|---|---|
| `--repo`, `-R` | `string` | - | Repository (owner/name); the origin of the current directory by default. |
| `--limit` | `integer` | `5` | The most issues that one run files; the worst severity goes first. |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Design

## Decisions

- **One group, one issue.** The key is the rule id and the path. One alert for each issue would make 52 issues at once, and one issue for a run would hold several fixes. The title is the key of the check for an open issue, so the check needs no state of its own.
- **The title is compared exactly.** An open issue with the same title means the group has an owner. The cost: intake can correct the type of a title (`fix` to `chore`), and the next run then files the group again. The filer limit of 5 bounds that cost. A hidden marker in the body would remove it, and the requirement of the issue asks for the title.
- **The worst severity first.** With a limit of 5, a CRITICAL alert never waits behind a LOW one.
- **A workflow, not a step of CI, and no `workflow_run`.** It needs `issues: write`, and a pull request run must not write issues. A `workflow_run` trigger would make zizmor report a HIGH finding (`dangerous-triggers`), one more alert with no judge, and the project allows no ignore of it. A daily schedule gives a new alert its issue in one day at most. The group `concurrency` stops two runs from filing the same issue.
- **Session and not `gh`.** The filer uses the GitHub session that `devops pr evidence` uses, so it paces and retries each request as the other commands do.
- **`.trivyignore.yaml` only for the IaC scan.** The image scans keep `.trivyignore` with `exp:`. The YAML form is the one that holds a path, a reason and an expiry, which a finding in one file of `k8s/` or `tf/` needs.
- **Judge and time.** The owner judges CRITICAL in 24 hours, because `SECURITY.md` forbids an agent to ignore CRITICAL. An agent judges the rest in 14 days, the longest total of an agent ignore.

## Rejected alternatives

- A rule in `SECURITY.md` only: it leaves the alert in the Security tab until a person looks.
- A job only: an issue with no judge and no time waits like the 52 alerts.
- A row on the status lane of the Service: it needs a new row, a setting and a token scope for work that CI already starts.
- A step in the CI workflow: a pull request run must not write issues.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Proposal

## Why

52 `Trivy-config` code scanning alerts stay open on `main`, and no fix, dismissal or ignore names them. Other scanners get a fix in days. Nothing turns a new `Trivy-config` alert into work, and `SECURITY.md` names no judge and no time. Closes #4401.

## What Changes

- Add `src/devops_cli/security/alert_filer.py` and the command `devops scan alerts`. It reads the open `Trivy-config` alerts, groups them by rule and path, and files one issue for each group that no open issue names, at most 5 in one run, the worst severity first.
- Add the workflow `.github/workflows/trivy-config-alerts.yml`. It runs `devops scan alerts` each day, with `security-events: read` and `issues: write`.
- Add the section "Judging a Trivy-config Alert" to `SECURITY.md`: the owner judges a CRITICAL alert within 24 hours, an agent judges the others within 14 days, and an IaC ignore goes to `.trivyignore.yaml` with `statement` and `expired_at`.
- Make the `trivy config` scan name `.trivyignore.yaml` of its directory with `--ignorefile`, so the entry of that file has an effect.
- The 52 alerts that are open now stay for #4409. This change adds no ignore entry and dismisses no alert.
- The change fits one pull request.

## Capabilities

### New Capabilities

- `trivy-config-alerts`: The filer, its workflow, the policy rule and the ignore file of the IaC scan

### Modified Capabilities

None.

## Impact

- Code: `src/devops_cli/security/alert_filer.py`, `src/devops_cli/security/trivy.py`, `src/devops_cli/security/scan_plans.py`, `src/devops_cli/commands/scan.py`, constants and language entries
- Workflow: `.github/workflows/trivy-config-alerts.yml`
- Documents: `SECURITY.md`, the generated command pages
- Tests: `tests/security/test_alert_filer.py`, `tests/security/test_trivy_config_ignore.py`, `tests/commands/test_scan_alerts.py`, `tests/invariants/test_workflow_contracts.py`, `tests/invariants/test_agents_md.py`

## Feasibility

- The alerts exist now. `devops gh api 'repos/dan-petty/devops-cli/code-scanning/alerts?state=open&per_page=100' --paginate` on 2026-11-11 gave 52 open alerts of the tool `Trivy-config` (1 critical, 10 high, 19 medium, 22 low). The latest analysis of the category `/devops-scan` for `Trivy-config` reports 52 results, so the scan still finds them.
- The read path works on the real payload: `read_open_alerts` parsed the 52 alerts, `group_alerts` made 52 groups, and `plan_filing` with the 400 open issues of that day chose `AZU-0041` first and left 47 for later runs. No issue was filed in this check.
- The issue text proposes `.trivyignore.yaml`. The repository holds `.trivyignore` only, which `trivy` reads by default. A test with Trivy 0.75.0 shows that a `.trivyignore.yaml` entry with `paths`, `statement` and `expired_at` hides `DS-0002` only when `--ignorefile .trivyignore.yaml` is named, and that Trivy fails with `ignore file not found` when the file is missing. So the scan names the file only when it exists (task 1.3). The plain `.trivyignore` with `exp:` cannot name a path, so the IaC rule uses the YAML file.
- A new issue needs no intake label: `docs/ROADMAP_WORKFLOW.md` lists "a new issue on GitHub" as a way to capture, and the filer sets only `type/bug` and `scope/security`.
- The issue text asks for a `workflow_run` trigger after CI. `devops scan workflows` on 2026-11-11 reports that trigger as a HIGH zizmor finding (`dangerous-triggers`), and the project publishes such findings to code scanning, so the trigger would add one more alert with no judge. The workflow therefore runs on a daily schedule only. The CI run on `main` uploads the alerts, and the next daily run files their issues. A step of the CI workflow is no choice either: a pull request run must not write issues.

## Existing Tool Considered

Trivy covers the detection, and the scoped ignore with `statement` and `expired_at`, and this change uses both. The alerts API of GitHub covers the record. No open tool files an issue for a code scanning alert group: the alternatives check of 2026-11-11 found none. The code is about 190 lines on the GitHub session that exists. The cost is about 350k tokens to build, about 120k tokens a year to keep and fix, and about 6 hours of elapsed time.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## ADDED Requirements

### Requirement: The filer lists the open Trivy-config alerts
The alert filer SHALL list each open code scanning alert whose tool is `Trivy-config` and no other alert.

#### Scenario: A payload with a second tool
- **WHEN** the alerts payload holds three `Trivy-config` alerts and one `CodeQL` alert
- **THEN** the filer groups the three `Trivy-config` alerts and no `CodeQL` alert

### Requirement: The filer groups the alerts by rule and path
The filer SHALL group the open alerts by rule id and file path, and it SHALL put the group with the worst severity first.

#### Scenario: Two alerts of one rule in one file
- **WHEN** two open alerts hold the rule id `KSV-0017` and the path `k8s/gpu-feature-discovery/daemonset.yaml`
- **THEN** the filer gives one group, and the body of the group names both alert numbers

### Requirement: A group that an open issue names gets no new issue
The filer SHALL skip each group whose exact title an open issue holds. A pull request with that title is no issue.

#### Scenario: One group with an open issue
- **WHEN** an open issue holds the title of one group and the other group has no issue
- **THEN** the filer files one issue, for the group with no open issue

### Requirement: One run files a bounded number of issues
The filer MUST file at most five issues in one run, and it SHALL name the groups that it leaves for the next run.

#### Scenario: Eight groups with no issue
- **WHEN** eight groups have no open issue and the limit is five
- **THEN** the filer files five issues and names the three groups that it leaves for the next run

### Requirement: The filed issue holds the rule, the path and the severity
The filer SHALL put the rule id, the path, the severity and the alert numbers in the issue that it files. The title SHALL be `fix(security): judge Trivy-config <rule-id> in <path>`.

#### Scenario: The body of a filed issue
- **WHEN** the filer files an issue for the rule id `DS-0002` at `.devcontainer/Dockerfile` with the severity `HIGH`
- **THEN** the title holds `DS-0002` and `.devcontainer/Dockerfile`, and the body holds `HIGH` and the alert number

### Requirement: The workflow runs every day with the least permissions
The alert workflow MUST run on a daily schedule, with the permissions `contents: read`, `security-events: read` and `issues: write` only. It SHALL have no `workflow_run` trigger, which zizmor reports as a HIGH finding.

#### Scenario: The triggers of the workflow
- **WHEN** a test reads the `on` block of `.github/workflows/trivy-config-alerts.yml`
- **THEN** the block holds a `schedule` trigger and no `workflow_run` trigger

### Requirement: The policy names the judge and the time
`SECURITY.md` SHALL name who judges a new `Trivy-config` alert, the time in which it happens, and the ignore file with its reason and expiry fields.

#### Scenario: The Trivy-config rule in the policy
- **WHEN** a test reads the `Trivy-config` rule of `SECURITY.md`
- **THEN** the rule names the owner for a CRITICAL alert within 24 hours, an agent for the other severities within 14 days, and `.trivyignore.yaml` with `statement` and `expired_at`

### Requirement: The IaC scan reads the ignore file with an expiry
The `trivy config` scan SHALL name `.trivyignore.yaml` of its directory with `--ignorefile` when that file exists, and it SHALL name no ignore file when it does not.

#### Scenario: A directory with the file
- **WHEN** the scan starts in a directory that holds `.trivyignore.yaml`
- **THEN** the command holds `--ignorefile` and the path of that file, and Trivy hides a finding of an entry whose `expired_at` is later than today
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Tasks

## 1. Behavior

- [x] 1.1 Write the failing tests of the filer, the command, the workflow, the policy rule and the ignore file
- Verification: `$ uv run devops ci test tests/security/test_alert_filer.py tests/commands/test_scan_alerts.py tests/invariants/test_workflow_contracts.py tests/invariants/test_agents_md.py tests/security/test_trivy_config_ignore.py`
- [x] 1.2 Add the filer, the command `devops scan alerts` and the workflow
- Verification: `$ uv run devops ci test tests/security/test_alert_filer.py tests/commands/test_scan_alerts.py tests/invariants/test_workflow_contracts.py tests/invariants/test_agents_md.py`
- [x] 1.3 Make the `trivy config` scan name `.trivyignore.yaml` when it exists
- Verification: `$ uv run devops ci test tests/security/test_trivy_config_ignore.py`

## 2. Documents

- [x] 2.1 Add the section "Judging a Trivy-config Alert" to `SECURITY.md`, and regenerate the command pages
- Verification: `$ uv run devops ci docs`
Loading
Loading