Skip to content

Commit db4e493

Browse files
committed
Update inline_scan.sh and include report URL in action output.
1 parent 7ee2ba0 commit db4e493

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This action performs analysis on locally built container image and posts the res
1010

1111
### `sysdig-secure-token`
1212

13-
**Required** API token for Sysdig Scanning auth. Example: `"924c7ddc-4c09-4d22-bd52-2f7db22f3066"`.
13+
**Required** API token for Sysdig Scanning auth. Example: `"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"`.
1414

1515
Directly specifying the API token in the action configuration is not recommended. A better approach is to [store it in GitHub secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets), and reference `${{ secrets.MY_SECRET_NAME }}` instead.
1616

index.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
const core = require('@actions/core');
22
const exec = require('@actions/exec');
3+
const querystring = require("querystring");
34

45
(async () => {
6+
57
try {
8+
69
const image_tag = core.getInput('image-tag', {required: true});
710
const sysdig_secure_token = core.getInput('sysdig-secure-token', {required: true});
811
const sysdig_secure_url = core.getInput('sysdig-secure-url', {required: true});
912
const dockerfile_path = core.getInput('dockerfile-path');
1013
const pull_from_registry = core.getInput('pull-from-registry') == 'true';
14+
15+
let image_id = '';
16+
17+
// Calculate SYSDIG_DIGEST as done in inline_scan.sh
18+
const options = {};
19+
options.silent = true;
20+
options.listeners = {
21+
stdout: (data) => {
22+
image_id += data.toString();
23+
}
24+
};
25+
26+
try {
27+
await exec.exec(`docker inspect --format="{{index .RepoDigests 0}}" ${image_tag}`, [], options);
28+
image_id = "sha256:" + image_id.split(':')[1];
29+
} catch {
30+
// Calculate from the output of docker inspect
31+
image_id = '';
32+
await exec.exec(`bash -c "docker inspect ${image_tag} | sha256sum | awk '{ print $1 }' | tr -d \\"\\n\\""`, [], options);
33+
image_id = "sha256:" + image_id;
34+
}
1135

1236
let cmd = `${__dirname}/inline_scan.sh analyze -s ${sysdig_secure_url} -k ${sysdig_secure_token}`;
1337

@@ -24,9 +48,16 @@ const exec = require('@actions/exec');
2448

2549
cmd += ` ${image_tag}`;
2650

27-
await exec.exec(cmd);
51+
try {
52+
await exec.exec(cmd);
53+
core.info(`Scan was SUCCESS. Check scan results at ${sysdig_secure_url}/#/scanning/scan-results/localbuild%2F${querystring.escape(image_tag)}/${image_id}`);
54+
} catch (error) {
55+
core.setFailed(`Scan FAILED. Check scan results at ${sysdig_secure_url}/#/scanning/scan-results/localbuild%2F${querystring.escape(image_tag)}/${image_id}`);
56+
}
2857

2958
} catch (error) {
3059
core.setFailed(error.message);
3160
}
61+
3262
})();
63+

inline_scan.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ POLICY_BUNDLE="./policy_bundle.json"
2727
TIMEOUT=300
2828
VOLUME_PATH="/tmp/"
2929
# Analyzer option variable defaults
30-
SYSDIG_BASE_SCANNING_URL=''
30+
SYSDIG_BASE_SCANNING_URL="https://secure.sysdig.com"
3131
SYSDIG_SCANNING_URL="http://localhost:9040/api/scanning"
3232
SYSDIG_ANCHORE_URL="http://localhost:9040/api/scanning/v1/anchore"
3333
SYSDIG_ANNOTATIONS="foo=bar"
@@ -55,22 +55,23 @@ cat << EOF
5555
5656
Sysdig Inline Analyzer --
5757
58-
Script for performing analysis on local docker images, utilizing the Sysdig analyzer subsystem.
58+
Script for performing analysis on local container images, utilizing the Sysdig analyzer subsystem.
5959
After image is analyzed, the resulting image archive is sent to a remote Sysdig installation
6060
using the -s <URL> option. This allows inline analysis data to be persisted & utilized for reporting.
6161
6262
Images should be built & tagged locally.
6363
64-
Usage: ${0##*/} analyze -s <SYSDIG_REMOTE_URL> -k <API Token> [ OPTIONS ] <FULL_IMAGE_TAG>
64+
Usage: ${0##*/} analyze -k <API Token> [ OPTIONS ] <FULL_IMAGE_TAG>
6565
66-
-s <TEXT> [required] URL to Sysdig Secure URL (ex: -s 'https://secure-sysdig.com')
6766
-k <TEXT> [required] API token for Sysdig Scanning auth (ex: -k '924c7ddc-4c09-4d22-bd52-2f7db22f3066')
67+
-s <TEXT> [optional] Sysdig Secure URL (ex: -s 'https://secure-sysdig.svc.cluster.local').
68+
If not specified, it will default to Sysdig Secure SaaS URL (https://secure.sysdig.com/).
6869
-a <TEXT> [optional] Add annotations (ex: -a 'key=value,key=value')
6970
-f <PATH> [optional] Path to Dockerfile (ex: -f ./Dockerfile)
7071
-i <TEXT> [optional] Specify image ID used within Sysdig (ex: -i '<64 hex characters>')
7172
-d <PATH> [optional] Specify image digest (ex: -d 'sha256:<64 hex characters>')
7273
-m <PATH> [optional] Path to Docker image manifest (ex: -m ./manifest.json)
73-
-P [optional] Pull docker image from registry
74+
-P [optional] Pull container image from registry
7475
-V [optional] Increase verbosity
7576
7677
EOF
@@ -102,10 +103,10 @@ main() {
102103

103104
get_and_validate_analyzer_options() {
104105
#Parse options
105-
while getopts ':s:k:r:u:p:a:d:f:i:m:t:PgVh' option; do
106+
while getopts ':k:s:r:u:p:a:d:f:i:m:t:PgVh' option; do
106107
case "${option}" in
107-
s ) s_flag=true; SYSDIG_BASE_SCANNING_URL="${OPTARG%%}";;
108108
k ) k_flag=true; SYSDIG_API_TOKEN="${OPTARG}";;
109+
s ) s_flag=true; SYSDIG_BASE_SCANNING_URL="${OPTARG%%}";;
109110
a ) a_flag=true; SYSDIG_ANNOTATIONS="${OPTARG}";;
110111
f ) f_flag=true; DOCKERFILE="${OPTARG}";;
111112
i ) i_flag=true; SYSDIG_IMAGE_ID="${OPTARG}";;
@@ -135,10 +136,6 @@ get_and_validate_analyzer_options() {
135136
printf '\n\t%s\n\n' "ERROR - must specify an image to analyze" >&2
136137
display_usage_analyzer >&2
137138
exit 1
138-
elif [[ ! "${s_flag:-}" ]]; then
139-
printf '\n\t%s\n\n' "ERROR - must provide a Sysdig Secure endpoint" >&2
140-
display_usage_analyzer >&2
141-
exit 1
142139
elif [[ "${s_flag:-}" ]] && [[ ! "${k_flag:-}" ]]; then
143140
printf '\n\t%s\n\n' "ERROR - must provide the Sysdig Secure API token" >&2
144141
display_usage_analyzer >&2
@@ -464,3 +461,4 @@ cleanup() {
464461
}
465462

466463
main "$@"
464+

0 commit comments

Comments
 (0)