Week Notes 2026.11
Vulnerability Tracking #
Last week I wrote about my exploration of the Vanta API with Clojure. My initial focus was on the management API, but this week I moved on to look at the API for integrations. This allows you to build an integration to send data into Vanta, and my interest was in tracking vulnerabilities detected in our CI/CD pipelines.
Currently we are using three different audit tools depending on the language used by the project:
- pip-audit for Python;
- npm-audit for NodeJS;
- govulncheck for Go.
The audit job runs in the test stage of the pipeline and the pipeline will fail if the audit tool discovers any dependencies with vulnerabilities, so these usually get fixed quite quickly. However, for the purposes of our SOC2 audit, we need to report on when vulnerabilities are discovered and provide proof that the are fixed within the SLA specified in our security policy. To date, I’ve been doing this by using the GitLab API to search for audit pipelines that fail, then find the next pipeline that succeeds. This is quite an inefficient approach as the script needs to list all projects and, for each project, list all pipeline jobs and filter by job name to find the audit jobs.
The Vanta integration API provides two resources for tracking package vulnerabilities:
- Vulnerable Components correspond to the GitLab projects where a vulnerability is detected;
- Package Vulnerabilities are the vulnerabilities found by one of the audit tools.
The only problem with these endpoints is that they are for “state of the world” synchronisation: you have to send data on all the vulnerable components in one request, then follow that with a request that sends data on all the package vulnerabilities (each with a link to the corresponding component). This does not play nicely with CI/CD pipelines that run on a project-by-project basis and are triggered either by changes to the repository or on a cron schedule. So we need some way to aggregate all the audit reports generated by the pipelines on an ongoing basis, then periodically collate that data and send it over to Vanta.
My solution #
All of the audit tools can output JSON data, so it seemed like a good approach
would be simply to save the results to an S3 bucket, with each object having key
/projects/${CI_PROJECT_ID}.json. By creating a versioned bucket, we
automatically get history for each project, and we can optionally configure a
lifecycle rule to delete old versions after, say, one year.
However, I did not want to require every project pipeline to install a client for uploading to S3, and I did not want to give every project global write access to the S3 bucket (where a rogue pipeline could overwrite audit data for other projects).
To solve these issues, I implemented an API Gateway with a single endpoint allowing the pipelines to upload results via a HTTP POST request. This is backed by a Lambda function that simply validates the request and saves the audit data to S3. For authentication, I configured it to use a JWT authorizer:
resource "aws_apigatewayv2_authorizer" "vulntrack" {
name = "gitlab-oidc"
api_id = aws_apigatewayv2_api.vulntrack.id
authorizer_type = "JWT"
identity_sources = ["$request.header.Authorization"]
jwt_configuration {
audience = ["https://vulntrack.example.org"]
issuer = "https://gitlab.com"
}
}
resource "aws_apigatewayv2_route" "audit" {
api_id = aws_apigatewayv2_api.vulntrack.id
route_key = "POST /audit"
target = "integrations/${aws_apigatewayv2_integration.vulntrack.id}"
authorization_type = "JWT"
authorizer_id = aws_apigatewayv2_authorizer.vulntrack.id
}
GitLab has built-in support for OIDC allowing a CI/CD pipeline to retrieve a JWT to authenticate to third-party services. The tokens issued by GitLab include claims for the project id, project path, and namespace, so using a JWT for authentication we can verify that the project belongs to our GitLab group and we can use the project id from the token in the S3 key, knowing that it cannot have been tampered with by the caller.
The API Gateway authorizer takes care of verifying the JWT, so the lambda function handling the API request just receives a JSON data structure that includes the claims from the JWT and the request body containing the audit report.
With the AWS infrastructure in place, the GitLab audit job configuration for a Python project now looks like:
pip-audit:
stage: test
image: public.ecr.aws/sam/build-python3.12
id_tokens:
VULNTRACK:
aud: https://vulntrack.example.org
before_script:
- pip install pip-audit
script:
- >
pip-audit -r requirements.txt -f json
| curl -H "Authorization: Bearer ${VULNTRACK}"
-s -S -d pip-audit -d @- https://vkvjkqv04e.execute-api.us-east-1.amazonaws.com/v1/audit
The missing piece #
We now have the infrastructure in place for collecting vulnerability data, so my next job will be to write a Lambda function that runs on a schedule to collate the data and synchronise it with the state-of-the-world endpoints in Vanta. I’ve already done most of the exploratory work with the API as a proof of concept, so hopefully it won’t take too long to wrap this up.
A Look at Task #
It’s been on my mind for a while to look at Task, which describes itself as:
A fast, cross-platform build tool inspired by Make, designed for modern workflows.
This turned out to be very useful while I was working on the terraform and
Lambda function for vulnerability tracking. My usual workflow for this sort of
thing is to implement a placeholder Lambda function that simply logs its input
and returns a “Not implemented” response and deploy the Lambda function and
associated AWS infrastructure with terraform, then as I iterate on the function
implementation, I build the Lambda payload locally and run aws lambda update-function-code to update the function. Enter Taskfile.yml:
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
dotenv: [.envrc]
vars:
LAMBDA_NAME: vulntrack-api-handler
LAMBDA_VERSION: latest
DEPLOY_BUCKET: lambda-deployment-us-east-1-20251110091520487600000017
DEPLOY_KEY: "{{.LAMBDA_NAME}}/{{.LAMBDA_VERSION}}/function.zip"
tasks:
clean:
desc: "Clean up temporary build files"
cmds:
- rm -rf package function.zip
build-lambda:
desc: "Build the Lambda function zip payload"
cmds:
- mkdir package
- defer: rm -rf package
- pip install --target ./package -r handler/requirements.txt
- cp handler/app.py ./package
- pushd package && zip -r ../function.zip . && popd
sources:
- handler/app.py
- handler/requirements.txt
generates:
- function.zip
upload-lambda:
desc: "Upload lambda zip payload to S3"
deps: [build-lambda]
cmds:
- aws-vault exec "${AWS_PROFILE}" -- aws s3 cp function.zip "s3://{{.DEPLOY_BUCKET}}/{{.DEPLOY_KEY}}"
update-function:
desc: "Update the lambda handler function code"
deps: [upload-lambda]
cmds:
- aws-vault exec "${AWS_PROFILE}" -- aws lambda update-function-code --function-name "{{.LAMBDA_NAME}}" --s3-bucket "{{.DEPLOY_BUCKET}}" --s3-key "{{.DEPLOY_KEY}}"
This takes care of building a zip payload with the handler source code and all its dependencies, uploading this to S3, and updating the function. Now I can run all these steps with a single command:
task update-function
The build-lambda task specifies sources and generates which enables
Task to prevent unnecessary work
if the generated files are up-to-date.
I’m using the dotenv feature to keep environment variables specific to me out
of the Taskfile (at the moment the .envrc just specifies the AWS_PROFILE
environment variable, but in general it might include more sensitive data that
we would not want in version control).
Before I configured JWT authentication for the endpoint, I also had a task for invoking the lambda:
test-invoke:
desc: "Test API invocation"
cmds:
- curl -vv -d "name=test" -d "version=0.1.0" "{{.BASE_URL}}/audit"
vars:
BASE_URL:
sh: tofu output -json | jq -r .base_url.value
This is using another Task feature, dynamic variables, to define the
BASE_URL as the output of a shell command that looks up the API Gateway URL in
the tofu output.
I also added some tasks to run the various OpenTofu commands, overriding some terraform variables with values from the Taskfile (so they are only defined in one place):
tofu-init:
desc: "Run Tofu init step"
cmds:
- aws-vault exec "${AWS_PROFILE}" -- tofu init
tofu-validate:
desc: "Run Tofu validation"
deps: [tofu-init]
env:
TF_VAR_api_handler_function: "{{ .LAMBDA_NAME }}"
TF_VAR_api_handler_version: "{{ .LAMBDA_VERSION }}"
cmds:
- tofu fmt -check
- tofu validate
tofu-plan:
desc: "Run Tofu plan step"
deps: [tofu-validate]
env:
TF_VAR_api_handler_function: "{{ .LAMBDA_NAME }}"
TF_VAR_api_handler_version: "{{ .LAMBDA_VERSION }}"
cmds:
- aws-vault exec "${AWS_PROFILE}" -- tofu plan
tofu-apply:
desc: "Run Tofu apply step"
deps: [tofu-validate]
env:
TF_VAR_api_handler_function: "{{ .LAMBDA_NAME }}"
TF_VAR_api_handler_version: "{{ .LAMBDA_VERSION }}"
cmds:
- aws-vault exec "${AWS_PROFILE}" -- tofu apply
Finally, once the Lambda function was working and my test pipeline had reported some output, it was useful to define a couple of tasks for inspecting the output in S3:
list-bucket:
desc: "List vulnerabilities bucket"
cmds:
- aws-vault exec "${AWS_PROFILE}" -- aws s3 ls --recursive s3://{{.BUCKET_NAME}}/
vars:
BUCKET_NAME:
sh: tofu output -json | jq -r .bucket_name.value
get-object:
desc: "Dump an object from the vulnerabilities bucket to STDOUT"
cmds:
- aws-vault exec "${AWS_PROFILE}" -- aws s3 cp s3://{{.BUCKET_NAME}}/{{index .CLI_ARGS_LIST 0}} -
vars:
BUCKET_NAME:
sh: tofu output -json | jq -r .bucket_name.value
The get-object task gets the object key from the command-line arguments. To use this feature, you separate the task name(s) on the command-line from the arguments with --:
task get-object -- projects/80062085.json
The final feature of Task that I’ve been taking advantage of is to list the available tasks, which is handy once you get to my age and start forgetting things:
$ task -l
task: Available tasks for this project:
* build-lambda: Build the Lambda function zip payload
* clean: Clean up temporary build files
* get-object: Dump an object from the vulnerabilities bucket to STDOUT
* list-bucket: List vulnerabilities bucket
* tofu-apply: Run Tofu apply step
* tofu-init: Run Tofu init step
* tofu-plan: Run Tofu plan step
* tofu-validate: Run Tofu validation
* update-function: Update the lambda handler function code
* upload-lambda: Upload lambda zip payload to S3
Listening #
- Daughters of the Empire by Raymond E Feist and Janny Wurts (Audio book)
- Ask the Hosts: Episode 34 (Podcast)
- Darknet Diaries: Melody Fraud (Podcast)
- Hybrid Cloud Show: Episode 51 (Podcast)
- Linux Matters: The Smell of Git (Podcast)
- Linux Dev Time: Episode 145 (Podcast)
- Linux Unplugged: I See Live People (Podcast)
- Late Night Linux: Episode 376 (Podcast)
- Linux After Dark: Episode 117 (Podcast)
- 2.5 Admins: Tired of Tracking (Podcast)