Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 5 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,12 @@ All Go microservices are compiled using a single, unified multi-target Dockerfil
- Long-running metrics collector daemon (`go/cmd/custommetrics/`) that periodically reads batch/dataset state from Datastore (`JobData`, `SourceRepository`, `ImportFindings`) and GCS (`all.zip`, `modified_id.csv`) and exposes dataset, drift, reconciler, deleter, and linter state metrics on `:9090/metrics` for GMP/Grafana.

13. **`vanir_signatures`**:
- Cron job orchestrated in Go (`go/cmd/vanir_signatures/` and `go/internal/vanir/`) that queries modified vulnerabilities, shells out to a minimal Python helper script (`generate_signatures.py`) to run Vanir signature generation, and writes enriched signatures back to the database.
- Cron job orchestrated in Go (`go/cmd/vanir_signatures/` and `go/internal/vanir/`) that queries modified vulnerabilities, generates Vanir signatures, and writes them back to the database. Supports both remote Cloud Run `vanir-sandbox` execution (via `VANIR_SANDBOX_URL`) and local `generate_signatures.py` fallback.

14. **`ubuntubinarymapper`**:
14. **`vanir_sandbox`**:
- Untrusted Cloud Run Gen2 HTTP service (`go/cmd/vanir_sandbox/`) that executes `generate_signatures.py` for a single vulnerability record per request under a unique non-root Linux UID, isolated `0700` work directory, and fail-closed post-request `kill(-1, SIGKILL)` UID reaping, running with a zero-IAM-role service account and no VPC access.

15. **`ubuntubinarymapper`**:
- Run as a cron job (`go/cmd/ubuntubinarymapper/`).
- Reads `Ubuntu/modified_id.csv` from the exported GCS bucket (`gs://osv-vulnerabilities`) with a 1-hour lookback window, downloads modified Ubuntu vulnerability records (via `Ubuntu/all.zip` or individual `Ubuntu/<id>.json` files), extracts binary-to-source package name mappings from `ecosystem_specific`, and persists them to Datastore (`UbuntuPackageMapping`) alongside a `JobData` execution checkpoint (or to a local JSON file via `-output-json`).

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lib-tests: ## Run core Python library tests
./run_tests.sh

vanir-signatures-tests: ## Run Vanir signatures tests
cd go && go test ./internal/vanir/... ./cmd/vanir_signatures/...
cd go && go test ./internal/vanir/... ./cmd/vanir_signatures/... ./cmd/vanir_sandbox/...

vulnfeed-tests: ## Run Go vulnfeeds tests
cd vulnfeeds && ./run_tests.sh
Expand Down
23 changes: 23 additions & 0 deletions deployment/build-and-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ steps:
args: ['push', '--all-tags', 'gcr.io/oss-vdb/vanir-signatures']
waitFor: ['build-vanir-signatures', 'cloud-build-queue']

# Build/push vanir-sandbox images to gcr.io/oss-vdb.
- name: gcr.io/cloud-builders/docker
args: ['buildx', 'build', '--load', '-t', 'gcr.io/oss-vdb/vanir-sandbox:latest', '-t', 'gcr.io/oss-vdb/vanir-sandbox:$COMMIT_SHA', '--target', 'vanir-sandbox', '--build-context', 'bindings=../bindings', '--build-context', 'poetry=../docker/poetry', '-f', 'Dockerfile', '--pull', '.']
dir: 'go'
id: 'build-vanir-sandbox'
waitFor: ['build-vanir-signatures']
volumes:
- name: 'docker-config'
path: '/root/.docker'
- name: gcr.io/cloud-builders/docker
args: ['push', '--all-tags', 'gcr.io/oss-vdb/vanir-sandbox']
waitFor: ['build-vanir-sandbox', 'cloud-build-queue']

# Build/push cron job images.
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/oss-vdb/cron:latest', '-t', 'gcr.io/oss-vdb/cron:$COMMIT_SHA', '.']
Expand Down Expand Up @@ -583,6 +596,16 @@ steps:
id: 'deploy-osv-website'
waitFor: ['goose-up']

