Public Access
generated from Philipp/template-git
Compare commits
1
Commits
0.0.3
..
e1fd47716e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1fd47716e |
No files matched your search
+18
-42
@@ -7,8 +7,7 @@ inputs:
|
|||||||
required: true
|
required: true
|
||||||
target-image:
|
target-image:
|
||||||
description: Target baseline container image reference (e.g. host/server/gitea:latest)
|
description: Target baseline container image reference (e.g. host/server/gitea:latest)
|
||||||
required: false
|
required: true
|
||||||
default: ''
|
|
||||||
target-branch:
|
target-branch:
|
||||||
description: Target branch name for delta heading (e.g. main)
|
description: Target branch name for delta heading (e.g. main)
|
||||||
required: false
|
required: false
|
||||||
@@ -49,7 +48,7 @@ runs:
|
|||||||
id: vars
|
id: vars
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
TRIVY_VERSION: 0.75.0 # trivy-version
|
TRIVY_VERSION: 0.76.2 # trivy-version
|
||||||
run: |
|
run: |
|
||||||
echo "date=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
|
echo "date=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
|
||||||
echo "version=${TRIVY_VERSION}" >> "$GITHUB_OUTPUT"
|
echo "version=${TRIVY_VERSION}" >> "$GITHUB_OUTPUT"
|
||||||
@@ -166,14 +165,6 @@ runs:
|
|||||||
echo "ℹ️ Strategy: Direct Trivy image scanning enabled (default). Inspects full container rootfs and package databases for maximum fidelity."
|
echo "ℹ️ Strategy: Direct Trivy image scanning enabled (default). Inspects full container rootfs and package databases for maximum fidelity."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
target_available=true
|
|
||||||
if [ -z "${{ inputs.target-image }}" ] || [ "${{ inputs.target-image }}" = "none" ] || [ "${{ inputs.target-image }}" = "null" ]; then
|
|
||||||
target_available=false
|
|
||||||
elif ! docker manifest inspect "${{ inputs.target-image }}" >/dev/null 2>&1; then
|
|
||||||
echo "::warning::Target baseline image '${{ inputs.target-image }}' not found in registry (MANIFEST_UNKNOWN or inaccessible). Falling back to standalone head scan."
|
|
||||||
target_available=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
for platform in "${PLATFORMS[@]}"; do
|
for platform in "${PLATFORMS[@]}"; do
|
||||||
arch_tag=$(echo "$platform" | sed -e 's#^[a-zA-Z0-9_-]*/##' -e 's#/#-#g')
|
arch_tag=$(echo "$platform" | sed -e 's#^[a-zA-Z0-9_-]*/##' -e 's#/#-#g')
|
||||||
|
|
||||||
@@ -195,7 +186,6 @@ runs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Target image extraction & fallback
|
# Target image extraction & fallback
|
||||||
if [ "$target_available" = "true" ]; then
|
|
||||||
if [ "$use_inbuild" = "true" ]; then
|
if [ "$use_inbuild" = "true" ]; then
|
||||||
echo "Attempting extraction of built-in SBOM for target image ($platform)..."
|
echo "Attempting extraction of built-in SBOM for target image ($platform)..."
|
||||||
docker buildx imagetools inspect "${{ inputs.target-image }}" \
|
docker buildx imagetools inspect "${{ inputs.target-image }}" \
|
||||||
@@ -211,7 +201,6 @@ runs:
|
|||||||
fi
|
fi
|
||||||
cleanup_file "sboms/target/sbom-${arch_tag}.spdx.json"
|
cleanup_file "sboms/target/sbom-${arch_tag}.spdx.json"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Fallbacks if no platform-specific SBOMs were extracted (e.g. single-arch image without index)
|
# Fallbacks if no platform-specific SBOMs were extracted (e.g. single-arch image without index)
|
||||||
@@ -232,7 +221,7 @@ runs:
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$target_available" = "true" ] && [ -z "$(find sboms/target -type f -name 'sbom-*.spdx.json' 2>/dev/null)" ]; then
|
if [ -z "$(find sboms/target -type f -name 'sbom-*.spdx.json' 2>/dev/null)" ]; then
|
||||||
if [ "$use_inbuild" = "true" ]; then
|
if [ "$use_inbuild" = "true" ]; then
|
||||||
docker buildx imagetools inspect "${{ inputs.target-image }}" \
|
docker buildx imagetools inspect "${{ inputs.target-image }}" \
|
||||||
--format '{{ json .SBOM.SPDX }}' > sboms/target/sbom-default.spdx.json 2>/dev/null || true
|
--format '{{ json .SBOM.SPDX }}' > sboms/target/sbom-default.spdx.json 2>/dev/null || true
|
||||||
@@ -257,7 +246,7 @@ runs:
|
|||||||
head_sbom_err="No SBOM generated and head image could not be inspected"
|
head_sbom_err="No SBOM generated and head image could not be inspected"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$target_available" = "true" ] && [ ${#target_files[@]} -eq 0 ] && [ -z "$target_sbom_err" ]; then
|
if [ ${#target_files[@]} -eq 0 ] && [ -z "$target_sbom_err" ]; then
|
||||||
target_sbom_err="No SBOM generated and target baseline image could not be inspected"
|
target_sbom_err="No SBOM generated and target baseline image could not be inspected"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -275,9 +264,7 @@ runs:
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$target_available" != "true" ]; then
|
if [ -n "$target_sbom_err" ]; then
|
||||||
echo "TARGET Baseline Image (${{ inputs.target-image }}): ⚠️ NOT AVAILABLE (Registry manifest missing or target empty)"
|
|
||||||
elif [ -n "$target_sbom_err" ]; then
|
|
||||||
echo "TARGET Baseline Image (${{ inputs.target-image }}): ❌ FAILED - $target_sbom_err"
|
echo "TARGET Baseline Image (${{ inputs.target-image }}): ❌ FAILED - $target_sbom_err"
|
||||||
else
|
else
|
||||||
echo "TARGET Baseline Image (${{ inputs.target-image }}): ✅ SUCCESS"
|
echo "TARGET Baseline Image (${{ inputs.target-image }}): ✅ SUCCESS"
|
||||||
@@ -293,7 +280,7 @@ runs:
|
|||||||
echo "::error::Head SBOM extraction failed: $head_sbom_err"
|
echo "::error::Head SBOM extraction failed: $head_sbom_err"
|
||||||
has_sbom_err=true
|
has_sbom_err=true
|
||||||
fi
|
fi
|
||||||
if [ "$target_available" = "true" ] && [ -n "$target_sbom_err" ]; then
|
if [ -n "$target_sbom_err" ]; then
|
||||||
echo "::error::Target baseline SBOM extraction failed: $target_sbom_err"
|
echo "::error::Target baseline SBOM extraction failed: $target_sbom_err"
|
||||||
has_sbom_err=true
|
has_sbom_err=true
|
||||||
fi
|
fi
|
||||||
@@ -429,18 +416,9 @@ runs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. Scan Target SBOMs
|
# 2. Scan Target SBOMs
|
||||||
target_available=true
|
if [ ${#target_sboms[@]} -eq 0 ]; then
|
||||||
if [ -z "${{ inputs.target-image }}" ] || [ "${{ inputs.target-image }}" = "none" ] || [ "${{ inputs.target-image }}" = "null" ]; then
|
|
||||||
target_available=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$target_available" = "false" ] || [ ${#target_sboms[@]} -eq 0 ]; then
|
|
||||||
if [ "$target_available" = "true" ]; then
|
|
||||||
target_ok=false
|
target_ok=false
|
||||||
target_summary+=(" - ⚠️ No baseline SBOM files found (target image manifest unavailable)")
|
target_summary+=(" - ❌ No SBOM files found in sboms/target/")
|
||||||
else
|
|
||||||
target_summary+=(" - ℹ️ Target baseline not specified")
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
for f in "${target_sboms[@]}"; do
|
for f in "${target_sboms[@]}"; do
|
||||||
arch=$(basename "$f" .spdx.json | sed 's/sbom-//')
|
arch=$(basename "$f" .spdx.json | sed 's/sbom-//')
|
||||||
@@ -534,33 +512,31 @@ runs:
|
|||||||
echo "================================================================================"
|
echo "================================================================================"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# 4. Enforce Gating
|
# 4. Enforce Gating: Both must have succeeded with valid reports
|
||||||
has_error=false
|
has_error=false
|
||||||
if [ "$head_ok" != "true" ] || [ "$head_report_count" -eq 0 ]; then
|
if [ "$head_ok" != "true" ] || [ "$head_report_count" -eq 0 ]; then
|
||||||
echo "::error::Head image CVE analysis failed or produced no reports."
|
echo "::error::Head image CVE analysis failed or produced no reports."
|
||||||
has_error=true
|
has_error=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$target_ok" != "true" ] || [ "$target_report_count" -eq 0 ]; then
|
||||||
|
echo "::error::Target baseline CVE analysis failed or produced no reports."
|
||||||
|
has_error=true
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$has_error" = "true" ]; then
|
if [ "$has_error" = "true" ]; then
|
||||||
echo "::error::Aborting analysis: head scan must succeed."
|
echo "::error::Aborting differential analysis: both head and target scans must succeed before diffing."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 5. Run report generation (differential if target available, otherwise standalone summary)
|
# 5. Run multi-arch set-based diff and generate consolidated full summary report
|
||||||
if [ "$target_ok" = "true" ] && [ "$target_report_count" -gt 0 ]; then
|
|
||||||
echo "Both head and target scans succeeded. Computing set-based vulnerability delta..."
|
echo "Both head and target scans succeeded. Computing set-based vulnerability delta..."
|
||||||
target_path="cve-reports/target"
|
|
||||||
else
|
|
||||||
echo "Target baseline report unavailable. Generating standalone full vulnerability report..."
|
|
||||||
target_path="--none"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! node "${{ github.action_path }}/cve-diff.js" \
|
if ! node "${{ github.action_path }}/cve-diff.js" \
|
||||||
"$target_path" \
|
"cve-reports/target" \
|
||||||
"cve-reports/head" \
|
"cve-reports/head" \
|
||||||
"${{ inputs.target-branch }}" \
|
"${{ inputs.target-branch }}" \
|
||||||
"${{ inputs.output-summary }}" > "${{ inputs.output-delta }}"; then
|
"${{ inputs.output-summary }}" > "${{ inputs.output-delta }}"; then
|
||||||
echo "::error::Failed to generate CVE report"
|
echo "::error::Failed to generate CVE differential report"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+4
-18
@@ -344,30 +344,16 @@ function main() {
|
|||||||
const baseName = args[2] || 'main';
|
const baseName = args[2] || 'main';
|
||||||
const summaryOutputPath = args[3];
|
const summaryOutputPath = args[3];
|
||||||
|
|
||||||
|
const baseCves = loadReportsForArg(baseArg);
|
||||||
const branchCves = loadReportsForArg(branchArg);
|
const branchCves = loadReportsForArg(branchArg);
|
||||||
|
|
||||||
|
const output = renderMarkdownDiff(baseCves, branchCves, baseName);
|
||||||
|
console.log(output);
|
||||||
|
|
||||||
if (summaryOutputPath) {
|
if (summaryOutputPath) {
|
||||||
const summaryOutput = renderFullSummary(branchCves);
|
const summaryOutput = renderFullSummary(branchCves);
|
||||||
fs.writeFileSync(summaryOutputPath, summaryOutput, 'utf8');
|
fs.writeFileSync(summaryOutputPath, summaryOutput, 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baseArg === '--none' || baseArg === 'none' || baseArg === '') {
|
|
||||||
// No baseline provided: output full summary as diff report
|
|
||||||
const lines = [
|
|
||||||
`### 🛡️ Vulnerability Report (\`${baseName}\` baseline unavailable)`,
|
|
||||||
'',
|
|
||||||
`> [!NOTE]`,
|
|
||||||
`> Baseline target image for \`${baseName}\` was not found in the registry. Showing all detected vulnerabilities.`,
|
|
||||||
'',
|
|
||||||
];
|
|
||||||
lines.push(renderFullSummary(branchCves).replace(/^### 🛡️ Security Scan Report\n*/, ''));
|
|
||||||
console.log(lines.join('\n'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseCves = loadReportsForArg(baseArg);
|
|
||||||
const output = renderMarkdownDiff(baseCves, branchCves, baseName);
|
|
||||||
console.log(output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
|||||||
@@ -109,15 +109,3 @@ test('formatVulnRow properly formats badge, architecture tag, and escape pipes',
|
|||||||
const rowWithoutArch = formatVulnRow(vuln, allArchs, false);
|
const rowWithoutArch = formatVulnRow(vuln, allArchs, false);
|
||||||
assert.ok(!rowWithoutArch.includes('`amd64`'));
|
assert.ok(!rowWithoutArch.includes('`amd64`'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cve-diff CLI handles --none baseline gracefully and prints full summary', () => {
|
|
||||||
const { execFileSync } = require('node:child_process');
|
|
||||||
const headDir = path.join(FIXTURES_DIR, 'head');
|
|
||||||
const scriptPath = path.join(__dirname, '..', 'cve-diff.js');
|
|
||||||
|
|
||||||
const stdout = execFileSync('node', [scriptPath, '--none', headDir, 'main'], { encoding: 'utf8' });
|
|
||||||
assert.ok(stdout.includes('baseline unavailable'));
|
|
||||||
assert.ok(stdout.includes('Total Vulnerabilities'));
|
|
||||||
assert.ok(stdout.includes('CVE-2023-0002'));
|
|
||||||
assert.ok(stdout.includes('CVE-2023-0003'));
|
|
||||||
});
|
|
||||||
Reference in new issue
Block a user