Skip to content

Commit 446798f

Browse files
Merge pull request #455 from step-security/rc-12
Release v2.10.0
2 parents 951b485 + f0d3b1e commit 446798f

12 files changed

+251
-144
lines changed

dist/index.js

Lines changed: 5 additions & 1 deletion
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: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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: 117 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.

src/checksum.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,33 @@ import * as core from "@actions/core";
22
import * as crypto from "crypto";
33
import * as fs from "fs";
44

5-
export function verifyChecksum(downloadPath: string, is_tls: boolean) {
5+
const CHECKSUMS = {
6+
tls: {
7+
amd64: "0bd500769646f0a90c0dfe9ac59699d5165bed549a9870c031b861146af337b2", // v1.3.2
8+
arm64: "c2448ac205fd90f46abba31c13cf34c3b997824881502f736315fb08ac0a5a5c",
9+
},
10+
non_tls: {
11+
amd64: "a9f1842e3d7f3d38c143dbe8ffe1948e6c8173cd04da072d9f9d128bb400844a", // v0.13.7
12+
},
13+
};
14+
15+
export function verifyChecksum(
16+
downloadPath: string,
17+
isTLS: boolean,
18+
variant: string
19+
) {
620
const fileBuffer: Buffer = fs.readFileSync(downloadPath);
721
const checksum: string = crypto
822
.createHash("sha256")
923
.update(fileBuffer)
1024
.digest("hex"); // checksum of downloaded file
1125

12-
let expectedChecksum: string =
13-
"a9f1842e3d7f3d38c143dbe8ffe1948e6c8173cd04da072d9f9d128bb400844a"; // checksum for v0.13.7
26+
let expectedChecksum: string = "";
1427

15-
if (is_tls) {
16-
expectedChecksum =
17-
"fa9defcf9e125a62cb29747574d6a07aee4f04153e7bce4a3c7ce29681469e92"; // checksum for tls_agent
28+
if (isTLS) {
29+
expectedChecksum = CHECKSUMS["tls"][variant];
30+
} else {
31+
expectedChecksum = CHECKSUMS["non_tls"][variant];
1832
}
1933

2034
if (checksum !== expectedChecksum) {

src/cleanup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
2727
return;
2828
}
2929

30+
if (process.env.STATE_isTLS === "false" && process.arch === "arm64") {
31+
return;
32+
}
33+
3034
if (
3135
String(process.env.STATE_monitorStatusCode) ===
3236
common.STATUS_HARDEN_RUNNER_UNAVAILABLE

src/common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,7 @@ export const HARDEN_RUNNER_UNAVAILABLE_MESSAGE =
180180
"Sorry, we are currently experiencing issues with the Harden Runner installation process. It is currently unavailable.";
181181

182182
export const ARC_RUNNER_MESSAGE =
183-
"Workflow is currently being executed in ARC based runner";
183+
"Workflow is currently being executed in ARC based runner.";
184+
185+
export const ARM64_RUNNER_MESSAGE =
186+
"ARM runners are not supported in the Harden-Runner community tier.";

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import { STEPSECURITY_WEB_URL } from "./configs";
2323
return;
2424
}
2525

26+
if (process.env.STATE_isTLS === "false" && process.arch === "arm64") {
27+
return;
28+
}
29+
2630
if (
2731
core.getBooleanInput("disable-telemetry") &&
2832
core.getInput("egress-policy") === "block"

src/install-agent.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import * as tc from "@actions/tool-cache";
2+
import * as core from "@actions/core";
3+
import * as cp from "child_process";
4+
import * as path from "path";
5+
import * as fs from "fs";
6+
import { verifyChecksum } from "./checksum";
7+
import { EOL } from "os";
8+
import { ARM64_RUNNER_MESSAGE } from "./common";
9+
10+
export async function installAgent(
11+
isTLS: boolean,
12+
configStr: string
13+
): Promise<boolean> {
14+
// Note: to avoid github rate limiting
15+
const token = core.getInput("token", { required: true });
16+
const auth = `token ${token}`;
17+
18+
const variant = process.arch === "x64" ? "amd64" : "arm64";
19+
20+
let downloadPath: string;
21+
22+
fs.appendFileSync(process.env.GITHUB_STATE, `isTLS=${isTLS}${EOL}`, {
23+
encoding: "utf8",
24+
});
25+
26+
if (isTLS) {
27+
downloadPath = await tc.downloadTool(
28+
`https://packages.stepsecurity.io/github-hosted/harden-runner_1.3.2_linux_${variant}.tar.gz`
29+
);
30+
} else {
31+
if (variant === "arm64") {
32+
console.log(ARM64_RUNNER_MESSAGE);
33+
return false;
34+
}
35+
downloadPath = await tc.downloadTool(
36+
"https://github.com/step-security/agent/releases/download/v0.13.7/agent_0.13.7_linux_amd64.tar.gz",
37+
undefined,
38+
auth
39+
);
40+
}
41+
42+
verifyChecksum(downloadPath, isTLS, variant);
43+
44+
const extractPath = await tc.extractTar(downloadPath);
45+
46+
let cmd = "cp",
47+
args = [path.join(extractPath, "agent"), "/home/agent/agent"];
48+
49+
cp.execFileSync(cmd, args);
50+
51+
cp.execSync("chmod +x /home/agent/agent");
52+
53+
fs.writeFileSync("/home/agent/agent.json", configStr);
54+
55+
cmd = "sudo";
56+
args = [
57+
"cp",
58+
path.join(__dirname, "agent.service"),
59+
"/etc/systemd/system/agent.service",
60+
];
61+
cp.execFileSync(cmd, args);
62+
cp.execSync("sudo systemctl daemon-reload");
63+
cp.execSync("sudo service agent start", { timeout: 15000 });
64+
return true;
65+
}

0 commit comments

Comments
 (0)