Skip to content

Commit 71270c2

Browse files
committed
feat(vanir): add vanir-sandbox Cloud Run service and HTTP orchestrator
1 parent 73950c4 commit 71270c2

20 files changed

Lines changed: 2036 additions & 15 deletions

File tree

‎AGENTS.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,21 @@ All Go microservices are compiled using a single, unified multi-target Dockerfil
331331
- 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.
332332

333333
13. **`vanir_signatures`**:
334-
- 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.
334+
- 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` + `GITTER_HOST` commit-pack relay) and local `generate_signatures.py` fallback.
335335

336-
14. **`ubuntubinarymapper`**:
336+
14. **`vanir_sandbox`**:
337+
- 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, read-only unpacked commit packs (`--git-instead-ofs`), optional empty network namespace (`CLONE_NEWNET`), and post-request `kill(-1, SIGKILL)` UID reaping, running with a zero-IAM-role service account and no VPC access.
338+
339+
15. **`ubuntubinarymapper`**:
337340
- Run as a cron job (`go/cmd/ubuntubinarymapper/`).
338341
- 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`).
339342

340-
15. **`tools/` (`reimport-tui`, `repo-allowlist-sync`)**:
343+
16. **`tools/` (`reimport-tui`, `repo-allowlist-sync`)**:
341344
- Developer and operator CLI/TUI utilities under `go/cmd/tools/` that share the main `go/go.mod` module.
342345
- `reimport-tui`: Interactive TUI tool to trigger reimports for selected `SourceRepository` entities in Datastore (`make reimport-tui`). See its [README](go/cmd/tools/reimport-tui/README.md).
343346
- `repo-allowlist-sync`: Synchronizes the repository allowlist YAML files (`repo_allowlist.yaml` for prod, `repo_allowlist_test.yaml` for staging) to `RepoAllowList` entities in Datastore. Runs automatically via Cloud Build when those files change on `master`, so changing per-repo Git enumeration behavior is normally just a YAML PR. See its [README](go/cmd/tools/repo-allowlist-sync/README.md).
344347

345-
15. **Other jobs and utilities**:
348+
17. **Other jobs and utilities**:
346349
- `osv-linter-worker`: Runs the OSV linter over the exported data and writes findings to GCS and Datastore (`ImportFinding`).
347350
- `generatesitemap`: Generates the website sitemaps from exported vulnerability data.
348351
- `recordchecker`: Checks that every `Vulnerability` in Datastore has an up-to-date GCS record.

‎Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ lib-tests: ## Run core Python library tests
1919
./run_tests.sh
2020

2121
vanir-signatures-tests: ## Run Vanir signatures tests
22-
cd go && go test ./internal/vanir/... ./cmd/vanir_signatures/...
22+
cd go && go test ./internal/vanir/... ./cmd/vanir_signatures/... ./cmd/vanir_sandbox/...
23+
python3 -m unittest discover -s go/cmd/vanir_signatures -p '*_test.py'
2324

2425
vulnfeed-tests: ## Run Go vulnfeeds tests
2526
cd vulnfeeds && ./run_tests.sh

‎deployment/build-and-stage.yaml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ steps:
298298
args: ['push', '--all-tags', 'gcr.io/oss-vdb/vanir-signatures']
299299
waitFor: ['build-vanir-signatures', 'cloud-build-queue']
300300

301+
# Build/push vanir-sandbox images to gcr.io/oss-vdb.
302+
- name: gcr.io/cloud-builders/docker
303+
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', '.']
304+
dir: 'go'
305+
id: 'build-vanir-sandbox'
306+
waitFor: ['build-vanir-signatures']
307+
volumes:
308+
- name: 'docker-config'
309+
path: '/root/.docker'
310+
- name: gcr.io/cloud-builders/docker
311+
args: ['push', '--all-tags', 'gcr.io/oss-vdb/vanir-sandbox']
312+
waitFor: ['build-vanir-sandbox', 'cloud-build-queue']
313+
301314
# Build/push cron job images.
302315
- name: gcr.io/cloud-builders/docker
303316
args: ['build', '-t', 'gcr.io/oss-vdb/cron:latest', '-t', 'gcr.io/oss-vdb/cron:$COMMIT_SHA', '.']
@@ -548,6 +561,16 @@ steps:
548561
id: 'deploy-osv-website'
549562
waitFor: ['goose-up']
550563

