Skip to content

Commit 06f8e87

Browse files
authored
Added a script to perform sbom scanning (#1632)
1 parent 9253f8b commit 06f8e87

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

gulpfile.babel.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function humanize(categoryId) {
148148
case "elmah":
149149
return "ELMAH";
150150
case "email":
151-
return "Email";
151+
return "Email";
152152
case "entityframework":
153153
return "Entity Framework";
154154
case "event-tracing":
@@ -239,6 +239,8 @@ function humanize(categoryId) {
239239
return "Redgate";
240240
case "roundhouse":
241241
return "RoundhousE";
242+
case "sbom":
243+
return "SBOM";
242244
case "sharepoint":
243245
return "SharePoint";
244246
case "snowflake":

step-templates/logos/sbom.png

3.17 KB
Loading

step-templates/sbom-scan.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"Id": "a38bfff8-8dde-4dd6-9fd0-c90bb4709d5a",
3+
"Name": "Scan for Vulnerabilities",
4+
"Description": "This step extracts the Docker image, finds any bom.json files, and scans them for vulnerabilities using Trivy.",
5+
"ActionType": "Octopus.Script",
6+
"Version": 1,
7+
"CommunityActionTemplateId": null,
8+
"Packages": [],
9+
"GitDependencies": [],
10+
"Properties": {
11+
"OctopusUseBundledTooling": "False",
12+
"Octopus.Action.Script.ScriptSource": "Inline",
13+
"Octopus.Action.Script.Syntax": "PowerShell",
14+
"Octopus.Action.Script.ScriptBody": "Write-Host \"Pulling Trivy Docker Image\"\nWrite-Host \"##octopus[stdout-verbose]\"\ndocker pull ghcr.io/aquasecurity/trivy\nWrite-Host \"##octopus[stdout-default]\"\n\n$SUCCESS = 0\n\nWrite-Host \"##octopus[stdout-verbose]\"\nGet-ChildItem -Path \".\" | Out-String\nWrite-Host \"##octopus[stdout-default]\"\n\n# Find all bom.json files\n$currentDirectoryName = Split-Path -Path $PWD -Leaf\n$path = \".\"\n\n$bomFiles = Get-ChildItem -Path $path -Filter \"bom.json\" -Recurse -File\n\nif ($bomFiles.Count -eq 0) {\n Write-Host \"No bom.json files found in the current directory.\"\n exit 0\n}\n\nforeach ($file in $bomFiles) {\n Write-Host \"Scanning $($file.FullName)\"\n\n # Delete any existing report file\n if (Test-Path \"$PWD/depscan-bom.json\") {\n Remove-Item \"$PWD/depscan-bom.json\" -Force\n }\n\n # Generate the report, capturing the output\n try {\n $OUTPUT = docker run --rm -v \"$($file.FullName):/input/$($file.Name)\" ghcr.io/aquasecurity/trivy sbom -q \"/input/$($file.Name)\"\n $exitCode = $LASTEXITCODE\n }\n catch {\n $OUTPUT = $_.Exception.Message\n $exitCode = 1\n }\n\n # Run again to generate the JSON output\n docker run --rm -v \"${PWD}:/output\" -v \"$($file.FullName):/input/$($file.Name)\" ghcr.io/aquasecurity/trivy sbom -q -f json -o /output/depscan-bom.json \"/input/$($file.Name)\"\n\n # Octopus Deploy artifact\n New-OctopusArtifact \"$PWD/depscan-bom.json\"\n\n # Parse JSON output to count vulnerabilities\n $jsonContent = Get-Content -Path \"depscan-bom.json\" | ConvertFrom-Json\n $CRITICAL = ($jsonContent.Results | ForEach-Object { $_.Vulnerabilities } | Where-Object { $_.Severity -eq \"CRITICAL\" }).Count\n $HIGH = ($jsonContent.Results | ForEach-Object { $_.Vulnerabilities } | Where-Object { $_.Severity -eq \"HIGH\" }).Count\n\n if (\"#{Octopus.Environment.Name}\" -eq \"Security\") {\n Write-Highlight \"🟥 $CRITICAL critical vulnerabilities\"\n Write-Highlight \"🟧 $HIGH high vulnerabilities\"\n }\n\n # Set success to 1 if exit code is not zero\n if ($exitCode -ne 0) {\n $SUCCESS = 1\n }\n\n # Print the output\n $OUTPUT | ForEach-Object {\n if ($_.Length -gt 0) {\n Write-Host $_\n }\n }\n}\n\n# Cleanup\nfor ($i = 1; $i -le 10; $i++) {\n try {\n if (Test-Path \"bundle\") {\n Set-ItemProperty -Path \"bundle\" -Name IsReadOnly -Value $false -Recurse -ErrorAction SilentlyContinue\n Remove-Item -Path \"bundle\" -Recurse -Force -ErrorAction Stop\n break\n }\n }\n catch {\n Write-Host \"Attempting to clean up files\"\n Start-Sleep -Seconds 1\n }\n}\n\n# Set Octopus variable\nSet-OctopusVariable -Name \"VerificationResult\" -Value $SUCCESS\n\nexit 0"
15+
},
16+
"Parameters": [],
17+
"StepPackageId": "Octopus.Script",
18+
"$Meta": {
19+
"ExportedAt": "2025-11-02T21:42:33.662Z",
20+
"OctopusVersion": "2025.4.6337",
21+
"Type": "ActionTemplate"
22+
},
23+
"LastModifiedBy": "mcasperson",
24+
"Category": "sbom"
25+
}

0 commit comments

Comments
 (0)