|
| 1 | +#!/bin/bash |
| 2 | +#SECURE_API_TOKEN environment variable must be defined |
| 3 | + |
| 4 | +IMAGE=$1 |
| 5 | + |
| 6 | +### Use this block to get JSON output in output.json, as well as "human readable output" |
| 7 | +### Begin - no human readable output execution ### |
| 8 | +docker run -v /var/run/docker.sock:/var/run/docker.sock -e SYSDIG_API_TOKEN=$SECURE_API_TOKEN quay.io/sysdig/secure-inline-scan:2 $IMAGE --format=JSON > output.json |
| 9 | +### End - no human readable output execution ### |
| 10 | + |
| 11 | +### Use this block to get JSON output in output.json, as well as "human readable output" in stdout |
| 12 | +### Begin - add human readable output execution ### |
| 13 | +# CONTAINER_ID=$(docker run -d --entrypoint /bin/cat -ti -v /var/run/docker.sock:/var/run/docker.sock -e SYSDIG_API_TOKEN=$SECURE_API_TOKEN quay.io/sysdig/secure-inline-scan:2) |
| 14 | +# docker exec $CONTAINER_ID mkdir -p /tmp/sysdig-inline-scan/logs/ |
| 15 | +# docker exec $CONTAINER_ID touch /tmp/sysdig-inline-scan/logs/info.log |
| 16 | +# docker exec $CONTAINER_ID tail -f /tmp/sysdig-inline-scan/logs/info.log & |
| 17 | +# docker exec $CONTAINER_ID /sysdig-inline-scan.sh $IMAGE --format=JSON > output.json |
| 18 | +# exit_status=$? |
| 19 | +# sleep 1 |
| 20 | +# docker stop $CONTAINER_ID -t 0 > /dev/null && docker rm $CONTAINER_ID > /dev/null |
| 21 | +### End - add human readable output execution ### |
| 22 | + |
| 23 | +# Check exit status. 0 or 1 is ok to continue (pass or fail policy). Otherwise, report error |
| 24 | + |
| 25 | +exit_status=$? |
| 26 | +if [ $exit_status -gt 1 ]; then |
| 27 | + cat output.json |
| 28 | + exit $exit_status |
| 29 | +fi |
| 30 | + |
| 31 | +echo "Scan finished. Generating reports" |
| 32 | + |
| 33 | +# Create CSV report using mustache |
| 34 | +cat <<EOF | docker run -v $(pwd)/output.json:/output.json --rm -i toolbelt/mustache /output.json - > vulns.csv |
| 35 | +sep=; |
| 36 | +Vuln;Severity;Package;Package_Type;Fix;Url |
| 37 | +{{#vulnsReport.vulnerabilities}} |
| 38 | +{{vuln}};{{severity}};{{package}};{{package_type}};{{fix}};{{url}} |
| 39 | +{{/vulnsReport.vulnerabilities}} |
| 40 | +EOF |
| 41 | + |
| 42 | +echo "vulns.csv generated" |
| 43 | + |
| 44 | +# Create HTML report using mustache |
| 45 | +cat <<EOF | docker run -v $(pwd)/output.json:/output.json --rm -i toolbelt/mustache /output.json - > vulns.html |
| 46 | +<html> |
| 47 | +<head> |
| 48 | + <title>Vuln report</title> |
| 49 | + <style> |
| 50 | + body { |
| 51 | + font-family: Arial, Helvetica, sans-serif; |
| 52 | + } |
| 53 | + table { |
| 54 | + border-collapse: collapse; |
| 55 | + } |
| 56 | + td, th { |
| 57 | + border: 1px solid black; |
| 58 | + padding: 2px; |
| 59 | + } |
| 60 | + </style> |
| 61 | +</head> |
| 62 | +<body> |
| 63 | + <table> |
| 64 | + <thead> |
| 65 | + <tr> |
| 66 | + <th>Vuln</th> |
| 67 | + <th>Severity</th> |
| 68 | + <th>Package</th> |
| 69 | + <th>Package_Type</th> |
| 70 | + <th>Fix</th> |
| 71 | + <th>Url</th> |
| 72 | + </tr> |
| 73 | + </thead> |
| 74 | + <tbody> |
| 75 | +{{#vulnsReport.vulnerabilities}} |
| 76 | + <tr> |
| 77 | + <td>{{vuln}}</td> |
| 78 | + <td>{{severity}}</td> |
| 79 | + <td>{{package}}</td> |
| 80 | + <td>{{package_type}}</td> |
| 81 | + <td>{{fix}}</td> |
| 82 | + <td><a href="{{url}}">{{url}}</a></td> |
| 83 | + </tr> |
| 84 | +{{/vulnsReport.vulnerabilities}} |
| 85 | + </tbody> |
| 86 | + </table> |
| 87 | +</body> |
| 88 | +</html> |
| 89 | +EOF |
| 90 | + |
| 91 | +echo "vulns.html generated" |
0 commit comments