564+
# Vanir Sandbox
565+
- name: 'gcr.io/cloud-builders/gcloud'
566+
args: ['deploy', 'releases', 'create', 'osv-$SHORT_SHA', '--project=oss-vdb', '--region=us-central1',
567+
'--delivery-pipeline=vanir-sandbox', '--images',
568+
"vanir-sandbox=gcr.io/oss-vdb/vanir-sandbox:$COMMIT_SHA"
569+
]
570+
dir: deployment/clouddeploy/vanir-sandbox
571+
id: 'deploy-vanir-sandbox'
572+
waitFor: ['goose-up']
573+
551574
timeout: 7200s
552575
# Also set in Cloud Build:
553576
serviceAccount: 'projects/oss-vdb/serviceAccounts/deployment@oss-vdb.iam.gserviceaccount.com'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: deploy.cloud.google.com/v1
2+
kind: DeliveryPipeline
3+
metadata:
4+
name: vanir-sandbox
5+
description: Vanir sandbox Cloud Run pipeline
6+
serialPipeline:
7+
stages:
8+
- targetId: staging-vanir-sandbox
9+
profiles: [ staging ]
10+
- targetId: production-vanir-sandbox
11+
profiles: [ prod ]
12+
---
13+
14+
apiVersion: deploy.cloud.google.com/v1
15+
kind: Target
16+
metadata:
17+
name: staging-vanir-sandbox
18+
description: oss-vdb-test vanir-sandbox instance
19+
run:
20+
location: projects/oss-vdb-test/locations/us-west2
21+
executionConfigs:
22+
- usages:
23+
- RENDER
24+
- DEPLOY
25+
serviceAccount: deployment@oss-vdb.iam.gserviceaccount.com
26+
---
27+
28+
apiVersion: deploy.cloud.google.com/v1
29+
kind: Target
30+
metadata:
31+
name: production-vanir-sandbox
32+
description: oss-vdb vanir-sandbox instance
33+
run:
34+
location: projects/oss-vdb/locations/us-west2
35+
executionConfigs:
36+
- usages:
37+
- RENDER
38+
- DEPLOY
39+
serviceAccount: deployment@oss-vdb.iam.gserviceaccount.com
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: serving.knative.dev/v1
2+
kind: Service
3+
metadata:
4+
name: vanir-sandbox
5+
annotations:
6+
run.googleapis.com/ingress: all
7+
spec:
8+
template:
9+
metadata:
10+
annotations:
11+
autoscaling.knative.dev/minScale: '0'
12+
autoscaling.knative.dev/maxScale: '30'
13+
run.googleapis.com/execution-environment: gen2
14+
spec:
15+
serviceAccountName: vanir-sandbox@oss-vdb.iam.gserviceaccount.com
16+
containerConcurrency: 1
17+
timeoutSeconds: 1800
18+
containers:
19+
- image: vanir-sandbox
20+
ports:
21+
- containerPort: 8080
22+
startupProbe:
23+
httpGet:
24+
path: /healthz
25+
livenessProbe:
26+
httpGet:
27+
path: /healthz
28+
resources:
29+
limits:
30+
cpu: '4'
31+
memory: 8Gi
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: serving.knative.dev/v1
2+
kind: Service
3+
metadata:
4+
name: vanir-sandbox
5+
annotations:
6+
run.googleapis.com/ingress: all
7+
spec:
8+
template:
9+
metadata:
10+
annotations:
11+
autoscaling.knative.dev/minScale: '0'
12+
autoscaling.knative.dev/maxScale: '30'
13+
run.googleapis.com/execution-environment: gen2
14+
spec:
15+
serviceAccountName: vanir-sandbox@oss-vdb-test.iam.gserviceaccount.com
16+
containerConcurrency: 1
17+
timeoutSeconds: 1800
18+
containers:
19+
- image: vanir-sandbox
20+
ports:
21+
- containerPort: 8080
22+
startupProbe:
23+
httpGet:
24+
path: /healthz
25+
livenessProbe:
26+
httpGet:
27+
path: /healthz
28+
resources:
29+
limits:
30+
cpu: '4'
31+
memory: 8Gi
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: skaffold/v3
2+
kind: Config
3+
metadata:
4+
name: vanir-sandbox
5+
6+
profiles:
7+
- name: staging
8+
manifests:
9+
rawYaml:
10+
- run-staging.yaml
11+
12+
- name: prod
13+
manifests:
14+
rawYaml:
15+
- run-prod.yaml
16+
17+
deploy:
18+
cloudrun: {}

