This guide walks you through the steps to connect your AWS pipeline with ZeroThreat using a buildspec.yml file.
Before you begin:
.png)
.png)
Once confirmed, a unique ZT_TOKEN will be generated. This token is used to trigger and authorize scans from your AWS pipeline.
.png)
buildspec.yml to Your ProjectIn your project repository (connected to CodePipeline), add a file named buildspec.yml at the root. This file contains the scan logic that will be executed by AWS CodeBuild.
Use the below buildspec.yml:
version: 0.2
phases:
install:
runtime-versions:
python: 3.11
commands:
- apt-get update && apt-get install -y curl jq
pre_build:
commands:
- |
if [ -z "$ZT_TOKEN" ]; then
echo "ZT_TOKEN input is required but not provided."
exit 1
fi
build:
commands:
- echo "Starting security scan..."
- |
response=$(curl -s -X POST https://api.zerothreat.ai/api/scan/devops \
-H "Content-Type: application/json" \
-d '{"token":"'"${ZT_TOKEN}"'"}')
status=$(echo "$response" | jq -r '.status')
code=$(echo "$response" | jq -r '.code')
message=$(echo "$response" | jq -r '.message')
url=$(echo "$response" | jq -r '.url')
if [ "$status" = "200" ]; then
echo "Scan started successfully."
echo "Scan Report URL: $url"
else
echo "Failed to initiate scan"
echo "Reason: $message"
exit 1
fi
if [ "$WAIT_FOR_ANALYSIS" = "true" ]; then
scanStatus=1
while [ "$scanStatus" -lt 4 ]; do
sleep 300
response=$(curl -s -X GET "https://api.zerothreat.ai/api/scan/devops/$code")
scanStatus=$(echo "$response" | jq -r '.scanStatus')
if [ -z "$scanStatus" ] || [ "$scanStatus" = "null" ]; then
echo "Scan polling failed: invalid status response."
exit 1
fi
if [ "$scanStatus" -ge 4 ]; then
echo "Scan completed successfully."
break
else
echo "Scan still in progress..."
fi
done
fi
artifacts:
files:
- "**/*"
.png)
.png)
.png)
.png)
.png)
.png)
buildspec.yml..png)
ZT_TOKEN – (Paste your token generated in Step 1 in ZeroThreat)WAIT_FOR_ANALYSIS – true or false .png)
.png)
Your AWS pipeline is now integrated with ZeroThreat. Every time your pipeline runs, it will trigger a security scan using the API Collection and target settings you've configured.
You can monitor the scan status and view results in the Scans section of ZeroThreat.