Skip to content

feat(k8s): scan running third-party images with Trivy Operator #4998

Done

Description

@dan-petty

Update 2026-11-26 (infra move): the Argo CD Applications, namespaces, policies, dashboards and alert rules moved to dan-petty/homelab.

The operator install is in the homelab follow-up. This issue keeps the devops-cli part, after that merge: the deploy-stack entries in stack_lifecycle.py (Helm repository, release, NetworkPolicy and Application tables) and the new egress in SECURITY.md. test_k8s_local_path_placement.py and k8s/devops/renovate/ no longer exist.

Follow-up: dan-petty/homelab#287.


Problem or Motivation

44 third-party images run in the cluster. CI scans one of them (crawl4ai), only on a manifest change, and only reports. Renovate brings patch tags at once (#4905). But these cases get no scan:

  • a fix that comes only in a minor release, which waits for the weekly schedule;
  • a rebuild under the same tag;
  • an image that git does not name, such as the device plugin v0.16.2 and Postgres 17.2.

Nothing marks an image bump as a security fix. This item does not answer the limits remark; it stands on its security value. It is rank 7 of the cluster integration plan #4989.

Proposed Solution & Architectural Design

  1. Install Trivy Operator (Apache-2.0, chart v0.36.1 or later, image digests pinned) with an Argo CD Application in its own namespace.
  2. Run the vulnerability scanner only. Turn off the config audit, RBAC and exposed-secret scanners: CI runs trivy config and gitleaks.
  3. Use ClientServer mode with the built-in Trivy server and the image command. It needs no root, so the namespace can stay restricted.
  4. Keep its database on emptyDir, or on a claim with a CHART_CLAIMS entry in tests/core/test_k8s_local_path_placement.py.
  5. Concurrency 1 or 2, severities HIGH and CRITICAL, ignoreUnfixed: true.
  6. Exclude the devops-cli images and the Service Job pods (skipResourceByLabels or excludeNamespaces).
  7. Add a NetworkPolicy for the namespace, a ServiceMonitor, one dashboard and one alert: a running image has a CRITICAL finding with a fixed version.
  8. Record the new egress (the vulnerability database mirror and the image registries) in SECURITY.md.

Target Subsystem

Security & Vulnerability Scanners (k8s/).

Existing Tool Considered

Trivy Operator (Apache-2.0). It uses the same Trivy that CI runs, so the findings and the ignore rules read the same. It needs no public endpoint, no secret and no host change.

Acceptance Criteria

  • The Argo CD Application is Synced and Healthy, and the namespace enforces restricted Pod Security.
  • VulnerabilityReports exist for the running third-party images, and none for the devops-cli images or the Job pods.
  • A promtool case covers the CRITICAL-with-fix alert.
  • SECURITY.md names the new egress.

Dependencies

None.

Source: #4989

Alternatives check of 2026-11-27: in-use.
The item already names this tool.
Tool: aquasecurity/trivy-operator (https://github.com/aquasecurity/trivy-operator), Apache-2.0, last activity 2026-11-23, maintained.
Reason: Searches and the repository facts confirm Trivy Operator is a Kubernetes-native operator that continuously scans running images with Trivy and emits VulnerabilityReports, which is the issue's need; only the deploy-stack rows and the SECURITY.md egress record remain.

Covers:

  • Continuous scan of running workloads, with VulnerabilityReports per container
  • Built-in Trivy server in ClientServer mode, no root needed
  • Chart values for severities, ignoreUnfixed, concurrency and emptyDir database
  • excludeImages globs and skip label keys for project images
  • Same Trivy engine and ignore rules as the CI scan

Lacks:

  • No CI gate, no fix and no image bump
  • deploy-stack repository, release, NetworkPolicy and Application rows still unwritten
  • SECURITY.md egress record for mirror.gcr.io and image registries still missing
  • skipResourceByLabels tests label keys only, not name values
  • Pod mixing excluded and third-party images is rescanned after each scan

Proposed design

Problem statement

The homelab#426 installs Trivy Operator for the third-party images. The devops-cli deploy-stack tables do not hold the Helm repository and release entries. SECURITY.md does not record the new egress. This change adds only the deploy-stack entries and the egress record.

Acceptance criteria

Requirement: Deploy-stack Helm repository entry

The HELM_REPOS_BY_STACK['infra'] table in stack_lifecycle.py SHALL hold the aquasecurity entry with URL https://aquasecurity.github.io/helm-charts/.

Scenario: Unit test reads the Helm repository table

  • WHEN A test reads HELM_REPOS_BY_STACK['infra']['aquasecurity'].
  • THEN The value is https://aquasecurity.github.io/helm-charts/.

Requirement: Deploy-stack release entry

The HELM_RELEASES_BY_STACK['infra'] table SHALL hold a trivy-operator entry with chart aquasecurity/trivy-operator and namespace trivy-system, and no version key.

Scenario: Unit test reads the release table

  • WHEN A test reads the trivy-operator entry in HELM_RELEASES_BY_STACK['infra'].
  • THEN The entry names chart aquasecurity/trivy-operator and namespace trivy-system, and it holds no version key.

Requirement: Chart version comes from the Application

The deploy-stack release lookup SHALL read the chart version from the targetRevision of the trivy-operator Application in the --k8s-dir environment tree.

Scenario: Release lookup uses the Application version

  • WHEN A test writes a temporary environment tree with a trivy-operator Application at targetRevision 0.38.1 and runs uv run devops k8s deploy-stack --stack infra --dry-run --k8s-dir <dir>.
  • THEN The command exits 0 and its output lists version 0.38.1 for release trivy-operator.

Requirement: No Application table entry

The change SHALL add no trivy-operator entry to APPLICATIONS_BY_STACK, because the homelab Application has no path source.

Scenario: Application table has no Trivy Operator entry

  • WHEN A test reads APPLICATIONS_BY_STACK['infra'].
  • THEN The table holds no trivy-operator entry.

Requirement: No manifest or teardown entry

The change SHALL add no trivy-system entry to MANIFESTS_BY_STACK or _teardown_namespaces, because the homelab environment tree owns the namespace and NetworkPolicy.

Scenario: Manifest and teardown tables stay unchanged

  • WHEN A test reads MANIFESTS_BY_STACK['infra'] and _teardown_namespaces.
  • THEN Neither table holds trivy-system.

Requirement: SECURITY egress record

SECURITY.md SHALL add a TCP 443 egress row from trivy-system to mirror.gcr.io and to the registries of the scanned images.

Scenario: Docs check accepts the egress record

  • WHEN A test runs uv run devops ci --check --only docs and reads SECURITY.md.
  • THEN The docs check exits 0, and SECURITY.md holds a row that names trivy-system and mirror.gcr.io on TCP 443.

Requirement: K8s environment freeze

The change SHALL add no file under the k8s environment tree.

Scenario: K8s check passes

  • WHEN A developer runs uv run devops ci --check --only k8s.
  • THEN The k8s check exits 0 and reports no environment-freeze error.

Existing Tool Considered

Trivy Operator (aquasecurity/trivy-operator) has the verdict in-use in the alternatives check of 2026-11-27 in the issue body. The item already names this tool. The block gives the reason and records what the tool covers and lacks. This change adds the deploy-stack Helm repository and release rows and the SECURITY.md egress record. It builds no scanner and adds no CI gate, fix or image bump.

Key questions

  • Which chart version should the deploy-stack release use?: Read targetRevision from the trivy-operator Application in the environment tree. Keep no chart version in HELM_RELEASES_BY_STACK. (best practice) [sources: openspec/specs/k8s-helm-deploy/spec.md, src/devops_cli/commands/k8s/stack_lifecycle.py:1420]
    • Chosen: Read targetRevision from the Application. The k8s-helm-deploy spec says the code holds no chart version, and _release_at() reads the Application version.
    • Rejected: Pin chart 0.38.1 in HELM_RELEASES_BY_STACK. The spec forbids a chart version in code, and the command raises when the environment tree lacks the Application.
    • Rejected: Use the latest chart. A floating version makes the deployment unreproducible.
  • Which Helm repository and release entries should the deploy-stack tables hold?: Add HELM_REPOS_BY_STACK['infra']['aquasecurity'] = 'https://aquasecurity.github.io/helm-charts/' and the release entry {'name': 'trivy-operator', 'chart': 'aquasecurity/trivy-operator', 'namespace': 'trivy-system'}. (best practice) [sources: src/devops_cli/commands/k8s/stack_lifecycle.py:90, src/devops_cli/commands/k8s/stack_lifecycle.py:142]
    • Chosen: Trailing slash Helm repository URL and release in trivy-system. The chart repository URL and the homelab Application use this form.
    • Rejected: Helm repository URL without trailing slash. The stage return accepts one consistent form, and the trailing slash matches the repository URL.
    • Rejected: Release in namespace trivy-operator. The homelab Application and namespace use trivy-system.
  • Should trivy-operator go into APPLICATIONS_BY_STACK?: No. Add no trivy-operator entry to APPLICATIONS_BY_STACK. (best practice) [sources: src/devops_cli/commands/k8s/stack_lifecycle.py:276, src/devops_cli/commands/k8s/stack_lifecycle.py:1420]
    • Chosen: No Application table entry. APPLICATIONS_BY_STACK builds only path sources, and the homelab Application has chart and ref sources.
    • Rejected: Add a path source. The homelab Application has no path source, so the entry matches zero sources.
    • Rejected: Add a chart source. The Application table code does not build chart sources.
  • Should trivy-system go into _teardown_namespaces or MANIFESTS_BY_STACK?: No. Add no trivy-system entry to _teardown_namespaces or MANIFESTS_BY_STACK. (best practice) [sources: src/devops_cli/commands/k8s/stack_lifecycle.py:1809, docs/HOMELAB_REPO_SWITCH.md]
    • Chosen: No teardown or manifest entry. The homelab environment tree owns the namespace and applies the NetworkPolicy with the root kustomization.
    • Rejected: Add a MANIFESTS_BY_STACK entry. The root kustomization already applies k8s/trivy-system/networkpolicy.yaml.
    • Rejected: Add a _teardown_namespaces entry. Teardown would delete a namespace that the homelab repository owns.
  • Which egress should SECURITY.md record?: Record TCP 443 egress from trivy-system to mirror.gcr.io and to the registries of the scanned images. (best practice) [sources: SECURITY.md:18]
    • Chosen: Record mirror.gcr.io and the image registries on TCP 443. The operator reaches the database mirror and each image registry.
    • Rejected: Record no new egress. The operator adds egress, and SECURITY.md records the egress of each service.
  • Which files can this issue change after the homelab move?: Change only src/devops_cli/commands/k8s/stack_lifecycle.py and SECURITY.md. [sources: docs/HOMELAB_REPO_SWITCH.md, src/devops_cli/commands/k8s/stack_lifecycle.py:90, SECURITY.md:18]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 12, 2026
  2. added
    type/feature
    scope/k8s
    status/new
    value/high
    effort/medium
    on Nov 12, 2026
  3. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 12, 2026
  5. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Alternatives check: covers

    Reason: The searches returned Trivy Operator, a Kubernetes-native toolkit that uses Trivy to scan the images running in a cluster continuously and publishes the results as VulnerabilityReports, and the repository facts match the issue's candidate (Apache-2.0, v0.36.1 released 2026-10-29, maintained). It therefore covers the whole need, and no ADR in force rejects it; the project runs the Trivy CLI in CI, but the operator itself is not yet installed, so it is not in use.

    Tool: aquasecurity/trivy-operator (https://github.com/aquasecurity/trivy-operator)

    • License: Apache-2.0
    • Last activity: 2026-11-15
    • Maintained: yes

    Covers:

    • Continuous vulnerability scanning of the images that run in the cluster, not only of the manifests that CI sees
    • Kubernetes-native custom resources (VulnerabilityReports) that record the findings for each scanned workload image
    • Uses the same Trivy engine and ignore rules as the CI scan, so findings read the same
    • Scanner selection, so only the vulnerability scanner needs to run beside the CI config and secret checks
    • No public endpoint, secret or host change is needed for the scan

    Lacks:

    • Does not replace the CI-side trivy config or gitleaks checks; the issue keeps those in CI
    • Does not mark an image bump in git as a security fix
    • Needs its own namespace, CRDs and egress to the vulnerability database mirror and image registries

    Tools considered:

    Searches run:

    • Trivy Operator Kubernetes vulnerability scanner running images, results: 5
    • aquasecurity trivy-operator VulnerabilityReport kubernetes cluster image scanning, results: 5
    • trivy operator helm chart install vulnerability scanning docs, results: 5
    • trivy-operator, results: 5
    • trivy operator client server mode vulnerability scanner settings, results: 5

    Sources:

    Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.

  6. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Owner question: The alternatives check found that https://github.com/aquasecurity/trivy-operator covers this item. Adopt the tool, or keep the item and give the reason. (a person decides)

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  7. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Owner question: See the first point of Open questions in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  8. dan-petty commented on Nov 23, 2026

    @dan-petty
    OwnerAuthor

    The daily image rescan workflow (.github/workflows/image-rescan.yml) covers the project's own images (service, runner, mcp-server, and devcontainer). Third-party images stay with Trivy Operator.

  9. added
    status/ready
    and removed
    status/new
    on Nov 23, 2026
  10. 9 remaining items

  11. dan-petty commented on Nov 28, 2026

    @dan-petty
    OwnerAuthor

    Returning #4998 to status/new because the Proposed design in the issue body contradicts the current codebase and living spec after #6060 and #7290 (AGENTS.md rule 2: return a leaf item that cannot be built as written rather than writing compensating code):

    1. No chart version in code (stack_lifecycle.py & openspec/specs/k8s-helm-deploy/spec.md): The refine design requires "The deploy-stack release table SHALL pin the Trivy Operator chart at version 0.38.1" and a dry-run scenario outputting 0.38.1 without --k8s-dir. However, openspec/specs/k8s-helm-deploy/spec.md ("deploy-stack installs each chart at the version that its Application pins") states "The code SHALL hold no chart version", HELM_RELEASES_BY_STACK in src/devops_cli/commands/k8s/stack_lifecycle.py holds no chart versions, and _release_at() (stack_lifecycle.py:1420-1443) reads targetRevision from the Argo CD Application trivy-operator in --k8s-dir and raises KubernetesDeployError when the environment tree lacks that Application.
    2. No NetworkPolicy table and no path source Application: The refine design requires adding entries to "the existing NetworkPolicy and Application tables in stack_lifecycle.py". stack_lifecycle.py has no NetworkPolicy table, and APPLICATIONS_BY_STACK (stack_lifecycle.py:276-285) builds only path sources (_path_builds filters "path" in source). In dan-petty/homelab#426, k8s/argocd/apps/trivy-operator.yaml has a Helm chart source (0.38.1) and a ref: values source with no path source, while the namespace NetworkPolicy is included via the root kustomization (trivy-system/kustomization.yaml). Adding trivy-operator to APPLICATIONS_BY_STACK would match zero path sources, and k8s/trivy-system/networkpolicy.yaml is already applied with the root kustomization (stack_lifecycle.py:1809) unless explicitly needed in MANIFESTS_BY_STACK.

    Re-refine #4998 to specify only:

    • HELM_REPOS_BY_STACK["infra"]["aquasecurity"] = "https://aquasecurity.github.io/helm-charts/" (or consistent trailing slash form) and HELM_RELEASES_BY_STACK["infra"] entry {"name": "trivy-operator", "chart": "aquasecurity/trivy-operator", "namespace": "trivy-system"} (version and values read from the environment tree's trivy-operator Application per k8s-helm-deploy, plus whether "trivy-system" belongs in _teardown_namespaces / MANIFESTS_BY_STACK);
    • Recording the trivy-system TCP 443 egress (mirror.gcr.io and scanned image registries) in SECURITY.md.
  12. added
    status/new
    and removed
    status/ready
    on Nov 28, 2026
  13. added
    status/ready
    and removed
    status/new
    on Nov 28, 2026
  14. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  15. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  16. removed
    status/in-review
    on Nov 29, 2026
  17. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 16:17 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/k8ssource/agenttype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions