Skip to content

Commit f9d15fa

Browse files
authored
Fix inline scan 2.3 output (#9)
* fix: change log path to fix output in inline-scan:2.3 * fix: run as same UID to prevent permission issues * fix: add conclusion to the run check
1 parent f0d777d commit f9d15fa

File tree

6 files changed

+32
-16
lines changed

6 files changed

+32
-16
lines changed

.github/workflows/scan.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: Scan Image
22

33
on:
4-
push:
54
workflow_dispatch:
65

76
jobs:

dist/index.js

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function printOptions(opts) {
6868
}
6969

7070
function composeFlags(opts) {
71-
let dockerFlags = `--rm -v ${process.cwd()}/scan-output:/tmp/sysdig-inline-scan`;
71+
let dockerFlags = `--rm -v ${process.cwd()}/scan-output:/tmp/logs -e LOGS_DIR=/tmp/logs`;
7272
let runFlags = `--sysdig-token=${opts.sysdigSecureToken || ""} --format=JSON`;
7373

7474
if (opts.sysdigSecureURL) {
@@ -95,6 +95,8 @@ function composeFlags(opts) {
9595

9696
if (opts.runAsUser) {
9797
dockerFlags += ` -u ${opts.runAsUser}`;
98+
} else {
99+
dockerFlags += ` -u ${process.getuid()}`
98100
}
99101

100102
if (opts.sysdigSkipTLS) {
@@ -166,8 +168,10 @@ async function processScanResult(result) {
166168
try {
167169
report = JSON.parse(result.Output);
168170
} catch (error) {
169-
core.error("Error parsing analysis JSON report: " + error);
171+
core.error("Error parsing analysis JSON report: " + error + ". Output was: " + result.output);
172+
throw new ExecutionError(result.Output, result.Error);
170173
}
174+
171175
if (report) {
172176

173177
let vulnerabilities = [];
@@ -208,9 +212,7 @@ async function executeInlineScan(scanImage, dockerFlags, runFlags) {
208212
let errOutput = '';
209213

210214
fs.mkdirSync("./scan-output", { recursive: true });
211-
fs.chmodSync("./scan-output", 0o777);
212215
fs.closeSync(fs.openSync("./scan-output/info.log", 'w'));
213-
fs.chmodSync("./scan-output/info.log", 0o666);
214216
let tail = new Tail("./scan-output/info.log", { fromBeginning: true, follow: true });
215217
tail.on("line", function (data) {
216218
console.log(data);
@@ -401,12 +403,19 @@ async function generateChecks(scanResult, evaluationResults, vulnerabilities) {
401403
return;
402404
}
403405

406+
let conclusion = "success";
407+
if (scanResult != "Success") {
408+
conclusion = "failure";
409+
}
410+
404411
try {
405412
check_run = await octokit.checks.create({
406413
owner: github.context.repo.owner,
407414
repo: github.context.repo.repo,
408415
name: "Scan results",
409416
head_sha: github.context.sha,
417+
status: "completed",
418+
conclusion: conclusion,
410419
output: {
411420
title: "Inline scan results",
412421
summary: "Scan result is " + scanResult,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "secure-inline-scan-action",
3-
"version": "3.0.0",
3+
"version": "3.0.2",
44
"description": "This actions performs image analysis on locally built container image and posts the result of the analysis to Sysdig Secure.",
55
"main": "index.js",
66
"scripts": {

tests/index.test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe("docker flags", () => {
104104
it("uses default docker flags", () => {
105105
let flags = index.composeFlags({});
106106
expect(flags.dockerFlags).toMatch(/(^| )--rm($| )/)
107-
expect(flags.dockerFlags).toMatch(new RegExp(`(^| )-v ${process.cwd()}/scan-output:/tmp/sysdig-inline-scan($| )`));
107+
expect(flags.dockerFlags).toMatch(new RegExp(`(^| )-v ${process.cwd()}/scan-output:/tmp/logs($| )`));
108108
})
109109

110110
it("mounts the input file", () => {
@@ -304,7 +304,7 @@ describe("process scan results", () => {
304304
Output: "Some output",
305305
Error: "Some error"
306306
};
307-
return expect(index.processScanResult(scanResult)).rejects.toThrow(new index.ExecutionError('Some output', "Some error"));
307+
return expect(index.processScanResult(scanResult)).rejects.toThrow(new index.ExecutionError('Some output', 'Some error'));
308308
})
309309

310310
it("handles error on invalid JSON", async () => {
@@ -316,8 +316,7 @@ describe("process scan results", () => {
316316
Error: ""
317317
};
318318

319-
let success = await index.processScanResult(scanResult);
320-
expect(success).toBe(true);
319+
await expect(index.processScanResult(scanResult)).rejects.toThrow(new index.ExecutionError('invalid JSON', ''));
321320
expect(core.error).toBeCalledTimes(1);
322321
expect(core.error.mock.calls[0][0]).toMatch(/Error parsing analysis JSON report/)
323322
})
@@ -449,7 +448,7 @@ describe("process scan results", () => {
449448
})
450449

451450
xit("generates SARIF report with gates", async () => {
452-
451+
//TODO: Gates are not included in SARIF report
453452
})
454453
})
455454

0 commit comments

Comments
 (0)