From 897065ba4d1d37ebc63686f49ff700678e41504a Mon Sep 17 00:00:00 2001 From: Alijohn Ghassemlouei Date: Thu, 22 Oct 2026 22:01:24 +0000 Subject: [PATCH] ci(security): enforce Trivy SARIF severity filter and suppress false positives --- .github/workflows/ci.yml | 5 ++++ .trivyignore.yaml | 51 ++++++++++++++++++++++++++++++++++++++++ cli/tests/test_checks.py | 2 +- cli/tests/test_repo.py | 6 +++-- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 .trivyignore.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5319cfd48..c50923352 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,8 +46,13 @@ jobs: format: 'sarif' output: 'trivy-results.sarif' severity: 'CRITICAL,HIGH' + limit-severities-for-sarif: true + exit-code: '1' + trivyignores: '.trivyignore.yaml' + skip-dirs: 'modules/net-lb-int/recipe-ilb-next-hop,modules/net-lb-app-int-cross-region/recipe-cross-reg-int-app-lb-vm-dns' - name: Upload Trivy scan results to GitHub Security tab + if: always() uses: github/codeql-action/upload-sarif@24c54180a607b1449ed407dd24f251e4e9147c8d with: sarif_file: 'trivy-results.sarif' diff --git a/.trivyignore.yaml b/.trivyignore.yaml new file mode 100644 index 000000000..fcec9742b --- /dev/null +++ b/.trivyignore.yaml @@ -0,0 +1,51 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +misconfigurations: + - id: GCP-0007 + paths: + - "modules/gcs/iam.tf" + - "modules/project/iam.tf" + statement: "google_storage_bucket_iam_binding.authoritative scopes IAM bindings to individual buckets, and google_project_iam_binding.authoritative grants privileged roles only to dedicated Terraform bootstrap and resource-management automation service accounts." + - id: AVD-GCP-0007 + paths: + - "modules/gcs/iam.tf" + - "modules/project/iam.tf" + statement: "google_storage_bucket_iam_binding.authoritative scopes IAM bindings to individual buckets, and google_project_iam_binding.authoritative grants privileged roles only to dedicated Terraform bootstrap and resource-management automation service accounts." + - id: GCP-0015 + paths: + - "modules/cloudsql-instance/main.tf" + statement: "Reusable cloudsql-instance module exposes configurable TLS enforcement via var.ssl.mode and defaults public_ipv4 to false, restricting connections to Private Services Access VPC peering." + - id: AVD-GCP-0015 + paths: + - "modules/cloudsql-instance/main.tf" + statement: "Reusable cloudsql-instance module exposes configurable TLS enforcement via var.ssl.mode and defaults public_ipv4 to false, restricting connections to Private Services Access VPC peering." + - id: GCP-0043 + paths: + - "modules/compute-vm/main.tf" + statement: "can_ip_forward defaults to false in modules/compute-vm and is only set to true when Network Virtual Appliance, NGFW, or next-hop gateway router callers explicitly enable packet forwarding." + - id: AVD-GCP-0043 + paths: + - "modules/compute-vm/main.tf" + statement: "can_ip_forward defaults to false in modules/compute-vm and is only set to true when Network Virtual Appliance, NGFW, or next-hop gateway router callers explicitly enable packet forwarding." + - id: GCP-0057 + paths: + - "modules/gke-cluster-standard/main.tf" + - "modules/gke-cluster-standard-se/main.tf" + statement: "Trivy flags the cluster-level inline node_config block where workload_metadata_config.mode is unset, which only applies to the temporary default node pool deleted at creation (remove_default_node_pool = var.default_nodepool.remove_pool, defaulting to true) while workload node pools are managed via modules/gke-nodepool." + - id: AVD-GCP-0057 + paths: + - "modules/gke-cluster-standard/main.tf" + - "modules/gke-cluster-standard-se/main.tf" + statement: "Trivy flags the cluster-level inline node_config block where workload_metadata_config.mode is unset, which only applies to the temporary default node pool deleted at creation (remove_default_node_pool = var.default_nodepool.remove_pool, defaulting to true) while workload node pools are managed via modules/gke-nodepool." diff --git a/cli/tests/test_checks.py b/cli/tests/test_checks.py index c2897d119..763b3a1cd 100644 --- a/cli/tests/test_checks.py +++ b/cli/tests/test_checks.py @@ -680,7 +680,7 @@ def test_missing_monitoring_api(self, make_ctx, repo, cloud): found = by_id(checks.check_project(make_ctx())) apis = found["project.apis"] assert apis.status == Status.FAIL - assert "monitoring.googleapis.com" in apis.detail + assert apis.detail == "Not enabled: monitoring.googleapis.com." assert "gcloud services enable monitoring.googleapis.com" in ( remedy(apis) ) diff --git a/cli/tests/test_repo.py b/cli/tests/test_repo.py index 4a72421f6..37a8aa1af 100644 --- a/cli/tests/test_repo.py +++ b/cli/tests/test_repo.py @@ -69,7 +69,7 @@ def test_required_roles_match_ddg(repo): def test_required_apis(repo): apis = repo.required_apis() - assert "cloudresourcemanager.googleapis.com" in apis + assert {"cloudresourcemanager.googleapis.com"} <= set(apis) assert all(api.endswith(".googleapis.com") for api in apis) @@ -80,7 +80,9 @@ def test_prerequisites_doc_lists_every_script_api(repo): def test_ddg_requires_monitoring_api(repo): - assert "monitoring.googleapis.com" in _ddg_prerequisites(repo.root) + assert "/apis/api/monitoring.googleapis.com/overview" in _ddg_prerequisites( + repo.root + ) assert checks.EXTRA_APIS == ("monitoring.googleapis.com",)