# Vanir Sandbox
- name: 'gcr.io/cloud-builders/gcloud'
args: ['deploy', 'releases', 'create', 'osv-$SHORT_SHA', '--project=oss-vdb', '--region=us-central1',
'--delivery-pipeline=vanir-sandbox', '--images',
"vanir-sandbox=gcr.io/oss-vdb/vanir-sandbox:$COMMIT_SHA"
]
dir: deployment/clouddeploy/vanir-sandbox
id: 'deploy-vanir-sandbox'
waitFor: ['goose-up']

timeout: 7200s
# Also set in Cloud Build:
serviceAccount: 'projects/oss-vdb/serviceAccounts/deployment@oss-vdb.iam.gserviceaccount.com'
Expand Down
39 changes: 39 additions & 0 deletions deployment/clouddeploy/vanir-sandbox/clouddeploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: deploy.cloud.google.com/v1
kind: DeliveryPipeline
metadata:
name: vanir-sandbox
description: Vanir sandbox Cloud Run pipeline
serialPipeline:
stages:
- targetId: staging-vanir-sandbox
profiles: [ staging ]
- targetId: production-vanir-sandbox
profiles: [ prod ]
---

apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
name: staging-vanir-sandbox
description: oss-vdb-test vanir-sandbox instance
run:
location: projects/oss-vdb-test/locations/us-west2
executionConfigs:
- usages:
- RENDER
- DEPLOY
serviceAccount: deployment@oss-vdb.iam.gserviceaccount.com
---

apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
name: production-vanir-sandbox
description: oss-vdb vanir-sandbox instance
run:
location: projects/oss-vdb/locations/us-west2
executionConfigs:
- usages:
- RENDER
- DEPLOY
serviceAccount: deployment@oss-vdb.iam.gserviceaccount.com
31 changes: 31 additions & 0 deletions deployment/clouddeploy/vanir-sandbox/run-prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: vanir-sandbox
annotations:
run.googleapis.com/ingress: all
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/minScale: '0'
autoscaling.knative.dev/maxScale: '30'
run.googleapis.com/execution-environment: gen2
spec:
serviceAccountName: vanir-sandbox@oss-vdb.iam.gserviceaccount.com
containerConcurrency: 1
timeoutSeconds: 1800
containers:
- image: vanir-sandbox
ports:
- containerPort: 8080
startupProbe:
httpGet:
path: /healthz
livenessProbe:
httpGet:
path: /healthz
resources:
limits:
cpu: '4'
memory: 8Gi
31 changes: 31 additions & 0 deletions deployment/clouddeploy/vanir-sandbox/run-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: vanir-sandbox
annotations:
run.googleapis.com/ingress: all
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/minScale: '0'
autoscaling.knative.dev/maxScale: '30'
run.googleapis.com/execution-environment: gen2
spec:
serviceAccountName: vanir-sandbox@oss-vdb-test.iam.gserviceaccount.com
containerConcurrency: 1
timeoutSeconds: 1800
containers:
- image: vanir-sandbox
ports:
- containerPort: 8080
startupProbe:
httpGet:
path: /healthz
livenessProbe:
httpGet:
path: /healthz
resources:
limits:
cpu: '4'
memory: 8Gi
18 changes: 18 additions & 0 deletions deployment/clouddeploy/vanir-sandbox/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: skaffold/v3
kind: Config
metadata:
name: vanir-sandbox

profiles:
- name: staging
manifests:
rawYaml:
- run-staging.yaml

- name: prod
manifests:
rawYaml:
- run-prod.yaml

deploy:
cloudrun: {}
4 changes: 4 additions & 0 deletions deployment/deploy-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ steps:
args: ['deploy', 'releases', 'promote', '--quiet', '--release=osv-$SHORT_SHA', '--region=us-central1', '--delivery-pipeline=gke-indexer', '--to-target=production-indexer', '--annotations=tag=$TAG_NAME']
- name: gcr.io/cloud-builders/gcloud
args: ['deploy', 'releases', 'promote', '--quiet', '--release=osv-$SHORT_SHA', '--region=us-central1', '--delivery-pipeline=osv-website', '--to-target=production-website', '--annotations=tag=$TAG_NAME']
- name: gcr.io/cloud-builders/gcloud
args: ['deploy', 'releases', 'promote', '--quiet', '--release=osv-$SHORT_SHA', '--region=us-central1', '--delivery-pipeline=vanir-sandbox', '--to-target=production-vanir-sandbox', '--annotations=tag=$TAG_NAME']

# Deploy OSS-Fuzz workers
- name: gcr.io/cloud-builders/gcloud
Expand Down Expand Up @@ -88,6 +90,8 @@ steps:
args: ['container', 'images', 'add-tag', '--quiet', 'gcr.io/oss-vdb/osv-website:$COMMIT_SHA', 'gcr.io/oss-vdb/osv-website:$TAG_NAME']
- name: gcr.io/cloud-builders/gcloud
args: ['container', 'images', 'add-tag', '--quiet', 'gcr.io/oss-vdb/recoverer:$COMMIT_SHA', 'gcr.io/oss-vdb/recoverer:$TAG_NAME']
- name: gcr.io/cloud-builders/gcloud
args: ['container', 'images', 'add-tag', '--quiet', 'gcr.io/oss-vdb/vanir-sandbox:$COMMIT_SHA', 'gcr.io/oss-vdb/vanir-sandbox:$TAG_NAME']

serviceAccount: 'projects/oss-vdb/serviceAccounts/deployment@oss-vdb.iam.gserviceaccount.com'
options:
Expand Down
5 changes: 5 additions & 0 deletions deployment/terraform/environments/oss-vdb-test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ output "postgres_read_pool_private_ip" {
value = module.osv_api.read_pool_private_ip_address
}

output "vanir_sandbox_uri" {
description = "HTTPS URI of the untrusted Vanir sandbox Cloud Run service"
value = module.osv_test.vanir_sandbox_uri
}

