Skip to content

Commit 18bf8ad

Browse files
Add step-security insights url in job summary (#227)
1 parent 8a1ef77 commit 18bf8ad

File tree

14 files changed

+3590
-2171
lines changed

14 files changed

+3590
-2171
lines changed

.github/workflows/test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
push:
7+
branches:
8+
- main # to update code coverage
9+
10+
permissions: # added using https://github.com/step-security/secure-workflows
11+
contents: read
12+
concurrency:
13+
group: ${{ github.workflow }}
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Harden Runner
19+
uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5 # v2.0.0
20+
with:
21+
disable-sudo: true
22+
egress-policy: block
23+
allowed-endpoints: >
24+
codecov.io:443
25+
github.com:443
26+
registry.npmjs.org:443
27+
storage.googleapis.com:443
28+
uploader.codecov.io:443
29+
30+
- name: Checkout
31+
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
32+
- name: Install Dependencies
33+
run: npm ci
34+
- name: Run coverage
35+
run: npm test -- --coverage
36+
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0

dist/index.js

Lines changed: 30 additions & 6 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.

dist/post/index.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61006,10 +61006,33 @@ var external_child_process_ = __nccwpck_require__(3129);
6100661006
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
6100761007
var lib_core = __nccwpck_require__(2186);
6100861008
;// CONCATENATED MODULE: ./src/common.ts
61009+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
61010+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
61011+
return new (P || (P = Promise))(function (resolve, reject) {
61012+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
61013+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
61014+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
61015+
step((generator = generator.apply(thisArg, _arguments || [])).next());
61016+
});
61017+
};
61018+
6100961019
function printInfo(web_url) {
6101061020
console.log("\x1b[32m%s\x1b[0m", "View security insights and recommended policy at:");
6101161021
console.log(`${web_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}`);
6101261022
}
61023+
function addSummary() {
61024+
return __awaiter(this, void 0, void 0, function* () {
61025+
if (process.env.STATE_monitorStatusCode === "200") {
61026+
const web_url = "https://app.stepsecurity.io";
61027+
const insights_url = `${web_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}`;
61028+
yield lib_core.summary.addSeparator()
61029+
.addImage("https://github.com/step-security/harden-runner/raw/main/images/banner.png", "StepSecurity Harden-Runner", { width: "200" })
61030+
.addLink("View security insights and recommended policy", insights_url)
61031+
.addSeparator()
61032+
.write();
61033+
}
61034+
});
61035+
}
6101361036
const CONTAINER_MESSAGE = "This job is running in a container. Harden Runner does not run in a container as it needs sudo access to run. This job will not be monitored.";
6101461037
const UBUNTU_MESSAGE = "This job is not running in a GitHub Actions Hosted Runner Ubuntu VM. Harden Runner is only supported on Ubuntu VM. This job will not be monitored.";
6101561038

@@ -61055,7 +61078,7 @@ var auth = __nccwpck_require__(5526);
6105561078
// EXTERNAL MODULE: external "crypto"
6105661079
var external_crypto_ = __nccwpck_require__(6417);
6105761080
;// CONCATENATED MODULE: ./src/cache.ts
61058-
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
61081+
var cache_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
6105961082
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6106061083
return new (P || (P = Promise))(function (resolve, reject) {
6106161084
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -61107,7 +61130,7 @@ function getCacheVersion(paths, compressionMethod) {
6110761130
return crypto.createHash("sha256").update(components.join("|")).digest("hex");
6110861131
}
6110961132
function getCacheEntry(keys, paths, options) {
61110-
return __awaiter(this, void 0, void 0, function* () {
61133+
return cache_awaiter(this, void 0, void 0, function* () {
6111161134
const httpClient = createHttpClient();
6111261135
const version = getCacheVersion(paths, options === null || options === void 0 ? void 0 : options.compressionMethod);
6111361136
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
@@ -61232,6 +61255,12 @@ var cleanup_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _
6123261255
console.log(exception);
6123361256
}
6123461257
}
61258+
try {
61259+
yield addSummary();
61260+
}
61261+
catch (exception) {
61262+
console.log(exception);
61263+
}
6123561264
}))();
6123661265
function sleep(ms) {
6123761266
return new Promise((resolve) => {

dist/post/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.

dist/pre/index.js

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14111,7 +14111,7 @@ var __webpack_exports__ = {};
1411114111
__nccwpck_require__.r(__webpack_exports__);
1411214112

1411314113
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
14114-
var core = __nccwpck_require__(2186);
14114+
var lib_core = __nccwpck_require__(2186);
1411514115
// EXTERNAL MODULE: external "child_process"
1411614116
var external_child_process_ = __nccwpck_require__(3129);
1411714117
// EXTERNAL MODULE: external "fs"
@@ -14135,10 +14135,34 @@ const stringify = dist.stringify;
1413514135
const parse = dist.parse;
1413614136

1413714137
;// CONCATENATED MODULE: ./src/common.ts
14138+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
14139+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14140+
return new (P || (P = Promise))(function (resolve, reject) {
14141+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14142+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14143+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14144+
step((generator = generator.apply(thisArg, _arguments || [])).next());
14145+
});
14146+
};
14147+
1413814148
function printInfo(web_url) {
1413914149
console.log("\x1b[32m%s\x1b[0m", "View security insights and recommended policy at:");
1414014150
console.log(`${web_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}`);
1414114151
}
14152+
function addSummary() {
14153+
return __awaiter(this, void 0, void 0, function* () {
14154+
if (process.env.STATE_monitorStatusCode === "200") {
14155+
const web_url = "https://app.stepsecurity.io";
14156+
const insights_url = `${web_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}`;
14157+
yield core.summary
14158+
.addSeparator()
14159+
.addImage("https://github.com/step-security/harden-runner/raw/main/images/banner.png", "StepSecurity Harden-Runner", { width: "200" })
14160+
.addLink("View security insights and recommended policy", insights_url)
14161+
.addSeparator()
14162+
.write();
14163+
}
14164+
});
14165+
}
1414214166
const CONTAINER_MESSAGE = "This job is running in a container. Harden Runner does not run in a container as it needs sudo access to run. This job will not be monitored.";
1414314167
const UBUNTU_MESSAGE = "This job is not running in a GitHub Actions Hosted Runner Ubuntu VM. Harden Runner is only supported on Ubuntu VM. This job will not be monitored.";
1414414168

@@ -14157,9 +14181,9 @@ function verifyChecksum(downloadPath) {
1415714181
.digest("hex"); // checksum of downloaded file
1415814182
const expectedChecksum = "79f397360470d6e42c73d6c9c5cf485ac9982e56e3e3fdd07f66c59cda4388c8"; // checksum for v0.12.1
1415914183
if (checksum !== expectedChecksum) {
14160-
core.setFailed(`Checksum verification failed, expected ${expectedChecksum} instead got ${checksum}`);
14184+
lib_core.setFailed(`Checksum verification failed, expected ${expectedChecksum} instead got ${checksum}`);
1416114185
}
14162-
core.debug("Checksum verification passed.");
14186+
lib_core.debug("Checksum verification passed.");
1416314187
}
1416414188

1416514189
;// CONCATENATED MODULE: external "node:fs"
@@ -14197,10 +14221,12 @@ function isDocker() {
1419714221

1419814222
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
1419914223
var github = __nccwpck_require__(5438);
14224+
// EXTERNAL MODULE: external "os"
14225+
var external_os_ = __nccwpck_require__(2087);
1420014226
// EXTERNAL MODULE: ./node_modules/@actions/http-client/lib/auth.js
1420114227
var auth = __nccwpck_require__(5526);
1420214228
;// CONCATENATED MODULE: ./src/cache.ts
14203-
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
14229+
var cache_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
1420414230
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1420514231
return new (P || (P = Promise))(function (resolve, reject) {
1420614232
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -14222,7 +14248,7 @@ function getCacheApiUrl(resource) {
1422214248
throw new Error("Cache Service Url not found, unable to restore cache.");
1422314249
}
1422414250
const url = `${baseUrl}_apis/artifactcache/${resource}`;
14225-
core.debug(`Resource Url: ${url}`);
14251+
lib_core.debug(`Resource Url: ${url}`);
1422614252
return url;
1422714253
}
1422814254
function createAcceptHeader(type, apiVersion) {
@@ -14252,7 +14278,7 @@ function getCacheVersion(paths, compressionMethod) {
1425214278
return external_crypto_.createHash("sha256").update(components.join("|")).digest("hex");
1425314279
}
1425414280
function getCacheEntry(keys, paths, options) {
14255-
return __awaiter(this, void 0, void 0, function* () {
14281+
return cache_awaiter(this, void 0, void 0, function* () {
1425614282
const httpClient = createHttpClient();
1425714283
const version = getCacheVersion(paths, options === null || options === void 0 ? void 0 : options.compressionMethod);
1425814284
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
@@ -14313,6 +14339,7 @@ var setup_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _ar
1431314339

1431414340

1431514341

14342+
1431614343
(() => setup_awaiter(void 0, void 0, void 0, function* () {
1431714344
try {
1431814345
if (process.platform !== "linux") {
@@ -14334,11 +14361,11 @@ var setup_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _ar
1433414361
correlation_id: correlation_id,
1433514362
working_directory: process.env["GITHUB_WORKSPACE"],
1433614363
api_url: api_url,
14337-
allowed_endpoints: core.getInput("allowed-endpoints"),
14338-
egress_policy: core.getInput("egress-policy"),
14339-
disable_telemetry: core.getBooleanInput("disable-telemetry"),
14340-
disable_sudo: core.getBooleanInput("disable-sudo"),
14341-
disable_file_monitoring: core.getBooleanInput("disable-file-monitoring"),
14364+
allowed_endpoints: lib_core.getInput("allowed-endpoints"),
14365+
egress_policy: lib_core.getInput("egress-policy"),
14366+
disable_telemetry: lib_core.getBooleanInput("disable-telemetry"),
14367+
disable_sudo: lib_core.getBooleanInput("disable-sudo"),
14368+
disable_file_monitoring: lib_core.getBooleanInput("disable-file-monitoring"),
1434214369
private: github.context.payload.repository.private,
1434314370
};
1434414371
if (isValidEvent()) {
@@ -14347,32 +14374,37 @@ var setup_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _ar
1434714374
compressionMethod: CompressionMethod.ZstdWithoutLong,
1434814375
});
1434914376
const url = new URL(cacheEntry.archiveLocation);
14350-
core.info(`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`);
14377+
lib_core.info(`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`);
1435114378
confg.allowed_endpoints += ` ${url.hostname}:443`;
1435214379
}
1435314380
catch (exception) {
1435414381
// some exception has occurred.
14355-
core.info("Unable to fetch cacheURL");
14382+
lib_core.info("Unable to fetch cacheURL");
1435614383
if (confg.egress_policy === "block") {
14357-
core.info("Switching egress-policy to audit mode");
14384+
lib_core.info("Switching egress-policy to audit mode");
1435814385
confg.egress_policy = "audit";
1435914386
}
1436014387
}
1436114388
}
1436214389
if (confg.egress_policy !== "audit" && confg.egress_policy !== "block") {
14363-
core.setFailed("egress-policy must be either audit or block");
14390+
lib_core.setFailed("egress-policy must be either audit or block");
1436414391
}
1436514392
if (confg.egress_policy === "block" && confg.allowed_endpoints === "") {
14366-
core.warning("egress-policy is set to block (default) and allowed-endpoints is empty. No outbound traffic will be allowed for job steps.");
14393+
lib_core.warning("egress-policy is set to block (default) and allowed-endpoints is empty. No outbound traffic will be allowed for job steps.");
1436714394
}
1436814395
if (confg.disable_telemetry !== true && confg.disable_telemetry !== false) {
14369-
core.setFailed("disable-telemetry must be a boolean value");
14396+
lib_core.setFailed("disable-telemetry must be a boolean value");
1437014397
}
1437114398
if (!confg.disable_telemetry) {
1437214399
let _http = new lib.HttpClient();
1437314400
_http.requestOptions = { socketTimeout: 3 * 1000 };
1437414401
try {
14375-
yield _http.get(`${api_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}/monitor`);
14402+
const resp = yield _http.get(`${api_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}/monitor`);
14403+
if (resp.message.statusCode === 200) {
14404+
external_fs_.appendFileSync(process.env.GITHUB_STATE, `monitorStatusCode=${resp.message.statusCode}${external_os_.EOL}`, {
14405+
encoding: "utf8",
14406+
});
14407+
}
1437614408
}
1437714409
catch (e) {
1437814410
console.log(`error in connecting to ${api_url}: ${e}`);
@@ -14382,7 +14414,7 @@ var setup_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _ar
1438214414
external_child_process_.execSync("sudo mkdir -p /home/agent");
1438314415
external_child_process_.execSync("sudo chown -R $USER /home/agent");
1438414416
// Note: to avoid github rate limiting
14385-
let token = core.getInput("token");
14417+
let token = lib_core.getInput("token");
1438614418
let auth = `token ${token}`;
1438714419
const downloadPath = yield tool_cache.downloadTool("https://github.com/step-security/agent/releases/download/v0.12.1/agent_0.12.1_linux_amd64.tar.gz", undefined, auth);
1438814420
verifyChecksum(downloadPath); // NOTE: verifying agent's checksum, before extracting
@@ -14429,7 +14461,7 @@ var setup_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _ar
1442914461
}
1443014462
}
1443114463
catch (error) {
14432-
core.setFailed(error.message);
14464+
lib_core.setFailed(error.message);
1443314465
}
1443414466
}))();
1443514467
function sleep(ms) {

dist/pre/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.

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

0 commit comments

Comments
 (0)