‎deployment/deploy-prod.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ steps:
4343
args: ['deploy', 'releases', 'promote', '--quiet', '--release=osv-$SHORT_SHA', '--region=us-central1', '--delivery-pipeline=gke-indexer', '--to-target=production-indexer', '--annotations=tag=$TAG_NAME']
4444
- name: gcr.io/cloud-builders/gcloud
4545
args: ['deploy', 'releases', 'promote', '--quiet', '--release=osv-$SHORT_SHA', '--region=us-central1', '--delivery-pipeline=osv-website', '--to-target=production-website', '--annotations=tag=$TAG_NAME']
46+
- name: gcr.io/cloud-builders/gcloud
47+
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']
4648

4749
# Deploy OSS-Fuzz workers
4850
- name: gcr.io/cloud-builders/gcloud
@@ -88,6 +90,8 @@ steps:
8890
args: ['container', 'images', 'add-tag', '--quiet', 'gcr.io/oss-vdb/osv-website:$COMMIT_SHA', 'gcr.io/oss-vdb/osv-website:$TAG_NAME']
8991
- name: gcr.io/cloud-builders/gcloud
9092
args: ['container', 'images', 'add-tag', '--quiet', 'gcr.io/oss-vdb/recoverer:$COMMIT_SHA', 'gcr.io/oss-vdb/recoverer:$TAG_NAME']
93+
- name: gcr.io/cloud-builders/gcloud
94+
args: ['container', 'images', 'add-tag', '--quiet', 'gcr.io/oss-vdb/vanir-sandbox:$COMMIT_SHA', 'gcr.io/oss-vdb/vanir-sandbox:$TAG_NAME']
9195

9296
serviceAccount: 'projects/oss-vdb/serviceAccounts/deployment@oss-vdb.iam.gserviceaccount.com'
9397
options:

‎deployment/terraform/environments/oss-vdb-test/main.tf‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ output "postgres_read_pool_private_ip" {
150150
value = module.osv_api.read_pool_private_ip_address
151151
}
152152

153+
output "vanir_sandbox_uri" {
154+
description = "HTTPS URI of the vanir-sandbox Cloud Run service"
155+
value = module.osv_test.vanir_sandbox_uri
156+
}
157+
153158
variable "deployment_service_account_email" {
154159
type = string
155160
description = "CI/CD deployment service account email."
@@ -162,7 +167,6 @@ variable "terraform_service_account_email" {
162167
default = "terraform-apply@oss-vdb.iam.gserviceaccount.com"
163168
}
164169

165-
166170
terraform {
167171
backend "gcs" {
168172
bucket = "oss-vdb-tf"

‎deployment/terraform/environments/oss-vdb/main.tf‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ output "postgres_read_pool_private_ip" {
228228
value = module.osv_api.read_pool_private_ip_address
229229
}
230230

231+
output "vanir_sandbox_uri" {
232+
description = "HTTPS URI of the vanir-sandbox Cloud Run service"
233+
value = module.osv.vanir_sandbox_uri
234+
}
235+
231236
terraform {
232237
backend "gcs" {
233238
bucket = "oss-vdb-tf"

0 commit comments

Comments
 (0)