Compare commits

...
10 Commits
Author SHA1 Message Date
Varun Sharma dea7bd51ad Merge pull request #25 from step-security/feature-23
Add service log to post step
2021-11-30 15:30:42 -08:00
Varun Sharma eaf0ca8d14 Print as string 2021-11-30 15:24:00 -08:00
Varun Sharma 11f0d6a28e Get it to write to log 2021-11-30 15:20:16 -08:00
Varun Sharma 9ed69afead Check for the right file 2021-11-30 15:16:42 -08:00
Varun Sharma 1be0435c5f Print service logs on failure 2021-11-30 15:12:30 -08:00
Varun Sharma f4e7a3e5ed Merge pull request #24 from step-security/feature-22
Call API to monitor run
2021-11-30 15:06:03 -08:00
Varun Sharma 40f1350eb7 Use latest agent version 2021-11-30 14:56:56 -08:00
Varun Sharma 4c12219d72 Update setup.ts 2021-11-30 14:24:04 -08:00
Varun Sharma 69f716dfe6 Update setup.ts 2021-11-30 14:22:37 -08:00
Varun Sharma 0a4cdd6afa Call monitor run 2021-11-30 14:16:09 -08:00
8 changed files with 39 additions and 8 deletions
+10
View File
@@ -26,6 +26,8 @@ __nccwpck_require__.r(__webpack_exports__);
;// CONCATENATED MODULE: external "fs"
const external_fs_namespaceObject = require("fs");
;// CONCATENATED MODULE: external "child_process"
const external_child_process_namespaceObject = require("child_process");
;// CONCATENATED MODULE: ./src/cleanup.ts
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -37,6 +39,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
});
};
(() => __awaiter(void 0, void 0, void 0, function* () {
if (process.platform !== "linux") {
console.log("Only runs on linux");
@@ -68,6 +71,13 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
var content = external_fs_namespaceObject.readFileSync(status, "utf-8");
console.log(content);
}
if (!external_fs_namespaceObject.existsSync(doneFile)) {
var journalLog = external_child_process_namespaceObject.execSync("sudo journalctl -u agent.service", {
encoding: "utf8",
});
console.log("Service log:");
console.log(journalLog);
}
}))();
function sleep(ms) {
return new Promise((resolve) => {
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"index.js","sources":["../webpack://step-security-harden-runner/webpack/bootstrap","../webpack://step-security-harden-runner/webpack/runtime/make namespace object","../webpack://step-security-harden-runner/webpack/runtime/compat","../webpack://step-security-harden-runner/external \"fs\"","../webpack://step-security-harden-runner/./src/cleanup.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"fs\");","import * as fs from \"fs\";\n\n(async () => {\n if (process.platform !== \"linux\") {\n console.log(\"Only runs on linux\");\n return;\n }\n\n fs.writeFileSync(\n \"/home/agent/post_event.json\",\n JSON.stringify({ event: \"post\" })\n );\n\n var doneFile = \"/home/agent/done.json\";\n var counter = 0;\n while (true) {\n if (!fs.existsSync(doneFile)) {\n counter++;\n if (counter > 10) {\n console.log(\"timed out\");\n\n break;\n }\n await sleep(1000);\n } // The file *does* exist\n else {\n break;\n }\n }\n\n var log = \"/home/agent/agent.log\";\n console.log(\"log:\");\n var content = fs.readFileSync(log, \"utf-8\");\n console.log(content);\n var status = \"/home/agent/agent.status\";\n if (fs.existsSync(status)) {\n console.log(\"status:\");\n var content = fs.readFileSync(status, \"utf-8\");\n console.log(content);\n }\n})();\n\nfunction sleep(ms) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;AAAA;AACA;AACA;;;;ACFA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACNA;AACA;;;;;;;;ACDA;;;;;;;;;;;ACAA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;;;A","sourceRoot":""}
{"version":3,"file":"index.js","sources":["../webpack://step-security-harden-runner/webpack/bootstrap","../webpack://step-security-harden-runner/webpack/runtime/make namespace object","../webpack://step-security-harden-runner/webpack/runtime/compat","../webpack://step-security-harden-runner/external \"fs\"","../webpack://step-security-harden-runner/external \"child_process\"","../webpack://step-security-harden-runner/./src/cleanup.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","\nif (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + \"/\";","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"fs\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"child_process\");","import * as fs from \"fs\";\nimport * as cp from \"child_process\";\n\n(async () => {\n if (process.platform !== \"linux\") {\n console.log(\"Only runs on linux\");\n return;\n }\n\n fs.writeFileSync(\n \"/home/agent/post_event.json\",\n JSON.stringify({ event: \"post\" })\n );\n\n var doneFile = \"/home/agent/done.json\";\n var counter = 0;\n while (true) {\n if (!fs.existsSync(doneFile)) {\n counter++;\n if (counter > 10) {\n console.log(\"timed out\");\n\n break;\n }\n await sleep(1000);\n } // The file *does* exist\n else {\n break;\n }\n }\n\n var log = \"/home/agent/agent.log\";\n console.log(\"log:\");\n var content = fs.readFileSync(log, \"utf-8\");\n console.log(content);\n var status = \"/home/agent/agent.status\";\n if (fs.existsSync(status)) {\n console.log(\"status:\");\n var content = fs.readFileSync(status, \"utf-8\");\n console.log(content);\n }\n\n if (!fs.existsSync(doneFile)) {\n var journalLog = cp.execSync(\"sudo journalctl -u agent.service\", {\n encoding: \"utf8\",\n });\n console.log(\"Service log:\");\n console.log(journalLog);\n }\n})();\n\nfunction sleep(ms) {\n return new Promise((resolve) => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;AAAA;AACA;AACA;;;;ACFA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACNA;AACA;;;;;;;;ACDA;;ACAA;;;;;;;;;;;ACAA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;;;A","sourceRoot":""}
+6 -1
View File
@@ -6235,6 +6235,8 @@ var core = __nccwpck_require__(2186);
var external_child_process_ = __nccwpck_require__(3129);
// EXTERNAL MODULE: external "fs"
var external_fs_ = __nccwpck_require__(5747);
// EXTERNAL MODULE: ./node_modules/@actions/http-client/index.js
var http_client = __nccwpck_require__(9925);
// EXTERNAL MODULE: external "path"
var external_path_ = __nccwpck_require__(5622);
// EXTERNAL MODULE: ./node_modules/uuid/dist/index.js
@@ -6276,6 +6278,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
(() => __awaiter(void 0, void 0, void 0, function* () {
try {
if (process.platform !== "linux") {
@@ -6286,6 +6289,8 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
var env = "agent";
var api_url = `https://${env}.api.stepsecurity.io/v1`;
var web_url = "https://app.stepsecurity.io";
let _http = new http_client.HttpClient();
yield _http.get(`${api_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}/monitor`);
const confg = {
repo: process.env["GITHUB_REPOSITORY"],
run_id: process.env["GITHUB_RUN_ID"],
@@ -6297,7 +6302,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
const confgStr = JSON.stringify(confg);
external_child_process_.execSync("sudo mkdir -p /home/agent");
external_child_process_.execSync("sudo chown -R $USER /home/agent");
const downloadPath = yield tool_cache.downloadTool("https://github.com/step-security/agent/releases/download/v0.1.5/agent_0.1.5_linux_amd64.tar.gz");
const downloadPath = yield tool_cache.downloadTool("https://github.com/step-security/agent/releases/download/v0.3.0/agent_0.3.0_linux_amd64.tar.gz");
const extractPath = yield tool_cache.extractTar(downloadPath);
console.log(`Step Security Job Correlation ID: ${correlation_id}`);
printInfo(web_url);
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -2
View File
@@ -1,17 +1,18 @@
{
"name": "step-security-harden-runner",
"version": "0.1.0",
"version": "0.3.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "step-security-harden-runner",
"version": "0.1.0",
"version": "0.3.0",
"license": "Apache License 2.0",
"dependencies": {
"@actions/core": "^1.5.0",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.0.0",
"@actions/http-client": "^1.0.11",
"@actions/tool-cache": "^1.7.1",
"node-fetch": "^2.6.1",
"uuid": "^8.3.2"
+2 -1
View File
@@ -1,6 +1,6 @@
{
"name": "step-security-harden-runner",
"version": "0.3.0",
"version": "0.4.0",
"description": "GitHub Actions Runtime Security",
"main": "index.js",
"scripts": {
@@ -25,6 +25,7 @@
"@actions/core": "^1.5.0",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.0.0",
"@actions/http-client": "^1.0.11",
"@actions/tool-cache": "^1.7.1",
"node-fetch": "^2.6.1",
"uuid": "^8.3.2"
+9
View File
@@ -1,4 +1,5 @@
import * as fs from "fs";
import * as cp from "child_process";
(async () => {
if (process.platform !== "linux") {
@@ -38,6 +39,14 @@ import * as fs from "fs";
var content = fs.readFileSync(status, "utf-8");
console.log(content);
}
if (!fs.existsSync(doneFile)) {
var journalLog = cp.execSync("sudo journalctl -u agent.service", {
encoding: "utf8",
});
console.log("Service log:");
console.log(journalLog);
}
})();
function sleep(ms) {
+7 -2
View File
@@ -1,7 +1,7 @@
import * as core from "@actions/core";
import * as cp from "child_process";
import * as fs from "fs";
import * as https from "https";
import * as httpm from "@actions/http-client";
import * as path from "path";
import { v4 as uuidv4 } from "uuid";
import { printInfo } from "./common";
@@ -19,6 +19,11 @@ import * as tc from "@actions/tool-cache";
var api_url = `https://${env}.api.stepsecurity.io/v1`;
var web_url = "https://app.stepsecurity.io";
let _http = new httpm.HttpClient();
await _http.get(
`${api_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}/monitor`
);
const confg = {
repo: process.env["GITHUB_REPOSITORY"],
run_id: process.env["GITHUB_RUN_ID"],
@@ -33,7 +38,7 @@ import * as tc from "@actions/tool-cache";
cp.execSync("sudo chown -R $USER /home/agent");
const downloadPath: string = await tc.downloadTool(
"https://github.com/step-security/agent/releases/download/v0.1.5/agent_0.1.5_linux_amd64.tar.gz"
"https://github.com/step-security/agent/releases/download/v0.3.0/agent_0.3.0_linux_amd64.tar.gz"
);
const extractPath = await tc.extractTar(downloadPath);