Vulnerability scanning is the first gate that decides whether a software artifact deserves to reach production. The objective is to detect CVEs before an image is published, repeat the scan on every push, and feed the findings into both the deployment decision and the external security operations stack.
Google Cloud expresses this pipeline through three services that compose without glue code: Cloud Build runs the build, Artifact Registry stores the result, and Artifact Analysis scans every image as soon as it lands. The Container Scanning API discovers vulnerabilities in operating-system packages and language ecosystems (Java, Python, JavaScript, Go), and writes findings as Grafeas Occurrence resources attached to the image digest, which makes downstream tooling deterministic because every reference is by SHA-256 rather than by tag.
Cloud Build is the canonical place to enforce the gate because it already authenticates as a service account, runs inside Google's network, and writes provenance metadata. A typical pipeline checks out source, runs unit tests, builds an image, pushes to Artifact Registry, then polls Artifact Analysis for findings before either tagging the digest with an attestation or failing the build.
The build can also call gcloud artifacts docker images scan for on-demand scanning of an image that was not pushed to Artifact Registry, which is useful for staging analysis against a developer laptop build. The result is a JSON document with severity buckets (CRITICAL, HIGH, MEDIUM, LOW, MINIMAL) that the pipeline can parse to fail any build with a CRITICAL finding above a tolerated count.
Pipeline ownership matters because the build service account is the identity that pushes artifacts and signs attestations.
The default Compute Engine service account is over-privileged for this purpose; the recommended pattern is a dedicated build service account scoped to roles/artifactregistry.writer on the registry, roles/cloudbuild.builds.builder in the build project, and the minimum Cloud KMS signer role on the attestor key.
Cloud Build with private pools removes the need for outbound public egress and lets the build run inside a customer-controlled VPC, which is the path that fits a workload subject to a VPC Service Controls perimeter from the previous chapter.
Provenance generation (provenance: true) records a SLSA Level 3 statement that subsequent attestors can verify cryptographically.
How it works
A complete CI/CD scan loop pushes the image, waits for Artifact Analysis to converge, queries findings filtered by severity, and either succeeds or fails based on a documented threshold policy.
The wait is necessary because scanning is asynchronous; the API publishes findings after the image is fully indexed.
The pipeline should also subscribe to the container-analysis-occurrences-v1 Pub/Sub topic to receive future occurrences when new vulnerabilities are disclosed against previously scanned images, then trigger a rebuild or quarantine workflow.
# cloudbuild.yaml
serviceAccount: projects/sec-cicd-prod/serviceAccounts/build-runner@sec-cicd-prod.iam.gserviceaccount.com
options:
pool:
name: projects/sec-cicd-prod/locations/us-central1/workerPools/private-pool
requestedVerifyOption: VERIFIED
logging: CLOUD_LOGGING_ONLY
steps:
- name: gcr.io/cloud-builders/docker
args: ["build", "-t",
"us-central1-docker.pkg.dev/sec-cicd-prod/apps/payments:${SHORT_SHA}", "."]
- name: gcr.io/cloud-builders/docker
args: ["push",
"us-central1-docker.pkg.dev/sec-cicd-prod/apps/payments:${SHORT_SHA}"]
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
entrypoint: bash
args:
- -c
- |
IMAGE="us-central1-docker.pkg.dev/sec-cicd-prod/apps/payments:${SHORT_SHA}"
DIGEST=$(gcloud artifacts docker images describe "$IMAGE" \
--format='value(image_summary.digest)')
for i in {1..30}; do
STATE=$(gcloud artifacts docker images list-vulnerabilities \
"us-central1-docker.pkg.dev/sec-cicd-prod/apps/payments@$DIGEST" \
--format='value(vulnerability.effectiveSeverity)' | sort -u)
if [ -n "$STATE" ]; then break; fi
sleep 20
done
CRIT=$(gcloud artifacts docker images list-vulnerabilities \
"us-central1-docker.pkg.dev/sec-cicd-prod/apps/payments@$DIGEST" \
--filter="vulnerability.effectiveSeverity=CRITICAL" \
--format='value(name)' | wc -l)
if [ "$CRIT" -gt 0 ]; then
echo "Blocked: $CRIT CRITICAL CVEs"; exit 1
fi
provenance:
enabled: true
💡 Exam Trap: Artifact Analysis publishes findings asynchronously after the push completes. A naive pipeline that queries vulnerabilities immediately after
docker pushreceives an empty list and proceeds to deploy. Always poll on the digest until findings stabilize, or subscribe to the Pub/Sub topic that emits new Occurrences.
📊 Limit: Container Scanning API supports manifest formats including Docker Image Manifest V2 (schemas 1 and 2) and OCI image format. Operating-system support spans common base images such as Debian, Ubuntu, RHEL, CentOS, Alpine, and others; language-package scanning covers Maven, npm, Python, and Go modules. Verify the supported-OS matrix on the Artifact Analysis page before standardizing a base image.
Exporting logs to external security systems
A CI/CD scan is only as useful as the systems that act on its output.
External security operations centers (SOCs) running Splunk, Chronicle SIEM, IBM QRadar, Elastic, or Microsoft Sentinel need a deterministic delivery path for build logs, scanning results, attestation events, and downstream audit logs. Google Cloud expresses that path with two primitives:
- log sinks that write to Pub/Sub for stream-based consumers
- log sinks that write to Cloud Storage or BigQuery for batch consumers
A Pub/Sub sink with a Dataflow subscription is the canonical pattern for Chronicle ingestion via the Chronicle forwarder, while Splunk consumes the same Pub/Sub topic through the Splunk Add-on for Google Cloud Platform with a Dataflow template (Pub/Sub to Splunk) that handles batching, retry, and dead-letter routing.
Steps
For pipeline-specific exports the build project should hold a sink filtered to Cloud Build events and Container Scanning occurrences, then route that sink to a security-owned Pub/Sub topic in a separate project.
The sink writer identity must be granted roles/pubsub.publisher on the destination topic and added to the destination project's VPC Service Controls perimeter ingress rule if the topic lives behind one.
Use unique writer identities (uniqueWriterIdentity: true) so each sink has its own service account that you can revoke without affecting unrelated routes.
gcloud logging sinks create cve-export \
pubsub.googleapis.com/projects/sec-siem-prod/topics/cve-events \
--log-filter='resource.type="build" OR
(logName:"cloudaudit.googleapis.com" AND
protoPayload.serviceName="containeranalysis.googleapis.com")' \
--project=sec-cicd-prod
SINK_SA=$(gcloud logging sinks describe cve-export \
--project=sec-cicd-prod --format='value(writerIdentity)')
gcloud pubsub topics add-iam-policy-binding cve-events \
--project=sec-siem-prod \
--member="$SINK_SA" --role=roles/pubsub.publisher
⚠️ Anti-Pattern: Sending scanning results directly from Cloud Build through HTTP webhooks to an external SIEM bypasses the durable Pub/Sub topic and loses messages whenever the SIEM ingestion endpoint is degraded. Always route through Pub/Sub so the broker buffers during downstream outages.
🎯 Scenario: A retail platform must block any image with a CRITICAL CVE from reaching production but still ship hotfixes within minutes. The team configures Cloud Build to poll Artifact Analysis for two minutes after push, fail the build on any CRITICAL finding, write the entire build log plus occurrences to a Pub/Sub sink that fans out to Chronicle and Splunk, and notify the on-call rotation through a Pub/Sub-triggered Cloud Function that posts to a chat channel. The hotfix path uses the same pipeline; what changes is the rebuild cadence, not the gate.
Decision Anchor: Choose Cloud Build with Artifact Analysis and a Pub/Sub sink to Chronicle or Splunk when the organization standardizes on Google Cloud-native CI/CD with external SIEM ingestion. Choose third-party scanners (Snyk, Aqua, Prisma Cloud, Trivy in Jenkins) when an existing tool chain already owns image scanning, but still publish their findings into Pub/Sub through a small adapter so downstream consumers see one unified feed.