variable "deployment_service_account_email" {
type = string
description = "CI/CD deployment service account email."
Expand Down
5 changes: 5 additions & 0 deletions deployment/terraform/environments/oss-vdb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ output "postgres_read_pool_private_ip" {
value = module.osv_api.read_pool_private_ip_address
}

output "vanir_sandbox_uri" {
description = "HTTPS URI of the untrusted Vanir sandbox Cloud Run service"
value = module.osv.vanir_sandbox_uri
}

terraform {
backend "gcs" {
bucket = "oss-vdb-tf"
Expand Down
5 changes: 5 additions & 0 deletions deployment/terraform/modules/osv/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ output "public_import_logs_bucket_name" {
value = google_storage_bucket.osv_public_import_logs.name
description = "The name of the public import logs bucket."
}

output "vanir_sandbox_uri" {
value = google_cloud_run_v2_service.vanir_sandbox.uri
description = "The HTTPS URI of the vanir-sandbox Cloud Run service."
}
74 changes: 74 additions & 0 deletions deployment/terraform/modules/osv/vanir_sandbox.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Dedicated zero-privilege service account for the untrusted Vanir sandbox Cloud Run service.
# Intentionally granted ZERO IAM roles so querying the metadata server yields no GCP permissions.
resource "google_service_account" "vanir_sandbox" {
project = var.project_id
account_id = "vanir-sandbox"
display_name = "Vanir Sandbox Service Account (zero IAM roles)"
}

# Allow CI/CD deployment and Terraform service accounts to attach vanir_sandbox to Cloud Run revisions.
# This grants permissions ON the service account to deployers, not TO the service account itself.
resource "google_service_account_iam_member" "vanir_sandbox_deployer_act_as" {
for_each = toset([
for email in var.frontend_deployer_service_account_emails : "serviceAccount:${email}"
])

service_account_id = google_service_account.vanir_sandbox.name
role = "roles/iam.serviceAccountUser"
member = each.value
}

# Untrusted Cloud Run Gen2 microVM sandbox for running Vanir signature generation.
# Note: template is in lifecycle.ignore_changes, so Terraform only bootstraps the initial
# revision; deployment/clouddeploy/vanir-sandbox/run-{staging,prod}.yaml are the source of
# truth for runtime settings (zero-IAM SA, Gen2, concurrency=1, and no VPC access).
resource "google_cloud_run_v2_service" "vanir_sandbox" {
project = var.project_id
name = "vanir-sandbox"
location = "us-west2"
ingress = "INGRESS_TRAFFIC_ALL"

depends_on = [google_service_account_iam_member.vanir_sandbox_deployer_act_as]

template {
service_account = google_service_account.vanir_sandbox.email
execution_environment = "EXECUTION_ENVIRONMENT_GEN2"
max_instance_request_concurrency = 1
timeout = "1800s"

scaling {
min_instance_count = 0
max_instance_count = 30
}

containers {
image = "gcr.io/oss-vdb/vanir-sandbox:latest" # Placeholder image.
resources {
limits = {
cpu = "4"
memory = "8Gi"
}
}
}
}

lifecycle {
ignore_changes = [
# To be managed by Cloud Deploy.
template,
traffic,
labels,
client,
]
}
Comment thread
another-rex marked this conversation as resolved.
Resolved
}

# Restrict invocation strictly to the GKE worker service account (never allUsers).
resource "google_cloud_run_v2_service_iam_member" "vanir_sandbox_invoker" {
count = var.worker_service_account_email != "" ? 1 : 0
project = var.project_id
location = google_cloud_run_v2_service.vanir_sandbox.location
name = google_cloud_run_v2_service.vanir_sandbox.name
role = "roles/run.invoker"
member = "serviceAccount:${var.worker_service_account_email}"
}
21 changes: 20 additions & 1 deletion go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#
# Select which service to build using the --target flag (e.g. importer, worker, exporter, exporter-deleter,
# relations, recordchecker, generatesitemap, custommetrics, gitter, first_package_finder,
# api, recoverer, vanir-signatures, ubuntubinarymapper, staging-api-test, website, osv-linter).
# api, recoverer, vanir-signatures, vanir-sandbox, ubuntubinarymapper, staging-api-test, website, osv-linter).
# ====================================================================================

# ========================================================
Expand Down Expand Up @@ -254,6 +254,25 @@ COPY cmd/vanir_signatures/generate_signatures.py /usr/local/bin/generate_signatu
RUN chmod 755 /usr/local/bin/generate_signatures.py
ENTRYPOINT ["/usr/local/bin/vanir_signatures"]

# ========================================================
# Target: Vanir Sandbox
# ========================================================
FROM builder AS vanir-sandbox-build
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 go build -o /app/vanir_sandbox ./cmd/vanir_sandbox/

FROM python:3.13-slim@sha256:8d9d0b8bcf6506481eae4907c18f5e3e7902e629f5f6d684f9e7c32e85e3ddf0 AS vanir-sandbox
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates tini && \
rm -rf /var/lib/apt/lists/* && \
find / -xdev -perm /6000 -exec chmod a-s {} +
COPY --from=vanir-python-deps /app/.venv /app/.venv
ENV PATH="/app/.venv/bin:$PATH"
COPY --from=vanir-sandbox-build /app/vanir_sandbox /usr/local/bin/vanir_sandbox
COPY cmd/vanir_signatures/generate_signatures.py /usr/local/bin/generate_signatures.py
RUN chmod 755 /usr/local/bin/vanir_sandbox /usr/local/bin/generate_signatures.py
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/vanir_sandbox"]

# ========================================================
# Target: Ubuntu Binary Mapper
# ========================================================
Expand Down
Loading