Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ff48025a8 | ||
|
|
6ddaf38701 | ||
|
|
6b1c98f1d2 | ||
|
|
0b4d9af9ef | ||
|
|
4dd31d13de | ||
|
|
8a6170d7ba | ||
|
|
a6f64cd1a2 | ||
|
|
3559266854 | ||
|
|
20cf305ff2 | ||
|
|
c51e8eeb6c | ||
|
|
e152b90204 | ||
|
|
ee1faec052 | ||
|
|
1dc7c17646 | ||
|
|
df199fb7be | ||
|
|
03d096a772 | ||
|
|
40901073af | ||
|
|
95d9a5deda | ||
|
|
87e429d3fb | ||
|
|
ef891c3a30 | ||
|
|
1fa8c8a8b1 | ||
|
|
92c522aaa6 | ||
|
|
4719ad5578 | ||
|
|
4fde639ab4 | ||
|
|
f682f2f2d0 | ||
|
|
f4a75cfd61 | ||
|
|
95503d076c | ||
|
|
4b250a0739 | ||
|
|
5b0ab6abcf | ||
|
|
d11f2c1d65 | ||
|
|
b3fc98e4df | ||
|
|
92fc5d4bf7 | ||
|
|
b61b0a4938 | ||
|
|
e3d3f2baea | ||
|
|
646ac01e72 | ||
|
|
7bc18df383 | ||
|
|
17d38b322b | ||
|
|
ec9f2d5744 | ||
|
|
04bcbc31cf | ||
|
|
7c7a56fcaa | ||
|
|
6c439dc8bd | ||
|
|
bf5688696d | ||
|
|
5436dac7b5 | ||
|
|
88d305a353 | ||
|
|
b976878278 | ||
|
|
875cc92db2 | ||
|
|
002fdce3c6 | ||
|
|
2489e3fcb3 | ||
|
|
75dd441a81 | ||
|
|
4381ace9c4 | ||
|
|
a9da90b635 | ||
|
|
a60ef21c0c | ||
|
|
4ad512f165 | ||
|
|
6b41a39235 | ||
|
|
fa70c45ca9 | ||
|
|
eb47845632 | ||
|
|
1705d777e5 | ||
|
|
62893838e7 | ||
|
|
42a3378d67 | ||
|
|
f0cb479b0f | ||
|
|
9abfa72990 | ||
|
|
4379a81ea6 | ||
|
|
5a5cdce402 | ||
|
|
1106c3d7dd | ||
|
|
0634a2670c | ||
|
|
2e3c511341 | ||
|
|
40873e6a41 | ||
|
|
484c2799ec | ||
|
|
4c8582f455 | ||
|
|
e8d595cd66 | ||
|
|
5d277fc873 | ||
|
|
ff2ab228bd | ||
|
|
b81d650d0e | ||
|
|
769df4ef5d | ||
|
|
a7a8a29fbc | ||
|
|
75fd6ee0fe | ||
|
|
86338660c4 | ||
|
|
230ee49196 | ||
|
|
617de1d11d | ||
|
|
d930a8a3b2 | ||
|
|
c6295a65d1 | ||
|
|
3e118b145b | ||
|
|
b38e918ba8 | ||
|
|
0664d30cda | ||
|
|
b131ca5ebf | ||
|
|
2dc9579753 | ||
|
|
f054d811b5 | ||
|
|
8a09271fed | ||
|
|
6ec6af7d62 | ||
|
|
539365ba33 | ||
|
|
e34e1ce869 | ||
|
|
4cfb9f26cc | ||
|
|
8b7e2a634c | ||
|
|
18fe9c66a7 | ||
|
|
bb31c5e3c0 | ||
|
|
bf5f99ab75 | ||
|
|
db60402296 | ||
|
|
41d3351872 | ||
|
|
27a99dbdfc | ||
|
|
0f3c98aa98 | ||
|
|
e8e3270940 | ||
|
|
a22641e386 | ||
|
|
8e17ea0862 | ||
|
|
4d991eb9b9 | ||
|
|
4ea872f897 | ||
|
|
65d6f6e4ee | ||
|
|
1034c9a805 | ||
|
|
ab221e2d7a | ||
|
|
7cb6c2fb52 | ||
|
|
cb605e52c2 | ||
|
|
61144dda3b | ||
|
|
b8be370ff4 | ||
|
|
6f6fa07e47 | ||
|
|
18f6947f13 | ||
|
|
81f844e743 | ||
|
|
4c766de2db | ||
|
|
c9c5f3273c | ||
|
|
2877824267 | ||
|
|
be87de076d | ||
|
|
2c885d7777 | ||
|
|
5cd8ab01b8 | ||
|
|
ed991e9352 | ||
|
|
c991186dd8 | ||
|
|
53cb01d530 | ||
|
|
196e3d0af0 | ||
|
|
bb2cfd011b | ||
|
|
7aaa42ceb4 | ||
|
|
0fc7228fde | ||
|
|
74f74a93dc | ||
|
|
3f2b8c3974 | ||
|
|
d77cef7a9d | ||
|
|
b893624186 | ||
|
|
9a7e935bf2 | ||
|
|
825fc30a5e | ||
|
|
c95a14d0e5 | ||
|
|
b78ba6a1b7 | ||
|
|
0080882f6c | ||
|
|
4a3a88bbf8 | ||
|
|
556aae632a | ||
|
|
6c39b84661 | ||
|
|
40401cf618 | ||
|
|
806ab1cccb | ||
|
|
28468118cd | ||
|
|
df8a07c171 | ||
|
|
30636fb583 | ||
|
|
91182cccc0 | ||
|
|
59ec1c6341 | ||
|
|
1d2370362e | ||
|
|
b03bddaa05 | ||
|
|
3d8dd68e57 | ||
|
|
446798f821 | ||
|
|
f0d3b1eb1b | ||
|
|
b7880a2f96 | ||
|
|
dade49eade | ||
|
|
d6248bed80 | ||
|
|
4330132d7e | ||
|
|
247a5c6fb1 | ||
|
|
782d84337f | ||
|
|
f5f18f8c5e | ||
|
|
3325870bea | ||
|
|
951b48540b | ||
|
|
49711f22fe | ||
|
|
5c7944e73c | ||
|
|
c79be451ee | ||
|
|
deb3383c4d | ||
|
|
23c8215e78 | ||
|
|
727d06a16d | ||
|
|
f0db2aa8a5 | ||
|
|
1938ffc008 | ||
|
|
8e7dd2c82b | ||
|
|
f2823ee7dd | ||
|
|
5f95e051ab | ||
|
|
0fe20c9a7d | ||
|
|
89c04c1cae | ||
|
|
d7cf128fba | ||
|
|
657cae2a4a | ||
|
|
0d381219dd | ||
|
|
29e9ae1229 | ||
|
|
9d596cfe4e | ||
|
|
6d3c2fe731 | ||
|
|
c2e63d350e | ||
|
|
547a5cc003 | ||
|
|
a5e1dca4fb | ||
|
|
3d32f8d8b2 | ||
|
|
891104cb4f | ||
|
|
17d0e2bd7d | ||
|
|
bb112d061b | ||
|
|
f4f3f445f3 | ||
|
|
7a946b57df | ||
|
|
75a01c2f00 | ||
|
|
53413f1a91 | ||
|
|
f086349bfa | ||
|
|
b9c325d8ce | ||
|
|
808a771f66 | ||
|
|
71714298b4 | ||
|
|
9ff9d14760 | ||
|
|
ac5fa0194e | ||
|
|
a4aa98b93c | ||
|
|
6c3b1c91e8 | ||
|
|
3498091f2b | ||
|
|
63a88e2cd7 | ||
|
|
07e5965e5b | ||
|
|
63c24ba6bd | ||
|
|
95691d3d1c | ||
|
|
6339621ce7 | ||
|
|
4a63cdab74 | ||
|
|
dece11172e | ||
|
|
1952f97070 | ||
|
|
32f00ffb1b | ||
|
|
ea8b747819 | ||
|
|
c0db65e1f6 | ||
|
|
4151c053ff | ||
|
|
c7832c5b85 | ||
|
|
c2443b23ee | ||
|
|
c7b5834cda | ||
|
|
eb238b55ef | ||
|
|
4b019e4301 | ||
|
|
2579b52abd | ||
|
|
c11b220564 | ||
|
|
3338abcc5a | ||
|
|
7523e86b7f | ||
|
|
bf4cac97a4 | ||
|
|
ab35e30883 | ||
|
|
02adcd6bfd | ||
|
|
cddb4d278e | ||
|
|
d7f96b7d4b | ||
|
|
092182fa67 | ||
|
|
1b05615854 | ||
|
|
398bb08048 | ||
|
|
0c6ab70129 | ||
|
|
e8c0b523ee | ||
|
|
3f86cc657b | ||
|
|
4a1e83c9ef | ||
|
|
10e0a2266a | ||
|
|
20779e73c4 | ||
|
|
ad05d1bc90 | ||
|
|
1223983f63 | ||
|
|
80b2fcb96a | ||
|
|
8e4e6d10a3 | ||
|
|
394d78e5b4 | ||
|
|
9579194548 | ||
|
|
0327a39356 | ||
|
|
241b85deb4 | ||
|
|
8ca2b8b2ec | ||
|
|
97689868c8 | ||
|
|
4735c31e98 | ||
|
|
2bd96dc857 | ||
|
|
781663beab | ||
|
|
cba0d00b1f | ||
|
|
aa817ef351 | ||
|
|
75ac55456f | ||
|
|
df76f095bf | ||
|
|
1d7cff8f22 | ||
|
|
1931def3f2 | ||
|
|
eba91136ef | ||
|
|
28a46cf742 | ||
|
|
532ef4a868 | ||
|
|
9973777dd4 | ||
|
|
7120a7ab6b | ||
|
|
d33e9c0321 | ||
|
|
55d479fb1c | ||
|
|
215c5ca5ec | ||
|
|
95a625ab96 | ||
|
|
7d83e8ed97 | ||
|
|
36ccae2f5b | ||
|
|
beefd8c500 | ||
|
|
bb523fd3f4 | ||
|
|
760976e8ee | ||
|
|
f70248679d | ||
|
|
1f715fe03d | ||
|
|
39fa126de8 | ||
|
|
1226c5f95a | ||
|
|
6e98209e69 | ||
|
|
a18fe9b696 | ||
|
|
10805cec00 | ||
|
|
7f6b548c36 | ||
|
|
678f9f50e5 | ||
|
|
128a63446a | ||
|
|
6dacdfc16c | ||
|
|
50ba86cd8e | ||
|
|
b4ed311ff3 | ||
|
|
5d5d34225d | ||
|
|
bb3ffe7c11 | ||
|
|
f4a62b32a7 | ||
|
|
0dcc8e68fd | ||
|
|
6b3083af28 | ||
|
|
daacdded59 | ||
|
|
012ac92c8d | ||
|
|
910b3276b2 | ||
|
|
5f67082df6 | ||
|
|
b3e3003dba | ||
|
|
5aebf4789e | ||
|
|
d81767b1cc | ||
|
|
61a6a28e1e | ||
|
|
f8b2294872 | ||
|
|
3693a6b26d | ||
|
|
49e89a7fe2 | ||
|
|
3f4805a4db | ||
|
|
03bee39306 | ||
|
|
345cb260f4 | ||
|
|
f6ad5edba8 | ||
|
|
8e0b415352 | ||
|
|
ef5e932006 | ||
|
|
40a26682a9 | ||
|
|
1d9871f0c5 | ||
|
|
4e302edd5f | ||
|
|
25084337c4 | ||
|
|
1f99358870 | ||
|
|
cbe5226399 | ||
|
|
c0b3d8bd46 | ||
|
|
d3561ded9e | ||
|
|
6c61cb4fea | ||
|
|
c6b96bbfd6 | ||
|
|
c8454efe5d | ||
|
|
1a5f3ff627 | ||
|
|
8f144f8401 | ||
|
|
5dfad97a98 | ||
|
|
b696244f12 | ||
|
|
10aedff7e5 | ||
|
|
4660e36515 | ||
|
|
6dc7d6afef | ||
|
|
6519f4ce27 | ||
|
|
ce7687506a |
@@ -0,0 +1,33 @@
|
||||
module.exports = {
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"files": [
|
||||
".eslintrc.{js,cjs}"
|
||||
],
|
||||
"parserOptions": {
|
||||
"sourceType": "script"
|
||||
}
|
||||
}
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,14 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5 # v1
|
||||
- uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
egress-policy: audit
|
||||
allowed-endpoints:
|
||||
api.github.com:443
|
||||
github.com:443
|
||||
|
||||
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v2
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v2
|
||||
- name: Update the rc tag
|
||||
uses: step-security/publish-action@b438f840875fdcb7d1de4fc3d1d30e86cf6acb5d
|
||||
with:
|
||||
@@ -40,3 +41,9 @@ jobs:
|
||||
env:
|
||||
PAT: ${{ secrets.PAT }}
|
||||
canary: true
|
||||
|
||||
- name: Canary TLS test
|
||||
uses: docker://ghcr.io/step-security/integration-test/int:latest
|
||||
env:
|
||||
PAT: ${{ secrets.PAT }}
|
||||
canary-tls: true
|
||||
|
||||
@@ -41,16 +41,16 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@959cbb7472c4d4ad70cdfe6f4976053fe48ab394
|
||||
uses: github/codeql-action/init@2d790406f505036ef40ecba973cc774a50395aac
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -61,7 +61,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@959cbb7472c4d4ad70cdfe6f4976053fe48ab394
|
||||
uses: github/codeql-action/autobuild@2d790406f505036ef40ecba973cc774a50395aac
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -75,4 +75,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@959cbb7472c4d4ad70cdfe6f4976053fe48ab394
|
||||
uses: github/codeql-action/analyze@2d790406f505036ef40ecba973cc774a50395aac
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# Dependency Review Action
|
||||
#
|
||||
# This Action will scan dependency manifest files that change as part of a Pull Request,
|
||||
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
|
||||
# Once installed, if the workflow run is marked as required,
|
||||
# PRs introducing known-vulnerable packages will be blocked from merging.
|
||||
#
|
||||
# Source repository: https://github.com/actions/dependency-review-action
|
||||
name: 'Dependency Review'
|
||||
on: [pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
dependency-review:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: 'Checkout Repository'
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
- name: 'Dependency Review'
|
||||
uses: actions/dependency-review-action@0c155c5e8556a497adf53f2c18edabf945ed8e70 # v4.3.2
|
||||
@@ -0,0 +1,28 @@
|
||||
name: 'Publish Immutable Action Version'
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Harden the runner (Audit all outbound calls)
|
||||
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: Checking out
|
||||
uses: actions/checkout@v4
|
||||
- name: Publish
|
||||
id: publish
|
||||
uses: actions/publish-immutable-action@0.0.4
|
||||
@@ -6,14 +6,14 @@ on:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
|
||||
jobs:
|
||||
int-tests:
|
||||
name: int tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
@@ -22,3 +22,18 @@ jobs:
|
||||
env:
|
||||
PAT: ${{ secrets.PAT }}
|
||||
canary: true
|
||||
|
||||
int-tls-tests:
|
||||
name: int tls tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
- name: Canary test
|
||||
uses: docker://ghcr.io/step-security/integration-test/int:latest
|
||||
env:
|
||||
PAT: ${{ secrets.PAT }}
|
||||
canary-tls: true
|
||||
|
||||
@@ -25,13 +25,14 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5
|
||||
- uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
|
||||
with:
|
||||
allowed-endpoints:
|
||||
egress-policy: audit
|
||||
allowed-endpoints:
|
||||
api.github.com:443
|
||||
github.com:443
|
||||
|
||||
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
- name: Update the rc tag
|
||||
uses: step-security/publish-action@b438f840875fdcb7d1de4fc3d1d30e86cf6acb5d
|
||||
with:
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
name: RunsOn Tests
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
test-host-outbound:
|
||||
runs-on:
|
||||
- runs-on=${{ github.run_id }}
|
||||
- runner=2cpu-linux-x64
|
||||
- image=ubuntu24-stepsecurity-x64
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@rc
|
||||
with:
|
||||
egress-policy: audit
|
||||
allowed-endpoints: >
|
||||
github.com:443
|
||||
goreleaser.com:443
|
||||
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Run outbound calls from host
|
||||
run: |
|
||||
start_time=$(date +%s)
|
||||
end_time=$((start_time + 90)) # 5 minutes = 300 seconds
|
||||
|
||||
while [ $(date +%s) -lt $end_time ]; do
|
||||
curl -I https://www.google.com
|
||||
curl -I https://goreleaser.com
|
||||
sleep 10 # wait 10 seconds between calls
|
||||
done
|
||||
|
||||
test-docker-outbound:
|
||||
runs-on:
|
||||
- runs-on=${{ github.run_id }}
|
||||
- runner=2cpu-linux-x64
|
||||
- image=ubuntu24-stepsecurity-x64
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@rc
|
||||
with:
|
||||
egress-policy: block
|
||||
allowed-endpoints: >
|
||||
archive.ubuntu.com:80
|
||||
github.com:443
|
||||
goreleaser.com:443
|
||||
production.cloudflare.docker.com:443
|
||||
docker-images-prod.6aa30f8b08e16409b46e0173d6de2f56.r2.cloudflarestorage.com:443
|
||||
*.docker.io:443
|
||||
security.ubuntu.com:80
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Run outbound calls from within Docker container
|
||||
continue-on-error: true
|
||||
run: |
|
||||
# Start the container
|
||||
docker run --rm -d --name test-container ubuntu:latest sleep 90
|
||||
|
||||
# Install curl in the container
|
||||
docker exec test-container apt-get update
|
||||
docker exec test-container apt-get install -y curl
|
||||
|
||||
# Print /etc/resolv.conf from the container
|
||||
docker exec test-container cat /etc/resolv.conf
|
||||
|
||||
# Make outbound calls
|
||||
for i in {1..9}; do
|
||||
docker exec test-container curl -I https://www.google.com
|
||||
docker exec test-container curl -I https://goreleaser.com
|
||||
sleep 10 # wait 10 seconds between calls
|
||||
done
|
||||
|
||||
# Stop the container
|
||||
docker stop test-container
|
||||
|
||||
|
||||
test-docker-build-outbound:
|
||||
runs-on:
|
||||
- runs-on=${{ github.run_id }}
|
||||
- runner=2cpu-linux-x64
|
||||
- image=ubuntu24-stepsecurity-x64
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@rc
|
||||
with:
|
||||
egress-policy: audit
|
||||
allowed-endpoints: >
|
||||
archive.ubuntu.com:80
|
||||
auth.docker.io:443
|
||||
github.com:443
|
||||
goreleaser.com:443
|
||||
production.cloudflare.docker.com:443
|
||||
docker-images-prod.6aa30f8b08e16409b46e0173d6de2f56.r2.cloudflarestorage.com:443
|
||||
registry-1.docker.io:443
|
||||
security.ubuntu.com:80
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Build Docker image and test outbound calls during build
|
||||
continue-on-error: true
|
||||
run: |
|
||||
# Create a Dockerfile that installs curl and makes outbound calls
|
||||
cat <<EOF > Dockerfile
|
||||
FROM ubuntu:latest
|
||||
RUN apt-get update && apt-get install -y curl
|
||||
RUN for i in {1..9}; do curl -I https://www.google.com && curl -I https://goreleaser.com; sleep 10; done
|
||||
EOF
|
||||
|
||||
# Build the Docker image
|
||||
docker build -t test-image .
|
||||
|
||||
# Print /etc/resolv.conf from the build container (temporary container used during build)
|
||||
container_id=$(docker create test-image)
|
||||
docker start $container_id
|
||||
docker exec $container_id cat /etc/resolv.conf
|
||||
docker stop $container_id
|
||||
docker rm $container_id
|
||||
|
||||
- name: Print Docker logs with journalctl
|
||||
run: |
|
||||
sudo journalctl -u docker.service --no-pager
|
||||
shell: bash
|
||||
|
||||
test-long-running-docker:
|
||||
runs-on:
|
||||
- runs-on=${{ github.run_id }}
|
||||
- runner=2cpu-linux-x64
|
||||
- image=ubuntu24-stepsecurity-x64
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@rc
|
||||
with:
|
||||
egress-policy: block
|
||||
allowed-endpoints: >
|
||||
archive.ubuntu.com:80
|
||||
auth.docker.io:443
|
||||
github.com:443
|
||||
goreleaser.com:443
|
||||
production.cloudflare.docker.com:443
|
||||
registry-1.docker.io:443
|
||||
docker-images-prod.6aa30f8b08e16409b46e0173d6de2f56.r2.cloudflarestorage.com:443
|
||||
security.ubuntu.com:80
|
||||
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Run long-running Docker container with outbound calls
|
||||
continue-on-error: true
|
||||
run: |
|
||||
# Start the long-running container
|
||||
docker run --rm -d --name long-running-container ubuntu:latest bash -c "
|
||||
apt-get update && apt-get install -y curl &&
|
||||
while true; do
|
||||
curl -I https://www.google.com;
|
||||
curl -I https://goreleaser.com;
|
||||
sleep 10;
|
||||
done
|
||||
"
|
||||
|
||||
# Print /etc/resolv.conf from the container
|
||||
docker exec long-running-container cat /etc/resolv.conf
|
||||
|
||||
# Let the container run for 5 minutes
|
||||
sleep 90
|
||||
|
||||
# Stop the container
|
||||
docker stop long-running-container
|
||||
|
||||
|
||||
@@ -24,13 +24,18 @@ jobs:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # tag=v3.0.0
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v3.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # tag=v1.1.1
|
||||
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # tag=v1.1.1
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
@@ -49,7 +54,7 @@ jobs:
|
||||
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||
# format to the repository Actions tab.
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # tag=v3.0.0
|
||||
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # tag=v4.6.1
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
@@ -57,6 +62,6 @@ jobs:
|
||||
|
||||
# Upload the results to GitHub's code scanning dashboard.
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@959cbb7472c4d4ad70cdfe6f4976053fe48ab394 # tag=v1.0.26
|
||||
uses: github/codeql-action/upload-sarif@2d790406f505036ef40ecba973cc774a50395aac # tag=v1.0.26
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
||||
@@ -13,14 +13,18 @@ concurrency:
|
||||
group: ${{ github.workflow }}
|
||||
jobs:
|
||||
test:
|
||||
permissions:
|
||||
checks: write
|
||||
pull-requests: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5 # v2.0.0
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
|
||||
with:
|
||||
disable-sudo: true
|
||||
egress-policy: block
|
||||
egress-policy: audit
|
||||
allowed-endpoints: >
|
||||
api.github.com:443
|
||||
codecov.io:443
|
||||
github.com:443
|
||||
registry.npmjs.org:443
|
||||
@@ -28,9 +32,44 @@ jobs:
|
||||
uploader.codecov.io:443
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
- name: Run coverage
|
||||
run: npm test -- --coverage
|
||||
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
|
||||
- uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
|
||||
- name: Publish Test Results
|
||||
uses: step-security/publish-unit-test-result-action@e88bfc6c0dffc68a1067d63526c80c81f248da11 # v2.20.0
|
||||
if: always()
|
||||
with:
|
||||
files: |
|
||||
reports/*.xml
|
||||
|
||||
build-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
|
||||
with:
|
||||
disable-sudo: true
|
||||
egress-policy: audit
|
||||
allowed-endpoints: >
|
||||
github.com:443
|
||||
registry.npmjs.org:443
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
- name: Run build
|
||||
run: npm run build
|
||||
- name: Check for changes in dist
|
||||
run: |
|
||||
if [[ `git status --porcelain dist` ]]; then
|
||||
echo "Changes detected in dist directory after build:"
|
||||
git status --porcelain dist
|
||||
git diff dist
|
||||
exit 1
|
||||
else
|
||||
echo "No changes in dist directory - build is clean"
|
||||
fi
|
||||
|
||||
@@ -20,6 +20,7 @@ lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
reports
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
@@ -104,4 +105,4 @@ typings/
|
||||
.tern-port
|
||||
|
||||
# vscode files
|
||||
.vscode
|
||||
.vscode
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
exclude: ^dist/
|
||||
repos:
|
||||
- repo: https://github.com/gitleaks/gitleaks
|
||||
rev: v8.16.3
|
||||
hooks:
|
||||
- id: gitleaks
|
||||
- repo: https://github.com/pre-commit/mirrors-eslint
|
||||
rev: v8.38.0
|
||||
hooks:
|
||||
- id: eslint
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
hooks:
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
@@ -1,7 +1,7 @@
|
||||
<p align="center">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="images/banner.png" width="400">
|
||||
<img src="images/banner.png" width="400">
|
||||
<source media="(prefers-color-scheme: light)" srcset="images/harden-runner-new.png" width="400">
|
||||
<img alt="Dark Banner" src="images/harden-runner-new.png" width="400">
|
||||
</picture>
|
||||
</p>
|
||||
|
||||
@@ -13,160 +13,181 @@
|
||||
|
||||
</div>
|
||||
|
||||
# Harden-Runner
|
||||
|
||||
Corporate laptops and production servers typically have robust security monitoring in place to reduce risk and meet compliance requirements. However, CI/CD runners, which handle sensitive information like secrets for cloud environments and create production builds, often lack such security measures. This oversight has led to significant supply chain attacks, including the SolarWinds and Codecov breaches.
|
||||
|
||||
Traditional security monitoring and EDR solutions are ineffective for CI/CD runners due to their ephemeral nature. These tools also lack the necessary context to correlate events with specific workflow runs in a CI/CD environment.
|
||||
|
||||
StepSecurity Harden-Runner addresses this gap by providing security monitoring tailored for CI/CD runners. This approach brings CI/CD runners under the same level of security scrutiny as other critical systems, addressing a significant gap in the software supply chain.
|
||||
### Harden-Runner: Security Incidents Detected
|
||||
|
||||
- [Harden-Runner Detected the tj-actions/changed-files compromise](https://www.stepsecurity.io/blog/harden-runner-detection-tj-actions-changed-files-action-is-compromised) ([CVE-2025-30066](https://github.com/advisories/GHSA-mrrh-fwg8-r2c3))
|
||||
- [Harden-Runner Detected a CI/CD Supply Chain Attack in Google’s Open-Source Project Flank](https://www.stepsecurity.io/case-studies/flank)
|
||||
- [Harden-Runner Detected the NX Build System compromise](https://www.stepsecurity.io/blog/supply-chain-security-alert-popular-nx-build-system-package-compromised-with-data-stealing-malware)
|
||||
- [Harden-Runner Detected a CI/CD Supply Chain Attack in Microsoft’s Open-Source Project Azure Karpenter Provider in Real-Time](https://www.stepsecurity.io/case-studies/azure-karpenter-provider)
|
||||
- [Harden-Runner Detected Anomalous Traffic to api.ipify.org Across Multiple Customers](https://www.stepsecurity.io/blog/harden-runner-detects-anomalous-traffic-to-api-ipify-org-across-multiple-customers)
|
||||
- [Harden-Runner Detected an Unexpected Microsoft Defender Installation on GitHub-Hosted Ubuntu Runners](https://www.stepsecurity.io/blog/how-stepsecurity-harden-runner-detected-unexpected-microsoft-defender-installation-on-github-hosted-ubuntu-runners)
|
||||
- [Harden-Runner Flagged an Anomalous Outbound Call, Leading to a Docker Documentation Update](https://www.stepsecurity.io/blog/harden-runner-flags-anomalous-outbound-call-leading-to-docker-documentation-update)
|
||||
|
||||
### See It in Action
|
||||
Harden-Runner secures over **8 million CI/CD workflow runs every week**, protecting thousands of pipelines, including those from popular open-source projects by **Microsoft, Google, and CISA**. See how top projects are using Harden-Runner and explore the insights:
|
||||
➡️ [Who's using Harden-Runner?](https://docs.stepsecurity.io/whos-using-harden-runner)
|
||||
|
||||
## Quick Links
|
||||
- [Getting Started Guide](#getting-started)
|
||||
- [Why Choose Harden-Runner](#why-choose-harden-runner)
|
||||
- [Features and Capabilities](#features)
|
||||
- [Case Studies and Trusted Projects](#trusted-by-and-case-studies)
|
||||
- [Environment Compatibility Matrix](#environment-compatibility-matrix)
|
||||
- [How It Works](docs/how-it-works.md)
|
||||
- [Known Limitations](docs/limitations.md)
|
||||
- [Join the Discussions](#discussions)
|
||||
- [Official Documentation](https://docs.stepsecurity.io/harden-runner)
|
||||
|
||||
---
|
||||
|
||||
Harden-Runner GitHub Action installs a security agent on the GitHub-hosted runner (Ubuntu VM) to
|
||||
## Introduction
|
||||
|
||||
1. Prevent exfiltration of credentials
|
||||
2. Detect tampering of source code during build
|
||||
3. Detect compromised dependencies and build tools
|
||||
Learn how Harden-Runner works through the video below, which shows how it detected the tj-actions/changed-files compromise. [View the interactive demo here](https://app.storylane.io/share/679y2zgzljov).
|
||||
|
||||
<a href="https://www.youtube.com/watch?v=oTAJ7Hy7nPU" target="_blank">
|
||||
<img src="images/case-study.png" alt="Harden-Runner detected the tj-actions/changed-files Breach" title="This case study video shows how StepSecurity Harden-Runner detected the tj-actions/changed-files Breach">
|
||||
</a>
|
||||
|
||||
<p align="center">
|
||||
<img src="images/demo.gif" alt="Harden Runner demo">
|
||||
</p>
|
||||
---
|
||||
## Getting Started
|
||||
|
||||
## Why
|
||||
This guide walks you through the steps to set up and use Harden-Runner in your CI/CD workflows. For more details, refer to the [official documentation](https://docs.stepsecurity.io/harden-runner).
|
||||
|
||||
Compromised dependencies and build tools typically make outbound calls to exfiltrate credentials, or may tamper source code, dependencies, or artifacts during the build.
|
||||
### **Step 1: Add Harden-Runner to Your Workflow**
|
||||
|
||||
Harden-Runner GitHub Actions installs a daemon that monitors process, file, and network activity to:
|
||||
|
||||
| | Countermeasure | Threat |
|
||||
| --- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1. | Block outbound calls that are not in the allowed list to prevent exfiltration of credentials | To prevent [Codecov breach](https://github.com/step-security/attack-simulator/blob/main/docs/RestrictOutboundTraffic.md) scenario |
|
||||
| 2. | Detect if source code is being overwritten during the build process to inject a backdoor | To detect [SolarWinds incident scenario](https://github.com/step-security/attack-simulator/blob/main/docs/MonitorSourceCode.md) |
|
||||
| 3. | Detect compromised dependencies that make unexpected outbound network calls | To detect [Dependency confusion](https://github.com/step-security/attack-simulator/blob/main/docs/DNSExfiltration.md) and [Malicious dependencies](https://github.com/step-security/attack-simulator/blob/main/docs/CompromisedDependency.md) |
|
||||
|
||||
Read this [case study](https://infosecwriteups.com/detecting-malware-packages-in-github-actions-7b93a9985635) on how Harden-Runner detected malicious packages in the NPM registry.
|
||||
|
||||
## How
|
||||
|
||||
1. Add `step-security/harden-runner` to your GitHub Actions workflow file as the first step in each job.
|
||||
To integrate Harden-Runner, follow these steps:
|
||||
|
||||
- Open your GitHub Actions workflow file (e.g., `.github/workflows/<workflow-name>.yml`).
|
||||
- Add the following code as the first step in each job:
|
||||
```yaml
|
||||
steps:
|
||||
- uses: step-security/harden-runner@ebacdc22ef6c2cfb85ee5ded8f2e640f4c776dd5
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
```
|
||||
|
||||
2. In the workflow logs, you will see a link to security insights and recommendations.
|
||||
**Tip**: Automate this step by pasting your workflow into the [StepSecurity online tool](https://app.stepsecurity.io/secure-workflow)
|
||||
<details>
|
||||
<summary>Click to view the full Getting Started Guide</summary>
|
||||
|
||||
<p align="left">
|
||||
<img src="images/buildlog1.png" alt="Link in build log" >
|
||||
### **Step 2: Access Security Insights**
|
||||
|
||||
Run your workflow. Once completed:
|
||||
- Review the **workflow logs** and the **job markdown summary**.
|
||||
- Look for a link to **security insights and recommendations**.
|
||||
<p align="left">
|
||||
<img src="images/buildlog1.png" alt="Link in workflow log" >
|
||||
</p>
|
||||
- Click on the provided link (e.g., [example link](https://app.stepsecurity.io/github/step-security/github-actions-goat/actions/runs/7704454287?jobid=20996777560&tab=network-events)) to access the **Process Monitor View**, which displays:
|
||||
- **Network events**: Outbound network calls correlated with each step.
|
||||
- **File events**: File writes tracked during the job.
|
||||
<p align="left">
|
||||
<img src="images/network-events.png" alt="Link in network events" >
|
||||
</p>
|
||||
|
||||
3. Click on the link ([example link](https://app.stepsecurity.io/github/ossf/scorecard/actions/runs/2265028928)). You will see a process monitor view of file and network activities correlated with each step of the job.
|
||||
</details>
|
||||
|
||||
<p align="left">
|
||||
<img src="images/insights2.png" alt="Insights from harden-runner" >
|
||||
</p>
|
||||
---
|
||||
## Why Choose Harden-Runner?
|
||||
|
||||
4. Below the insights, you will see the recommended policy. Update your workflow file with the recommended policy.
|
||||
- **Prevent Exfiltration:** Prevent the exfiltration of CI/CD secrets and source code.
|
||||
- **Detect Tampering:** Identify source code modifications during builds.
|
||||
- **Anomaly Detection:** Spot unusual dependencies and workflow behaviors.
|
||||
- **Simplify Permissions:** Determine the minimum required `GITHUB_TOKEN` permissions.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/rec-policy1.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
|
||||
## Features at a glance
|
||||
---
|
||||
|
||||
For details, check out the documentation at https://docs.stepsecurity.io
|
||||
## Features
|
||||
|
||||
<p align="left">
|
||||
<img src="images/main-screenshot1.png" alt="Policy recommended by harden-runner">
|
||||
</p>
|
||||
Harden-Runner offers a comprehensive suite of features to enhance the security of your CI/CD workflows, available in two tiers: **Community** (Free) and **Enterprise** (Paid).
|
||||
|
||||
### Restrict egress traffic to allowed endpoints
|
||||
### Community (Free)
|
||||
|
||||
Once allowed endpoints are set in the workflow file,
|
||||
- **CI/CD-Aware Event Correlation:** Each outbound network connection, file operation, and process execution is mapped to the exact step, job, and workflow where it occurs.
|
||||
- **Automated Baseline Creation:** Harden-Runner builds a baseline for each job based on past outbound network connections.
|
||||
- **Anomaly Detection:** Once the baseline is created, any future outbound calls not in the baseline trigger a detection.
|
||||
- **Block Network Egress Traffic with Domain Allowlist:** Optionally use the automatically created baseline to control outbound network traffic by specifying allowed domains, preventing unauthorized data exfiltration.
|
||||
- **Detect Modification of Source Code:** Monitor and alert on unauthorized changes to your source code during the CI/CD pipeline.
|
||||
|
||||
- Harden-Runner blocks egress traffic at the DNS (Layer 7) and network layers (Layers 3 and 4).
|
||||
- It blocks DNS exfiltration, where attacker tries to send data out using DNS resolution
|
||||
- Blocks outbound traffic using IP tables
|
||||
### Enterprise (Paid)
|
||||
|
||||
<p align="left">
|
||||
<img src="images/block-outbound-call.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
Includes all features in the **Community** tier, plus:
|
||||
|
||||
### Detect tampering of source code during build
|
||||
- **Support for Private Repositories:** Extend Harden-Runner's security capabilities to your private GitHub repositories.
|
||||
- **Support for Self-Hosted Runners:** Apply security controls and monitoring to self-hosted GitHub Actions runners.
|
||||
- **GitHub Checks Integration:** Enable GitHub Checks for Harden-Runner—if the baseline remains unchanged, the check passes; if it changes, the check fails, showing new outbound connections.
|
||||
- **View Outbound GitHub API calls at the Job Level:** Monitor HTTPS requests to GitHub APIs
|
||||
- **Determine Minimum GITHUB_TOKEN Permissions:** Monitor outbound HTTPS requests to GitHub APIs to recommend the least-privilege permissions needed for your workflows, enhancing security by reducing unnecessary access.
|
||||
- **View the Name and Path of Every File Written During the Build Process:** Gain visibility into every file written to the build environment, including the ability to correlate file writes with processes, ensuring complete transparency.
|
||||
- **View Process Names and Arguments:** Monitor every process executed during the build process, along with its arguments, and navigate the process tree to detect suspicious activities.
|
||||
|
||||
Harden-Runner monitors file writes and can detect if a file is overwritten.
|
||||
For a detailed comparison and more information, please visit our [Pricing Page](https://www.stepsecurity.io/pricing).
|
||||
|
||||
- Source code overwrite is not expected in a release build
|
||||
- All source code files are monitored, which means even changes to IaC files (Kubernetes manifest, Terraform) are detected
|
||||
- You can enable notifications to get one-time alert when source code is overwritten
|
||||
Explore the full feature set in the [Features Documentation](https://docs.stepsecurity.io/harden-runner).
|
||||
|
||||
<p align="left">
|
||||
<img src="images/fileoverwrite.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
---
|
||||
|
||||
### Run your job without sudo access
|
||||
## Trusted By and Case Studies
|
||||
|
||||
GitHub-hosted runner uses passwordless sudo for running jobs.
|
||||
Harden-Runner is trusted by over 8000 leading open-source projects and enterprises, including Microsoft, Google, Kubernetes, and more.
|
||||
|
||||
- This means compromised build tools or dependencies can install attack tools
|
||||
- If your job does not need sudo access, you see a policy
|
||||
recommendation to disable sudo in the insights page
|
||||
- When you set `disable-sudo` to `true`, the job steps run without sudo access to the Ubuntu VM
|
||||
### Trusted by
|
||||
|
||||
### Get security alerts
|
||||
|
||||
Install the [Harden Runner App](https://github.com/marketplace/harden-runner-app) to get security alerts.
|
||||
| [](https://app.stepsecurity.io/github/cisagov/skeleton-generic/actions/runs/9947319332?jobid=27479776091&tab=network-events) | [](https://app.stepsecurity.io/github/microsoft/ebpf-for-windows/actions/runs/7587031851) | [](https://app.stepsecurity.io/github/GoogleCloudPlatform/functions-framework-ruby/actions/runs/7576989995) | [](https://app.stepsecurity.io/github/DataDog/stratus-red-team/actions/runs/7446169664) | [](https://app.stepsecurity.io/github/intel/cve-bin-tool/actions/runs/7590975903) | [](https://app.stepsecurity.io/github/kubernetes-sigs/cluster-api-provider-azure/actions/runs/7591172950) | [](https://app.stepsecurity.io/github/nodejs/node/actions/runs/7591405720) | [](https://app.stepsecurity.io/github/aws/aperf/actions/runs/7631366761) |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **CISA**<br>[Explore](https://app.stepsecurity.io/github/cisagov/skeleton-generic/actions/runs/9947319332?jobid=27479776091&tab=network-events) | **Microsoft**<br>[Explore](https://app.stepsecurity.io/github/microsoft/ebpf-for-windows/actions/runs/7587031851) | **Google**<br>[Explore](https://app.stepsecurity.io/github/GoogleCloudPlatform/functions-framework-ruby/actions/runs/7576989995) | **DataDog**<br>[Explore](https://app.stepsecurity.io/github/DataDog/stratus-red-team/actions/runs/7446169664) | **Intel**<br>[Explore](https://app.stepsecurity.io/github/intel/cve-bin-tool/actions/runs/7590975903) | **Kubernetes**<br>[Explore](https://app.stepsecurity.io/github/kubernetes-sigs/cluster-api-provider-azure/actions/runs/7591172950) | **Node.js**<br>[Explore](https://app.stepsecurity.io/github/nodejs/node/actions/runs/7591405720) | **AWS**<br>[Explore](https://app.stepsecurity.io/github/aws/aperf/actions/runs/7631366761) |
|
||||
|
||||
- Email and Slack notifications are supported
|
||||
- Notifications are sent when outbound traffic is blocked or source code is overwritten
|
||||
- Notifications are not repeated for the same alert for a given workflow
|
||||
### Enterprise Case Studies
|
||||
|
||||
## Support for private repositories
|
||||
- [How Coveo Strengthened GitHub Actions Security with StepSecurity](https://www.stepsecurity.io/case-studies/coveo)
|
||||
- [Hashgraph Achieves Comprehensive CI/CD Security Without Compromising Development Speed](https://www.stepsecurity.io/case-studies/hashgraph)
|
||||
- [Chainguard Secures GitHub Actions with StepSecurity](https://www.stepsecurity.io/case-studies/chainguard)
|
||||
- [Kapiche secures their GitHub Actions software supply chain with Harden-Runner](https://www.stepsecurity.io/case-studies/kapiche)
|
||||
- [Arcjet Enhances CI/CD Security with Harden-Runner](https://www.stepsecurity.io/case-studies/arcjet)
|
||||
|
||||
Private repositories are supported if they have a commercial license. Check out the [documentation](https://docs.stepsecurity.io/harden-runner/installation/business-enterprise-license) for more details.
|
||||
---
|
||||
|
||||
Install the [Harden Runner App](https://github.com/marketplace/harden-runner-app) to use Harden-Runner GitHub Action for `Private` repositories.
|
||||
## Environment Compatibility Matrix
|
||||
|
||||
- If you use Harden-Runner GitHub Action in a private repository, the generated insights URL is NOT public.
|
||||
- You need to authenticate first to access insights URL for private repository. Only those who have access to the repository can view it.
|
||||
- [Harden Runner App](https://github.com/marketplace/harden-runner-app) only needs `actions: read` permissions on your repositories.
|
||||
Harden-Runner is designed to work seamlessly across a variety of runner environments, providing consistent security insights and protections regardless of where your workflows execute. For self-hosted runners, audit mode is deployed directly to the runner infrastructure without requiring any changes to your existing workflows. For more details, refer to the [official documentation](https://docs.stepsecurity.io/harden-runner).
|
||||
|
||||
Read this [case study on how Kapiche uses Harden Runner](https://www.stepsecurity.io/case-studies/kapiche/) to improve software supply chain security in their open source and private repositories.
|
||||
| Environment Type | Compatibility | Audit Mode Deployment | Workflow Changes for Audit Mode |
|
||||
|------------------|---------------|--------------------------|-------------------|
|
||||
| GitHub-hosted runners | ✅ Full support | Add Harden-Runner Action to workflow | Yes |
|
||||
| Self-hosted VM runners | ✅ Full support | Include agent in runner image | No |
|
||||
| Self-hosted bare-metal runners | ✅ Full support | Install agent as a service | No |
|
||||
| Actions Runner Controller (ARC) | ✅ Full support | Deploy as DaemonSet | No |
|
||||
| RunsOn Runners | ✅ Full support | Pre-integrated | No |
|
||||
|
||||
## Discussions
|
||||
## How It Works
|
||||
|
||||
If you have questions or ideas, please use [discussions](https://github.com/step-security/harden-runner/discussions).
|
||||
Want to know the technical details? Dive into the architecture of Harden-Runner and its integrations for GitHub-hosted and self-hosted runners in our [How Harden-Runner Works Documentation](docs/how-it-works.md).
|
||||
|
||||
1. [Support for private repositories](https://github.com/step-security/harden-runner/discussions/74)
|
||||
2. [Where should allowed-endpoints be stored?](https://github.com/step-security/harden-runner/discussions/84)
|
||||
3. [Cryptographically verify tools run as part of the CI/ CD pipeline](https://github.com/step-security/harden-runner/discussions/94)
|
||||
---
|
||||
|
||||
## Limitations
|
||||
|
||||
1. Harden-Runner GitHub Action only works for GitHub-hosted runners. Self-hosted runners are not supported.
|
||||
2. Only Ubuntu VM is supported. Windows and MacOS GitHub-hosted runners are not supported. There is a discussion about that [here](https://github.com/step-security/harden-runner/discussions/121).
|
||||
3. Harden-Runner is not supported when [job is run in a container](https://docs.github.com/en/actions/using-jobs/running-jobs-in-a-container) as it needs sudo access on the Ubuntu VM to run. It can be used to monitor jobs that use containers to run steps. The limitation is if the entire job is run in a container. That is not common for GitHub Actions workflows, as most of them run directly on `ubuntu-latest`.
|
||||
While Harden-Runner offers powerful features, there are certain limitations based on the environment, such as OS support. See the complete list in [Known Limitations](docs/limitations.md).
|
||||
|
||||
## Testimonials
|
||||
---
|
||||
|
||||
> _I think this is a great idea and for the threat model of build-time, an immediate network egress request monitoring makes a lot of sense_ - [Liran Tal](https://stars.github.com/profiles/lirantal/), GitHub Star, and Author of Essential Node.js Security
|
||||
## Discussions
|
||||
|
||||
> _Harden-Runner strikes an elegant balance between ease-of-use, maintainability, and mitigation that I intend to apply to all of my 300+ npm packages. I look forward to the tool’s improvement over time_ - [Jordan Harband](https://github.com/ljharb), Open Source Maintainer
|
||||
Join the conversation! For questions, ideas, or feedback, visit our [Discussions Page](https://github.com/step-security/harden-runner/discussions).
|
||||
|
||||
> _Harden runner from Step security is such a nice solution, it is another piece of the puzzle in helping treat the CI environment like production and solving supply chain security. I look forward to seeing it evolve._ - Cam Parry, Staff Site Reliability Engineer, Kapiche
|
||||
For enterprise support, email support@stepsecurity.io. Interested in using Harden-Runner in other CI/CD platforms? Reach out to interest@stepsecurity.io.
|
||||
|
||||
## Workflows using harden-runner
|
||||
---
|
||||
|
||||
Some important workflows using harden-runner:
|
||||
| |Repository |Link to insights|
|
||||
|--|----------|----------------|
|
||||
|1.|[nvm-sh/nvm](https://github.com/nvm-sh/nvm/blob/master/.github/workflows/lint.yml)|[Link to insights](https://app.stepsecurity.io/github/nvm-sh/nvm/actions/runs/1757959262)|
|
||||
|2.|[jsx-eslint/eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/.github/workflows/release.yml)|[Link to insights](https://app.stepsecurity.io/github/yannickcr/eslint-plugin-react/actions/runs/1930818585)
|
||||
|3.|[microsoft/msquic](https://github.com/microsoft/msquic/blob/main/.github/workflows/docker-publish.yml)|[Link to insights](https://app.stepsecurity.io/github/microsoft/msquic/actions/runs/1759010243)
|
||||
|4.|[ossf/scorecard](https://github.com/ossf/scorecard/blob/main/.github/workflows/codeql-analysis.yml)|[Link to insights](https://app.stepsecurity.io/github/ossf/scorecard/actions/runs/2006162141)
|
||||
|5.|[Automattic/vip-go-mu-plugins](https://github.com/Automattic/vip-go-mu-plugins/blob/master/.github/workflows/e2e.yml)|[Link to insights](https://app.stepsecurity.io/github/Automattic/vip-go-mu-plugins/actions/runs/1758760957)
|
||||
## License
|
||||
|
||||
## How does it work?
|
||||
|
||||
Harden-Runner GitHub Action downloads and installs the StepSecurity Agent.
|
||||
|
||||
- The code to monitor file, process, and network activity is in the Agent.
|
||||
- The agent is written in Go and is open source at https://github.com/step-security/agent
|
||||
- The agent's build is reproducible. You can view the steps to reproduce the build [here](http://app.stepsecurity.io/github/step-security/agent/releases/latest)
|
||||
Harden-Runner is open source. See the [LICENSE](LICENSE) file for details.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: "Harden Runner"
|
||||
description: "Security agent for GitHub-hosted runner to monitor the build process"
|
||||
name: "Harden-Runner"
|
||||
description: "Harden-Runner provides runtime security for GitHub-hosted and self-hosted runners"
|
||||
inputs:
|
||||
allowed-endpoints:
|
||||
description: "Only these endpoints will be allowed if egress-policy is set to block"
|
||||
@@ -17,18 +17,27 @@ inputs:
|
||||
required: false
|
||||
default: "false"
|
||||
disable-sudo:
|
||||
description: "Disable sudo access for the runner account"
|
||||
description: "Disable sudo access for the runner account. Note: This parameter will be deprecated in the future. Please use disable-sudo-and-containers instead."
|
||||
required: false
|
||||
default: "false"
|
||||
disable-sudo-and-containers:
|
||||
description: "Disable sudo and container access for the runner account"
|
||||
required: false
|
||||
default: "false"
|
||||
disable-file-monitoring:
|
||||
description: "Disable file monitoring"
|
||||
required: false
|
||||
default: "false"
|
||||
policy:
|
||||
description: "Policy name to be used from the policy store"
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
branding:
|
||||
icon: "check-square"
|
||||
color: "green"
|
||||
runs:
|
||||
using: "node16"
|
||||
using: "node20"
|
||||
pre: "dist/pre/index.js"
|
||||
main: "dist/index.js"
|
||||
post: "dist/post/index.js"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
## How Harden-Runner Works?
|
||||
|
||||
### GitHub-Hosted Runners
|
||||
|
||||
For GitHub-hosted runners, Harden-Runner GitHub Action downloads and installs the StepSecurity Agent.
|
||||
|
||||
- The code to monitor file, process, and network activity is in the Agent.
|
||||
- The community tier agent is open-source and can be found [here](https://github.com/step-security/agent). The enterprise tier agent is closed-source. Both agents are written in Go.
|
||||
- The agent's build is reproducible. You can view the steps to reproduce the build [here](http://app.stepsecurity.io/github/step-security/agent/releases/latest)
|
||||
|
||||
### Self-Hosted Actions Runner Controller (ARC) Runners
|
||||
|
||||
- ARC Harden Runner daemonset uses eBPF
|
||||
- You can find more details in this [blog post](https://www.stepsecurity.io/blog/introducing-harden-runner-for-kubernetes-based-self-hosted-actions-runners)
|
||||
- ARC Harden Runner is NOT open source.
|
||||
|
||||
### Self-Hosted VM Runners (e.g. on EC2)
|
||||
|
||||
- For self-hosted VMs, you add the Harden-Runner agent into your runner image (e.g. AMI).
|
||||
- You can find more details in this [blog post](https://www.stepsecurity.io/blog/ci-cd-security-for-self-hosted-vm-runners)
|
||||
- Agent for self-hosted VMs is NOT open source.
|
||||
@@ -0,0 +1,14 @@
|
||||
## Limitations
|
||||
|
||||
### GitHub-Hosted Runners
|
||||
|
||||
* Only Ubuntu VM is supported. Windows and MacOS GitHub-hosted runners are not supported. There is a discussion about that [here](https://github.com/step-security/harden-runner/discussions/121).
|
||||
* Harden-Runner is not supported when [job is run in a container](https://docs.github.com/en/actions/using-jobs/running-jobs-in-a-container) with built-in labels such as `ubuntu-latest`, as it needs sudo access on the Ubuntu VM to run. The limitation is if the entire job is run in a container. However, such jobs can be monitored when using custom VM images with GitHub-hosted runners. This is also not a limitation for Self-Hosted runners.
|
||||
|
||||
### Self-Hosted Actions Runner Controller (ARC) Runners
|
||||
|
||||
* Since ARC Harden Runner uses eBPF, only Linux jobs are supported. Windows and MacOS jobs are not supported.
|
||||
|
||||
### Self-Hosted VM (e.g. on EC2) and Bare-metal Runners
|
||||
|
||||
* Only Linux jobs are supported. Windows and MacOS jobs are not supported.
|
||||
|
After Width: | Height: | Size: 116 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 632 KiB |
|
After Width: | Height: | Size: 407 KiB |
|
Before Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 85 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 456 KiB |
|
After Width: | Height: | Size: 191 KiB |
|
After Width: | Height: | Size: 278 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 48 KiB |
@@ -1,5 +0,0 @@
|
||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
export default {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
reporters: [
|
||||
"default",
|
||||
["jest-junit", { outputDirectory: "reports", outputName: "report.xml" }],
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
[[IgnoredVulns]]
|
||||
id = "GHSA-h5c3-5r3r-rr8q"
|
||||
reason = "Untrusted headers are not processed"
|
||||
|
||||
[[IgnoredVulns]]
|
||||
id = "GHSA-rmvr-2pp2-xj38"
|
||||
reason = "Untrusted headers are not processed"
|
||||
|
||||
[[IgnoredVulns]]
|
||||
id = "GHSA-xx4v-prfh-6cgc"
|
||||
reason = "Untrusted headers are not processed"
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "step-security-harden-runner",
|
||||
"version": "2.1.0",
|
||||
"description": "Security agent for GitHub-hosted runner to monitor the build process",
|
||||
"version": "2.7.0",
|
||||
"description": "Security agent for GitHub-hosted runner: block egress traffic & detect code overwrite to prevent breaches",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "npm run main && npm run pre && npm run post",
|
||||
@@ -23,12 +23,13 @@
|
||||
},
|
||||
"homepage": "https://github.com/step-security/harden-runner#readme",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.0.4",
|
||||
"@actions/cache": "^4.0.0",
|
||||
"@actions/core": "^1.5.0",
|
||||
"@actions/exec": "^1.1.0",
|
||||
"@actions/github": "^5.0.0",
|
||||
"@actions/github": "^6.0.1",
|
||||
"@actions/http-client": "^2.0.1",
|
||||
"@actions/tool-cache": "^1.7.1",
|
||||
"@babel/helpers": "^7.26.10",
|
||||
"ansi-regex": ">=5.0.1",
|
||||
"is-docker": "^3.0.0",
|
||||
"node-fetch": ">=3.2.0",
|
||||
@@ -37,14 +38,16 @@
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.5.2",
|
||||
"@types/node": "^16.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.29.2",
|
||||
"@typescript-eslint/parser": "^4.29.2",
|
||||
"@vercel/ncc": "^0.30.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
||||
"@typescript-eslint/parser": "^6.1.0",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"jest": "^29.3.1",
|
||||
"jest-junit": ">=13.0.0",
|
||||
"nock": "^13.3.0",
|
||||
"ts-jest": "^29.0.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.3.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { isARCRunner } from "./arc-runner";
|
||||
|
||||
it("should correctly recognize arc based runner", async () => {
|
||||
process.env["GITHUB_ACTIONS_RUNNER_EXTRA_USER_AGENT"] =
|
||||
"actions-runner-controller/2.0.1";
|
||||
|
||||
let isArc: boolean = await isARCRunner();
|
||||
expect(isArc).toBe(true);
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import * as cp from "child_process";
|
||||
import * as fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export function isARCRunner(): boolean {
|
||||
const runnerUserAgent = process.env["GITHUB_ACTIONS_RUNNER_EXTRA_USER_AGENT"];
|
||||
|
||||
let isARC = false;
|
||||
|
||||
if (!runnerUserAgent) {
|
||||
isARC = false;
|
||||
} else {
|
||||
isARC = runnerUserAgent.includes("actions-runner-controller/");
|
||||
}
|
||||
|
||||
return isARC || isSecondaryPod();
|
||||
}
|
||||
|
||||
function isSecondaryPod(): boolean {
|
||||
const workDir = "/__w";
|
||||
let hasKubeEnv = process.env["KUBERNETES_PORT"] !== undefined;
|
||||
return fs.existsSync(workDir) && hasKubeEnv;
|
||||
}
|
||||
|
||||
export function sendAllowedEndpoints(endpoints: string): void {
|
||||
const startTime = Date.now();
|
||||
const allowedEndpoints = endpoints.split(" "); // endpoints are space separated
|
||||
|
||||
let sent = 0;
|
||||
for (let endpoint of allowedEndpoints) {
|
||||
endpoint = endpoint.trim();
|
||||
if (endpoint.length > 0) {
|
||||
let encodedEndpoint = Buffer.from(endpoint).toString("base64");
|
||||
let endpointPolicyStr = `step_policy_endpoint_${encodedEndpoint}`;
|
||||
echo(endpointPolicyStr);
|
||||
sent++;
|
||||
}
|
||||
}
|
||||
|
||||
if (sent > 0) {
|
||||
applyPolicy(sent);
|
||||
}
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
console.log(
|
||||
`[harden-runner] sendAllowedEndpoints completed in ${duration}ms (sent ${sent} endpoints)`
|
||||
);
|
||||
}
|
||||
|
||||
function applyPolicy(count: number): void {
|
||||
let applyPolicyStr = `step_policy_apply_${count}`;
|
||||
echo(applyPolicyStr);
|
||||
}
|
||||
|
||||
function echo(content: string) {
|
||||
cp.execFileSync("echo", [content]);
|
||||
}
|
||||
@@ -1,98 +1,6 @@
|
||||
import * as core from "@actions/core";
|
||||
import { HttpClient } from "@actions/http-client";
|
||||
import { RequestOptions } from "@actions/http-client/lib/interfaces";
|
||||
import { BearerCredentialHandler } from "@actions/http-client/lib/auth";
|
||||
import * as crypto from "crypto";
|
||||
|
||||
const versionSalt = "1.0";
|
||||
export const cacheKey = "harden-runner-cacheKey";
|
||||
export const cacheFile = "/home/agent/cache.txt";
|
||||
|
||||
function getCacheApiUrl(resource: string): string {
|
||||
const baseUrl: string = process.env["ACTIONS_CACHE_URL"] || "";
|
||||
if (!baseUrl) {
|
||||
throw new Error("Cache Service Url not found, unable to restore cache.");
|
||||
}
|
||||
|
||||
const url = `${baseUrl}_apis/artifactcache/${resource}`;
|
||||
core.debug(`Resource Url: ${url}`);
|
||||
return url;
|
||||
}
|
||||
|
||||
function createAcceptHeader(type: string, apiVersion: string): string {
|
||||
return `${type};api-version=${apiVersion}`;
|
||||
}
|
||||
|
||||
function getRequestOptions(): RequestOptions {
|
||||
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
||||
|
||||
const requestOptions: RequestOptions = {
|
||||
headers: {
|
||||
Accept: createAcceptHeader("application/json", "6.0-preview.1"),
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
};
|
||||
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
function createHttpClient(): HttpClient {
|
||||
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
|
||||
const bhandler = new BearerCredentialHandler(token);
|
||||
return new HttpClient("actions/cache", [bhandler], getRequestOptions());
|
||||
}
|
||||
|
||||
export function getCacheVersion(
|
||||
paths: string[],
|
||||
compressionMethod?: CompressionMethod
|
||||
): string {
|
||||
const components = paths.concat(
|
||||
!compressionMethod || compressionMethod === CompressionMethod.Gzip
|
||||
? []
|
||||
: [compressionMethod]
|
||||
);
|
||||
|
||||
// Add salt to cache version to support breaking changes in cache entry
|
||||
components.push(versionSalt);
|
||||
|
||||
return crypto.createHash("sha256").update(components.join("|")).digest("hex");
|
||||
}
|
||||
|
||||
export async function getCacheEntry(
|
||||
keys: string[],
|
||||
paths: string[],
|
||||
options?: InternalCacheOptions
|
||||
): Promise<ArtifactCacheEntry | null> {
|
||||
const httpClient = createHttpClient();
|
||||
const version = getCacheVersion(paths, options?.compressionMethod);
|
||||
const resource = `cache?keys=${encodeURIComponent(
|
||||
keys.join(",")
|
||||
)}&version=${version}`;
|
||||
|
||||
const response = await httpClient.getJson<ArtifactCacheEntry>(
|
||||
getCacheApiUrl(resource)
|
||||
);
|
||||
if (response.statusCode === 204) {
|
||||
throw new Error("Request returned 204 status");
|
||||
}
|
||||
if (!isSuccessStatusCode(response.statusCode)) {
|
||||
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||
}
|
||||
|
||||
const cacheResult = response.result;
|
||||
const cacheDownloadUrl = cacheResult?.archiveLocation;
|
||||
if (!cacheDownloadUrl) {
|
||||
throw new Error("Cache still be done, but not found.");
|
||||
}
|
||||
|
||||
return cacheResult;
|
||||
}
|
||||
|
||||
export interface InternalCacheOptions {
|
||||
compressionMethod?: CompressionMethod;
|
||||
cacheSize?: number;
|
||||
}
|
||||
|
||||
export interface ArtifactCacheEntry {
|
||||
cacheKey?: string;
|
||||
scope?: string;
|
||||
@@ -100,13 +8,6 @@ export interface ArtifactCacheEntry {
|
||||
archiveLocation?: string;
|
||||
}
|
||||
|
||||
function isSuccessStatusCode(statusCode?: number): boolean {
|
||||
if (!statusCode) {
|
||||
return false;
|
||||
}
|
||||
return statusCode >= 200 && statusCode < 300;
|
||||
}
|
||||
|
||||
export enum CompressionMethod {
|
||||
Gzip = "gzip",
|
||||
// Long range mode was added to zstd in v1.3.2.
|
||||
@@ -118,4 +19,4 @@ export enum CompressionMethod {
|
||||
const RefKey = "GITHUB_REF";
|
||||
export function isValidEvent(): boolean {
|
||||
return RefKey in process.env && Boolean(process.env[RefKey]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,21 +2,50 @@ import * as core from "@actions/core";
|
||||
import * as crypto from "crypto";
|
||||
import * as fs from "fs";
|
||||
|
||||
export function verifyChecksum(downloadPath: string) {
|
||||
const CHECKSUMS = {
|
||||
tls: {
|
||||
amd64: "2a5be06ab620340f6957ddd180450caab414671c8b7da1996d8e2755c1cd49fa", // v1.7.9
|
||||
arm64: "e9d0ccf3e4e62ba15ff208ef6e0afa0ad5e323c3dfc50527342f436a85e65a55",
|
||||
},
|
||||
non_tls: {
|
||||
amd64: "336093af8ebe969567b66fd035af3bd4f7e1c723ce680d6b4b5b2a1f79bc329e", // v0.14.2
|
||||
},
|
||||
darwin: "caaacc24bbf6a39ba7560e5e4701353c537883cb3ab9553359bd5caf5097246f", // v0.0.1
|
||||
};
|
||||
|
||||
export function verifyChecksum(
|
||||
downloadPath: string,
|
||||
isTLS: boolean,
|
||||
variant: string,
|
||||
platform: string
|
||||
) {
|
||||
const fileBuffer: Buffer = fs.readFileSync(downloadPath);
|
||||
const checksum: string = crypto
|
||||
.createHash("sha256")
|
||||
.update(fileBuffer)
|
||||
.digest("hex"); // checksum of downloaded file
|
||||
|
||||
const expectedChecksum: string =
|
||||
"79f397360470d6e42c73d6c9c5cf485ac9982e56e3e3fdd07f66c59cda4388c8"; // checksum for v0.12.1
|
||||
let expectedChecksum: string = "";
|
||||
|
||||
switch (platform) {
|
||||
case "linux":
|
||||
expectedChecksum = isTLS
|
||||
? CHECKSUMS["tls"][variant]
|
||||
: CHECKSUMS["non_tls"][variant];
|
||||
break;
|
||||
case "darwin":
|
||||
expectedChecksum = CHECKSUMS["darwin"];
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported platform: ${platform}`);
|
||||
}
|
||||
|
||||
if (checksum !== expectedChecksum) {
|
||||
core.setFailed(
|
||||
`Checksum verification failed, expected ${expectedChecksum} instead got ${checksum}`
|
||||
`❌ Checksum verification failed, expected ${expectedChecksum} instead got ${checksum}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
core.debug("Checksum verification passed.");
|
||||
core.info(`✅ Checksum verification passed. checksum=${checksum}`);
|
||||
}
|
||||
|
||||
@@ -1,51 +1,164 @@
|
||||
import * as fs from "fs";
|
||||
import * as cp from "child_process";
|
||||
import * as core from "@actions/core";
|
||||
import * as common from "./common";
|
||||
import isDocker from "is-docker";
|
||||
import * as cache from "@actions/cache";
|
||||
import { cacheFile, cacheKey, isValidEvent } from "./cache";
|
||||
import path from "path";
|
||||
|
||||
import { isARCRunner } from "./arc-runner";
|
||||
import { isGithubHosted } from "./tls-inspect";
|
||||
import { context } from "@actions/github";
|
||||
(async () => {
|
||||
if (process.platform !== "linux") {
|
||||
console.log(common.UBUNTU_MESSAGE);
|
||||
console.log("[harden-runner] post-step");
|
||||
|
||||
const customProperties = context?.payload?.repository?.custom_properties || {};
|
||||
if (customProperties["skip-harden-runner"] === "true") {
|
||||
console.log("Skipping harden-runner: custom property 'skip-harden-runner' is set to 'true'");
|
||||
return;
|
||||
}
|
||||
if (isDocker()) {
|
||||
|
||||
let platform = process.platform;
|
||||
switch (platform) {
|
||||
case "linux":
|
||||
case "darwin":
|
||||
break;
|
||||
default:
|
||||
console.log(common.UBUNTU_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (isGithubHosted() && isDocker()) {
|
||||
console.log(common.CONTAINER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isARCRunner()) {
|
||||
console.log(`[!] ${common.ARC_RUNNER_MESSAGE}`);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (platform) {
|
||||
case "darwin":
|
||||
await handleDarwinCleanup();
|
||||
break;
|
||||
|
||||
case "linux":
|
||||
await handleLinuxCleanup();
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
await common.addSummary();
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
})();
|
||||
|
||||
async function handleDarwinCleanup() {
|
||||
fs.writeFileSync(
|
||||
"/opt/step-security/post_event.json",
|
||||
JSON.stringify({ event: "post" })
|
||||
);
|
||||
|
||||
let macDone = "/opt/step-security/done.json";
|
||||
let counter = 0;
|
||||
while (true) {
|
||||
if (!fs.existsSync(macDone)) {
|
||||
counter++;
|
||||
if (counter > 10) {
|
||||
console.log("timed out");
|
||||
break;
|
||||
}
|
||||
await sleep(1000);
|
||||
} else {
|
||||
// The file *does* exist
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let macAgenLog = "/opt/step-security/agent.log";
|
||||
if (fs.existsSync(macAgenLog)) {
|
||||
console.log("macAgenLog:");
|
||||
var content = fs.readFileSync(macAgenLog, "utf-8");
|
||||
console.log(content);
|
||||
} else {
|
||||
console.log("😭 macos agent.log file not found");
|
||||
}
|
||||
|
||||
// Capture system log stream for harden-runner subsystem
|
||||
try {
|
||||
console.log("\nSystem log stream for io.stepsecurity.harden-runner:");
|
||||
const logStreamOutput = cp.execSync(
|
||||
"log show --predicate 'subsystem == \"io.stepsecurity.harden-runner\"' --info --last 10m",
|
||||
{
|
||||
encoding: "utf8",
|
||||
maxBuffer: 1024 * 1024 * 10, // 10MB buffer
|
||||
timeout: 10000, // 30 second timeout
|
||||
}
|
||||
);
|
||||
console.log(logStreamOutput);
|
||||
} catch (error) {
|
||||
console.log("Warning: Could not fetch system log stream:", error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLinuxCleanup() {
|
||||
if (process.env.STATE_selfHosted === "true") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.STATE_customVMImage === "true") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.STATE_isTLS === "false" && process.arch === "arm64") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
String(process.env.STATE_monitorStatusCode) ===
|
||||
common.STATUS_HARDEN_RUNNER_UNAVAILABLE
|
||||
) {
|
||||
console.log(common.HARDEN_RUNNER_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isGithubHosted() && fs.existsSync("/home/agent/post_event.json")) {
|
||||
console.log("Post step already executed, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
"/home/agent/post_event.json",
|
||||
JSON.stringify({ event: "post" })
|
||||
);
|
||||
|
||||
var doneFile = "/home/agent/done.json";
|
||||
var counter = 0;
|
||||
const doneFile = "/home/agent/done.json";
|
||||
let counter = 0;
|
||||
while (true) {
|
||||
if (!fs.existsSync(doneFile)) {
|
||||
counter++;
|
||||
if (counter > 10) {
|
||||
console.log("timed out");
|
||||
|
||||
break;
|
||||
}
|
||||
await sleep(1000);
|
||||
} // The file *does* exist
|
||||
else {
|
||||
} else {
|
||||
// The file *does* exist
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var log = "/home/agent/agent.log";
|
||||
const log = "/home/agent/agent.log";
|
||||
if (fs.existsSync(log)) {
|
||||
console.log("log:");
|
||||
var content = fs.readFileSync(log, "utf-8");
|
||||
console.log(content);
|
||||
}
|
||||
|
||||
const daemonLog = "/home/agent/daemon.log";
|
||||
if (fs.existsSync(daemonLog)) {
|
||||
console.log("daemonLog:");
|
||||
var content = fs.readFileSync(daemonLog, "utf-8");
|
||||
console.log(content);
|
||||
}
|
||||
|
||||
var status = "/home/agent/agent.status";
|
||||
if (fs.existsSync(status)) {
|
||||
console.log("status:");
|
||||
@@ -53,42 +166,25 @@ import path from "path";
|
||||
console.log(content);
|
||||
}
|
||||
|
||||
// write annotations
|
||||
var annotationsFile = "/home/agent/annotation.log";
|
||||
if (fs.existsSync(annotationsFile)) {
|
||||
var content = fs.readFileSync(annotationsFile, "utf-8");
|
||||
content.split(/\r?\n/).forEach((line) => {
|
||||
core.error(line);
|
||||
});
|
||||
}
|
||||
var disable_sudo = process.env.STATE_disableSudo;
|
||||
var disable_sudo_and_containers = process.env.STATE_disableSudoAndContainers;
|
||||
|
||||
var disable_sudo = core.getBooleanInput("disable-sudo");
|
||||
if (!disable_sudo) {
|
||||
var journalLog = cp.execSync("sudo journalctl -u agent.service", {
|
||||
encoding: "utf8",
|
||||
});
|
||||
console.log("Service log:");
|
||||
console.log(journalLog);
|
||||
}
|
||||
|
||||
if (isValidEvent()) {
|
||||
if (disable_sudo !== "true" && disable_sudo_and_containers !== "true") {
|
||||
try {
|
||||
const cmd = "cp";
|
||||
const args = [path.join(__dirname, "cache.txt"), cacheFile];
|
||||
cp.execFileSync(cmd, args);
|
||||
const cacheResult = await cache.saveCache([cacheFile], cacheKey);
|
||||
console.log(cacheResult);
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
var journalLog = cp.execSync(
|
||||
"sudo journalctl -u agent.service --lines=1000",
|
||||
{
|
||||
encoding: "utf8",
|
||||
maxBuffer: 1024 * 1024 * 10, // 10MB buffer
|
||||
}
|
||||
);
|
||||
console.log("agent.service log:");
|
||||
console.log(journalLog);
|
||||
} catch (error) {
|
||||
console.log("Warning: Could not fetch service logs:", error.message);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await common.addSummary();
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
import { addSummary } from "./common";
|
||||
import * as cp from "child_process";
|
||||
import { processLogLine } from "./common"; // import the function
|
||||
|
||||
test("adding stepsecurity summary in github_summary", async () => {
|
||||
let expected = `<hr>
|
||||
<img src="https://github.com/step-security/harden-runner/raw/main/images/banner.png" alt="StepSecurity Harden-Runner" width="200">
|
||||
<a href="https://app.stepsecurity.io/github/step-security/test/actions/runs/12345">View security insights and recommended policy</a>
|
||||
<hr>
|
||||
`;
|
||||
describe("processLogLine function", () => {
|
||||
it("correctly processes the log line and adds an entry to the array", () => {
|
||||
const tableEntries: {
|
||||
pid: string;
|
||||
process: string;
|
||||
domain: string;
|
||||
ipAddress: string;
|
||||
status: string;
|
||||
}[] = [];
|
||||
const logLine =
|
||||
"Thu, 15 Jun 2023 05:35:29 GMT:endpoint called ip address:port 104.16.24.35:443, domain: registry.npmjs.org., pid: 2135, process: node.";
|
||||
|
||||
const github_summary = "/tmp/github_summary";
|
||||
cp.execSync(`touch ${github_summary}`);
|
||||
processLogLine(logLine, tableEntries);
|
||||
|
||||
process.env["STATE_monitorStatusCode"] = "200";
|
||||
process.env["GITHUB_STEP_SUMMARY"] = github_summary;
|
||||
process.env["GITHUB_REPOSITORY"] = "step-security/test";
|
||||
process.env["GITHUB_RUN_ID"] = "12345";
|
||||
// Check if a single entry is added to the array
|
||||
expect(tableEntries.length).toBe(1);
|
||||
|
||||
await addSummary();
|
||||
|
||||
let output = cp.execSync(`cat ${github_summary}`).toString();
|
||||
cp.execSync(`rm ${github_summary}`);
|
||||
|
||||
expect(output).toMatch(expected);
|
||||
|
||||
});
|
||||
// Check if the entry's properties are set correctly
|
||||
const entry = tableEntries[0];
|
||||
expect(entry.pid).toBe("2135");
|
||||
expect(entry.process).toBe("node");
|
||||
expect(entry.domain).toBe("registry.npmjs.org.");
|
||||
expect(entry.ipAddress).toBe("104.16.24.35:443");
|
||||
expect(entry.status).toBe("✅ Allowed"); // Since the IP address is not '54.185.253.63', status should be '✔️ Allowed'
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as fs from "fs";
|
||||
import * as cp from "child_process";
|
||||
import { STEPSECURITY_API_URL, STEPSECURITY_WEB_URL } from "./configs";
|
||||
|
||||
export function printInfo(web_url) {
|
||||
console.log(
|
||||
"\x1b[32m%s\x1b[0m",
|
||||
@@ -9,28 +13,136 @@ export function printInfo(web_url) {
|
||||
`${web_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}`
|
||||
);
|
||||
}
|
||||
export async function addSummary() {
|
||||
if (process.env.STATE_monitorStatusCode === "200") {
|
||||
const web_url = "https://app.stepsecurity.io";
|
||||
const insights_url = `${web_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}`;
|
||||
|
||||
export const processLogLine = (
|
||||
line: string,
|
||||
tableEntries: {
|
||||
pid: string;
|
||||
process: string;
|
||||
domain: string;
|
||||
ipAddress: string;
|
||||
status: string;
|
||||
}[]
|
||||
): void => {
|
||||
if (
|
||||
line.includes("pid") &&
|
||||
line.includes("process") &&
|
||||
line.includes("domain") &&
|
||||
line.includes("ip address")
|
||||
) {
|
||||
const matches = line.match(
|
||||
/ip address:port ([\d.:]+), domain: ([\w.-]+), pid: (\d+), process: (\w+)/
|
||||
);
|
||||
if (matches) {
|
||||
const [ipAddress, domain, pid, process] = matches.slice(1);
|
||||
|
||||
// Check if all values are non-empty and domain does not end with specified patterns
|
||||
if (
|
||||
pid &&
|
||||
process &&
|
||||
domain &&
|
||||
ipAddress &&
|
||||
!domain.endsWith(".actions.githubusercontent.com.") &&
|
||||
!domain.endsWith(".blob.core.windows.net.")
|
||||
) {
|
||||
const status = ipAddress.startsWith("54.185.253.63")
|
||||
? "❌ Blocked"
|
||||
: "✅ Allowed";
|
||||
|
||||
tableEntries.push({ pid, process, domain, ipAddress, status });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export async function addSummary() {
|
||||
if (process.env.STATE_addSummary !== "true") {
|
||||
return;
|
||||
}
|
||||
|
||||
const correlation_id = process.env.STATE_correlation_id;
|
||||
if (!correlation_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
let needsSubscription = false;
|
||||
try {
|
||||
let data = fs.readFileSync("/home/agent/annotation.log", "utf8");
|
||||
if (data.includes("StepSecurity Harden Runner is disabled")) {
|
||||
needsSubscription = true;
|
||||
}
|
||||
} catch (err) {
|
||||
//console.error(err);
|
||||
}
|
||||
|
||||
if (needsSubscription) {
|
||||
await core.summary
|
||||
.addSeparator()
|
||||
.addImage(
|
||||
"https://github.com/step-security/harden-runner/raw/main/images/banner.png",
|
||||
"StepSecurity Harden-Runner",
|
||||
{ width: "200" }
|
||||
)
|
||||
.addLink(
|
||||
"View security insights and recommended policy",
|
||||
insights_url
|
||||
.addRaw(
|
||||
`<h2>⚠️ Your GitHub Actions Runtime Security is currently disabled!</h2>`
|
||||
);
|
||||
|
||||
await core.summary
|
||||
.addRaw(
|
||||
`
|
||||
<p>It appears that you're using the <a href="https://github.com/step-security/harden-runner">Harden-Runner GitHub Action</a> by StepSecurity within a private repository. However, runtime security is not enabled as your organization hasn't signed up for a free trial or a paid subscription yet.</p>
|
||||
<p>To enable runtime security, start a free trial today by installing the <a href="https://github.com/apps/stepsecurity-actions-security">StepSecurity Actions Security GitHub App</a>. For more information or assistance, feel free to reach out to us through our <a href="https://www.stepsecurity.io/contact">contact form</a>.</p>
|
||||
`
|
||||
)
|
||||
.addSeparator()
|
||||
.write();
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract owner and repo from GITHUB_REPOSITORY (format: owner/repo)
|
||||
const [owner, repo] = process.env["GITHUB_REPOSITORY"]?.split("/") || [];
|
||||
const run_id = process.env["GITHUB_RUN_ID"];
|
||||
if (!owner || !repo || !run_id || !correlation_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch job summary from API
|
||||
const apiUrl = `${STEPSECURITY_API_URL}/github/${owner}/${repo}/actions/runs/${run_id}/correlation/${correlation_id}/job-markdown-summary`;
|
||||
try {
|
||||
const response = await fetch(apiUrl);
|
||||
if (!response.ok) {
|
||||
console.error(`Failed to fetch job summary: ${response.status} ${response.statusText}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const markdownSummary = await response.text();
|
||||
|
||||
// Render the markdown summary using core.summary.addRaw
|
||||
await core.summary.addRaw(markdownSummary).write();
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(`Error fetching job summary: ${error}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export function chownForFolder(newOwner: string, target: string) {
|
||||
let cmd = "sudo";
|
||||
let args = ["chown", "-R", newOwner, target];
|
||||
cp.execFileSync(cmd, args);
|
||||
}
|
||||
|
||||
export const STATUS_HARDEN_RUNNER_UNAVAILABLE = "409";
|
||||
|
||||
export 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.";
|
||||
"This job is running in a container. Such jobs can be monitored by installing Harden Runner in a custom VM image for GitHub-hosted runners.";
|
||||
|
||||
export 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.";
|
||||
|
||||
export const SELF_HOSTED_RUNNER_MESSAGE =
|
||||
"This job is running on a self-hosted runner.";
|
||||
|
||||
export const HARDEN_RUNNER_UNAVAILABLE_MESSAGE =
|
||||
"Sorry, we are currently experiencing issues with the Harden Runner installation process. It is currently unavailable.";
|
||||
|
||||
export const ARC_RUNNER_MESSAGE =
|
||||
"Workflow is currently being executed in ARC based runner.";
|
||||
|
||||
export const ARM64_RUNNER_MESSAGE =
|
||||
"ARM runners are not supported in the Harden-Runner community tier.";
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export const STEPSECURITY_ENV = "agent"; // agent or int
|
||||
|
||||
export const STEPSECURITY_API_URL = `https://${STEPSECURITY_ENV}.api.stepsecurity.io/v1`;
|
||||
|
||||
export const STEPSECURITY_WEB_URL = "https://app.stepsecurity.io";
|
||||
@@ -1,17 +1,39 @@
|
||||
import * as common from "./common";
|
||||
import * as core from "@actions/core";
|
||||
import isDocker from "is-docker";
|
||||
|
||||
import { STEPSECURITY_WEB_URL } from "./configs";
|
||||
import { isGithubHosted } from "./tls-inspect";
|
||||
import { context } from "@actions/github";
|
||||
(async () => {
|
||||
console.log("[harden-runner] main-step");
|
||||
|
||||
const customProperties = context?.payload?.repository?.custom_properties || {};
|
||||
if (customProperties["skip-harden-runner"] === "true") {
|
||||
console.log("Skipping harden-runner: custom property 'skip-harden-runner' is set to 'true'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.platform !== "linux") {
|
||||
console.log(common.UBUNTU_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (isDocker()) {
|
||||
if (isGithubHosted() && isDocker()) {
|
||||
console.log(common.CONTAINER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
String(process.env.STATE_monitorStatusCode) ===
|
||||
common.STATUS_HARDEN_RUNNER_UNAVAILABLE
|
||||
) {
|
||||
console.log(common.HARDEN_RUNNER_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.STATE_isTLS === "false" && process.arch === "arm64") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
core.getBooleanInput("disable-telemetry") &&
|
||||
core.getInput("egress-policy") === "block"
|
||||
@@ -20,7 +42,7 @@ import isDocker from "is-docker";
|
||||
"Telemetry will not be sent to StepSecurity API as disable-telemetry is set to true"
|
||||
);
|
||||
} else {
|
||||
var web_url = "https://app.stepsecurity.io";
|
||||
var web_url = STEPSECURITY_WEB_URL;
|
||||
common.printInfo(web_url);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
import * as tc from "@actions/tool-cache";
|
||||
import * as core from "@actions/core";
|
||||
import * as cp from "child_process";
|
||||
import * as path from "path";
|
||||
import * as fs from "fs";
|
||||
import { verifyChecksum } from "./checksum";
|
||||
import { EOL } from "os";
|
||||
import { ARM64_RUNNER_MESSAGE, chownForFolder } from "./common";
|
||||
|
||||
export async function installAgent(
|
||||
isTLS: boolean,
|
||||
configStr: string
|
||||
): Promise<boolean> {
|
||||
// Note: to avoid github rate limiting
|
||||
const token = core.getInput("token", { required: true });
|
||||
const auth = `token ${token}`;
|
||||
|
||||
const variant = process.arch === "x64" ? "amd64" : "arm64";
|
||||
|
||||
let downloadPath: string;
|
||||
|
||||
fs.appendFileSync(process.env.GITHUB_STATE, `isTLS=${isTLS}${EOL}`, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
|
||||
if (isTLS) {
|
||||
downloadPath = await tc.downloadTool(
|
||||
`https://github.com/step-security/agent-ebpf/releases/download/v1.7.9/harden-runner_1.7.9_linux_${variant}.tar.gz`,
|
||||
undefined,
|
||||
auth
|
||||
);
|
||||
} else {
|
||||
if (variant === "arm64") {
|
||||
console.log(ARM64_RUNNER_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
downloadPath = await tc.downloadTool(
|
||||
"https://github.com/step-security/agent/releases/download/v0.14.2/agent_0.14.2_linux_amd64.tar.gz",
|
||||
undefined,
|
||||
auth
|
||||
);
|
||||
}
|
||||
|
||||
verifyChecksum(downloadPath, isTLS, variant, process.platform);
|
||||
|
||||
const extractPath = await tc.extractTar(downloadPath);
|
||||
|
||||
let cmd = "cp",
|
||||
args = [path.join(extractPath, "agent"), "/home/agent/agent"];
|
||||
|
||||
cp.execFileSync(cmd, args);
|
||||
|
||||
cp.execSync("chmod +x /home/agent/agent");
|
||||
|
||||
fs.writeFileSync("/home/agent/agent.json", configStr);
|
||||
|
||||
cmd = "sudo";
|
||||
args = [
|
||||
"cp",
|
||||
path.join(__dirname, "agent.service"),
|
||||
"/etc/systemd/system/agent.service",
|
||||
];
|
||||
cp.execFileSync(cmd, args);
|
||||
cp.execSync("sudo systemctl daemon-reload");
|
||||
cp.execSync("sudo service agent start", { timeout: 15000 });
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function installMacosAgent(confgStr: string): Promise<boolean> {
|
||||
const token = core.getInput("token", { required: true });
|
||||
const auth = `token ${token}`;
|
||||
|
||||
try {
|
||||
// Create working directory
|
||||
core.info("Creating /opt/step-security directory...");
|
||||
cp.execSync("sudo mkdir -p /opt/step-security");
|
||||
chownForFolder(process.env.USER, "/opt/step-security");
|
||||
core.info("✓ Successfully created /opt/step-security directory");
|
||||
|
||||
// Create agent configuration file
|
||||
core.info("Creating agent.json");
|
||||
fs.writeFileSync("/opt/step-security/agent.json", confgStr);
|
||||
core.info(
|
||||
"✓ Successfully created agent.json at /opt/step-security/agent.json"
|
||||
);
|
||||
|
||||
// Download installer package
|
||||
const downloadUrl =
|
||||
"https://github.com/step-security/agent-releases/releases/download/v1.0.0-int/macos-installer-0.0.1.tar.gz";
|
||||
core.info(`Downloading macOS installer.. : ${downloadUrl}`);
|
||||
const downloadPath = await tc.downloadTool(downloadUrl);
|
||||
core.info(`✓ Successfully downloaded installer to: ${downloadPath}`);
|
||||
|
||||
// Verify SHA256 checksum
|
||||
core.info("Verifying SHA256 checksum of downloaded tar file...");
|
||||
verifyChecksum(downloadPath, false, "", "darwin");
|
||||
|
||||
// Extract installer package
|
||||
core.info("Extracting installer...");
|
||||
const extractPath = await tc.extractTar(downloadPath);
|
||||
core.info(`✓ Successfully extracted installer to: ${extractPath}`);
|
||||
|
||||
// Copy Installer binary to /opt/step-security
|
||||
const installerSourcePath = path.join(extractPath, "Installer");
|
||||
core.info(
|
||||
`Copying Installer from ${installerSourcePath} to /opt/step-security...`
|
||||
);
|
||||
cp.execSync(`cp "${installerSourcePath}" /opt/step-security/`);
|
||||
core.info("✓ Successfully copied Installer to /opt/step-security");
|
||||
|
||||
const installerBinaryPath = "/opt/step-security/Installer";
|
||||
|
||||
// Verify installer binary exists
|
||||
if (!fs.existsSync(installerBinaryPath)) {
|
||||
throw new Error(
|
||||
"Installer binary not found at /opt/step-security/Installer"
|
||||
);
|
||||
}
|
||||
core.info("✓ Installer binary verified");
|
||||
|
||||
// Make installer executable
|
||||
core.info("Making installer executable...");
|
||||
cp.execSync(`chmod +x "${installerBinaryPath}"`);
|
||||
core.info("✓ Installer is now executable");
|
||||
|
||||
// Run installer
|
||||
core.info("Running installer...");
|
||||
cp.execSync(
|
||||
`sudo "${installerBinaryPath}" -workdir /opt/step-security >> /opt/step-security/agent.log 2>&1`,
|
||||
{
|
||||
shell: "/bin/bash",
|
||||
timeout: 10000, // 10 second timeout
|
||||
}
|
||||
);
|
||||
core.info("✓ Installer completed successfully");
|
||||
|
||||
core.info("✅ macOS agent installation completed successfully");
|
||||
return true;
|
||||
} catch (error) {
|
||||
core.error(`❌ Failed to install macOS agent: ${error}`);
|
||||
if (error instanceof Error && error.stack) {
|
||||
core.debug(error.stack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
export interface Configuration {
|
||||
repo: string;
|
||||
run_id: string;
|
||||
correlation_id: string;
|
||||
working_directory: string;
|
||||
api_url: string;
|
||||
allowed_endpoints: string;
|
||||
egress_policy: string;
|
||||
disable_telemetry: boolean;
|
||||
disable_sudo: boolean;
|
||||
disable_sudo_and_containers: boolean;
|
||||
disable_file_monitoring: boolean;
|
||||
is_github_hosted: boolean;
|
||||
private: string;
|
||||
is_debug: boolean;
|
||||
one_time_key: string;
|
||||
}
|
||||
|
||||
export interface PolicyResponse {
|
||||
owner?: string;
|
||||
policyName?: string;
|
||||
allowed_endpoints?: string[];
|
||||
disable_sudo?: boolean;
|
||||
disable_sudo_and_containers?: boolean;
|
||||
disable_file_monitoring?: boolean;
|
||||
disable_telemetry?: boolean;
|
||||
egress_policy?: string;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import nock from "nock";
|
||||
import { fetchPolicy, mergeConfigs } from "./policy-utils";
|
||||
import { Configuration, PolicyResponse } from "./interfaces";
|
||||
import { STEPSECURITY_API_URL } from "./configs";
|
||||
|
||||
test("success: fetching policy", async () => {
|
||||
let owner = "h0x0er";
|
||||
let policyName = "policy1";
|
||||
let response = {
|
||||
owner: "h0x0er",
|
||||
policyName: "policy1",
|
||||
allowed_endpoints: ["github.com:443"],
|
||||
egress_policy: "audit",
|
||||
disable_telemetry: false,
|
||||
disable_sudo: false,
|
||||
disable_file_monitoring: false,
|
||||
};
|
||||
const policyScope = nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/actions/policies/${policyName}`)
|
||||
.reply(200, response);
|
||||
|
||||
let idToken = "xyz";
|
||||
let policy = await fetchPolicy(owner, policyName, idToken);
|
||||
console.log(policy);
|
||||
expect(policy).toStrictEqual(response);
|
||||
});
|
||||
|
||||
test("merge configs", async () => {
|
||||
let localConfig: Configuration = {
|
||||
repo: "test/repo",
|
||||
run_id: "xyx",
|
||||
correlation_id: "aaaaa",
|
||||
working_directory: "/xyz",
|
||||
api_url: "xyz",
|
||||
allowed_endpoints: "",
|
||||
egress_policy: "audit",
|
||||
disable_telemetry: false,
|
||||
disable_sudo: false,
|
||||
disable_sudo_and_containers: false,
|
||||
disable_file_monitoring: false,
|
||||
private: "true",
|
||||
is_github_hosted: true,
|
||||
is_debug: false,
|
||||
one_time_key: "",
|
||||
};
|
||||
let policyResponse: PolicyResponse = {
|
||||
owner: "h0x0er",
|
||||
policyName: "policy1",
|
||||
allowed_endpoints: ["github.com:443", "google.com:443"],
|
||||
egress_policy: "audit",
|
||||
disable_telemetry: false,
|
||||
disable_sudo: false,
|
||||
disable_file_monitoring: false,
|
||||
};
|
||||
|
||||
let expectedConfiguration: Configuration = {
|
||||
repo: "test/repo",
|
||||
run_id: "xyx",
|
||||
correlation_id: "aaaaa",
|
||||
working_directory: "/xyz",
|
||||
api_url: "xyz",
|
||||
allowed_endpoints: "github.com:443 google.com:443",
|
||||
egress_policy: "audit",
|
||||
disable_telemetry: false,
|
||||
disable_sudo: false,
|
||||
disable_sudo_and_containers: false,
|
||||
disable_file_monitoring: false,
|
||||
private: "true",
|
||||
is_github_hosted: true,
|
||||
is_debug: false,
|
||||
one_time_key: "",
|
||||
};
|
||||
|
||||
localConfig = mergeConfigs(localConfig, policyResponse);
|
||||
expect(localConfig).toStrictEqual(expectedConfiguration);
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
import { HttpClient } from "@actions/http-client";
|
||||
import { PolicyResponse, Configuration } from "./interfaces";
|
||||
import { STEPSECURITY_API_URL } from "./configs";
|
||||
|
||||
export async function fetchPolicy(
|
||||
owner: string,
|
||||
policyName: string,
|
||||
idToken: string
|
||||
): Promise<PolicyResponse> {
|
||||
if (idToken === "") {
|
||||
throw new Error("[PolicyFetch]: id-token in empty");
|
||||
}
|
||||
|
||||
let policyEndpoint = `${STEPSECURITY_API_URL}/github/${owner}/actions/policies/${policyName}`;
|
||||
|
||||
let httpClient = new HttpClient();
|
||||
|
||||
let headers = {};
|
||||
headers["Authorization"] = `Bearer ${idToken}`;
|
||||
headers["Source"] = "github-actions";
|
||||
|
||||
let response = undefined;
|
||||
let err = undefined;
|
||||
|
||||
let retry = 0;
|
||||
while (retry < 3) {
|
||||
try {
|
||||
console.log(`Attempt: ${retry + 1}`);
|
||||
response = await httpClient.getJson<PolicyResponse>(
|
||||
policyEndpoint,
|
||||
headers
|
||||
);
|
||||
break;
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
retry += 1;
|
||||
await sleep(1000);
|
||||
}
|
||||
|
||||
if (response === undefined && err !== undefined) {
|
||||
// Preserve the original error's statusCode if it exists
|
||||
const error = new Error(`[Policy Fetch] ${err}`);
|
||||
if (err.statusCode !== undefined) {
|
||||
(error as any).statusCode = err.statusCode;
|
||||
}
|
||||
throw error;
|
||||
} else {
|
||||
return response.result;
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeConfigs(
|
||||
localConfig: Configuration,
|
||||
remoteConfig: PolicyResponse
|
||||
) {
|
||||
if (localConfig.allowed_endpoints === "") {
|
||||
localConfig.allowed_endpoints = remoteConfig.allowed_endpoints.join(" ");
|
||||
}
|
||||
if (remoteConfig.disable_sudo !== undefined) {
|
||||
localConfig.disable_sudo = remoteConfig.disable_sudo;
|
||||
}
|
||||
|
||||
if (remoteConfig.disable_sudo_and_containers !== undefined) {
|
||||
localConfig.disable_sudo_and_containers = remoteConfig.disable_sudo_and_containers;
|
||||
}
|
||||
|
||||
if (remoteConfig.disable_file_monitoring !== undefined) {
|
||||
localConfig.disable_file_monitoring = remoteConfig.disable_file_monitoring;
|
||||
}
|
||||
if (remoteConfig.egress_policy !== undefined) {
|
||||
localConfig.egress_policy = remoteConfig.egress_policy;
|
||||
}
|
||||
|
||||
return localConfig;
|
||||
}
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
@@ -5,38 +5,66 @@ import * as httpm from "@actions/http-client";
|
||||
import * as path from "path";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import * as common from "./common";
|
||||
import * as tc from "@actions/tool-cache";
|
||||
import { verifyChecksum } from "./checksum";
|
||||
import isDocker from "is-docker";
|
||||
import { context } from "@actions/github";
|
||||
import { EOL } from "os";
|
||||
import {
|
||||
cacheFile,
|
||||
ArtifactCacheEntry,
|
||||
cacheKey,
|
||||
cacheFile,
|
||||
CompressionMethod,
|
||||
getCacheEntry,
|
||||
isValidEvent,
|
||||
} from "./cache";
|
||||
import { Configuration, PolicyResponse } from "./interfaces";
|
||||
import { fetchPolicy, mergeConfigs } from "./policy-utils";
|
||||
import * as cache from "@actions/cache";
|
||||
import { getCacheEntry } from "@actions/cache/lib/internal/cacheHttpClient";
|
||||
import * as cacheTwirpClient from "@actions/cache/lib/internal/shared/cacheTwirpClient";
|
||||
import { GetCacheEntryDownloadURLRequest } from "@actions/cache/lib/generated/results/api/v1/cache";
|
||||
import { getCacheServiceVersion } from "@actions/cache/lib/internal/config";
|
||||
|
||||
import * as utils from "@actions/cache/lib/internal/cacheUtils";
|
||||
import { isARCRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
import { STEPSECURITY_API_URL, STEPSECURITY_WEB_URL } from "./configs";
|
||||
import { isGithubHosted, isTLSEnabled } from "./tls-inspect";
|
||||
import { installAgent, installMacosAgent } from "./install-agent";
|
||||
|
||||
interface MonitorResponse {
|
||||
runner_ip_address?: string;
|
||||
one_time_key?: string;
|
||||
monitoring_started?: boolean;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
if (process.platform !== "linux") {
|
||||
console.log(common.UBUNTU_MESSAGE);
|
||||
console.log("[harden-runner] pre-step");
|
||||
|
||||
const customProperties = context?.payload?.repository?.custom_properties || {};
|
||||
if (customProperties["skip-harden-runner"] === "true") {
|
||||
console.log("Skipping harden-runner: custom property 'skip-harden-runner' is set to 'true'");
|
||||
return;
|
||||
}
|
||||
if (isDocker()) {
|
||||
|
||||
let platform = process.platform;
|
||||
switch (platform) {
|
||||
case "linux":
|
||||
case "darwin":
|
||||
break;
|
||||
default:
|
||||
console.log(common.UBUNTU_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isGithubHosted() && isDocker()) {
|
||||
console.log(common.CONTAINER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
var correlation_id = uuidv4();
|
||||
var env = "agent";
|
||||
var api_url = `https://${env}.api.stepsecurity.io/v1`;
|
||||
var web_url = "https://app.stepsecurity.io";
|
||||
var api_url = STEPSECURITY_API_URL;
|
||||
var web_url = STEPSECURITY_WEB_URL;
|
||||
|
||||
console.log(`Step Security Job Correlation ID: ${correlation_id}`);
|
||||
|
||||
const confg = {
|
||||
let confg: Configuration = {
|
||||
repo: process.env["GITHUB_REPOSITORY"],
|
||||
run_id: process.env["GITHUB_RUN_ID"],
|
||||
correlation_id: correlation_id,
|
||||
@@ -46,27 +74,60 @@ import {
|
||||
egress_policy: core.getInput("egress-policy"),
|
||||
disable_telemetry: core.getBooleanInput("disable-telemetry"),
|
||||
disable_sudo: core.getBooleanInput("disable-sudo"),
|
||||
disable_sudo_and_containers: core.getBooleanInput(
|
||||
"disable-sudo-and-containers"
|
||||
),
|
||||
disable_file_monitoring: core.getBooleanInput("disable-file-monitoring"),
|
||||
private: context.payload.repository.private,
|
||||
private: context?.payload?.repository?.private || false,
|
||||
is_github_hosted: isGithubHosted(),
|
||||
is_debug: core.isDebug(),
|
||||
one_time_key: "",
|
||||
};
|
||||
|
||||
if (isValidEvent()) {
|
||||
let policyName = core.getInput("policy");
|
||||
if (policyName !== "") {
|
||||
console.log(`Fetching policy from API with name: ${policyName}`);
|
||||
try {
|
||||
const cacheEntry = await getCacheEntry([cacheKey], [cacheFile], {
|
||||
compressionMethod: CompressionMethod.ZstdWithoutLong,
|
||||
});
|
||||
const url = new URL(cacheEntry.archiveLocation);
|
||||
core.info(`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`);
|
||||
confg.allowed_endpoints += ` ${url.hostname}:443`;
|
||||
} catch (exception) {
|
||||
// some exception has occurred.
|
||||
core.info("Unable to fetch cacheURL");
|
||||
if (confg.egress_policy === "block") {
|
||||
core.info("Switching egress-policy to audit mode");
|
||||
confg.egress_policy = "audit";
|
||||
let idToken: string = await core.getIDToken();
|
||||
let result: PolicyResponse = await fetchPolicy(
|
||||
context.repo.owner,
|
||||
policyName,
|
||||
idToken
|
||||
);
|
||||
confg = mergeConfigs(confg, result);
|
||||
} catch (err) {
|
||||
core.info(`[!] ${err}`);
|
||||
// Only fail the job if ID token is not available
|
||||
if (err.message && err.message.includes('Unable to get ACTIONS_ID_TOKEN_REQUEST')) {
|
||||
core.setFailed('Policy store requires id-token write permission as it uses OIDC to fetch the policy from StepSecurity API. Please add "id-token: write" to your job permissions.');
|
||||
} else {
|
||||
// Handle different HTTP status codes
|
||||
if (err.statusCode >= 400 && err.statusCode < 500) {
|
||||
core.error('Policy not found');
|
||||
} else {
|
||||
core.error(
|
||||
`Unexpected error occurred: ${err}. Falling back to egress policy audit`
|
||||
);
|
||||
confg.egress_policy = "audit";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fs.appendFileSync(
|
||||
process.env.GITHUB_STATE,
|
||||
`disableSudo=${confg.disable_sudo}${EOL}`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
);
|
||||
fs.appendFileSync(
|
||||
process.env.GITHUB_STATE,
|
||||
`disableSudoAndContainers=${confg.disable_sudo_and_containers}${EOL}`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
);
|
||||
core.info(`[!] Current Configuration: \n${JSON.stringify(confg)}\n`);
|
||||
|
||||
if (confg.egress_policy !== "audit" && confg.egress_policy !== "block") {
|
||||
core.setFailed("egress-policy must be either audit or block");
|
||||
@@ -82,96 +143,246 @@ import {
|
||||
core.setFailed("disable-telemetry must be a boolean value");
|
||||
}
|
||||
|
||||
if (!confg.disable_telemetry) {
|
||||
let _http = new httpm.HttpClient();
|
||||
_http.requestOptions = { socketTimeout: 3 * 1000 };
|
||||
if (isValidEvent() && confg.egress_policy === "block") {
|
||||
try {
|
||||
const resp: httpm.HttpClientResponse = await _http.get(
|
||||
`${api_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}/monitor`
|
||||
const cacheResult = await cache.saveCache(
|
||||
[path.join(__dirname, "cache.txt")],
|
||||
cacheKey
|
||||
);
|
||||
if(resp.message.statusCode === 200){
|
||||
fs.appendFileSync(
|
||||
process.env.GITHUB_STATE,
|
||||
`monitorStatusCode=${resp.message.statusCode}${EOL}`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
console.log(cacheResult);
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
|
||||
const cacheServiceVersion: string = getCacheServiceVersion();
|
||||
|
||||
switch (cacheServiceVersion) {
|
||||
case "v2":
|
||||
core.info(`cache version: v2`);
|
||||
try {
|
||||
const cacheFilePath = path.join(__dirname, "cache.txt");
|
||||
core.info(`cacheFilePath ${cacheFilePath}`);
|
||||
|
||||
const twirpClient = cacheTwirpClient.internalCacheTwirpClient();
|
||||
const compressionMethod = await utils.getCompressionMethod();
|
||||
|
||||
const request: GetCacheEntryDownloadURLRequest = {
|
||||
key: cacheKey,
|
||||
restoreKeys: [],
|
||||
version: utils.getCacheVersion(
|
||||
[cacheFilePath],
|
||||
compressionMethod,
|
||||
false
|
||||
),
|
||||
};
|
||||
|
||||
const response = await twirpClient.GetCacheEntryDownloadURL(
|
||||
request
|
||||
);
|
||||
|
||||
const url = new URL(response.signedDownloadUrl);
|
||||
core.info(
|
||||
`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`
|
||||
);
|
||||
|
||||
confg.allowed_endpoints += ` ${url.hostname}:443`;
|
||||
} catch (e) {
|
||||
core.info(`Unable to fetch cacheURL ${e}`);
|
||||
if (confg.egress_policy === "block") {
|
||||
core.info("Switching egress-policy to audit mode");
|
||||
confg.egress_policy = "audit";
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.log(`error in connecting to ${api_url}: ${e}`);
|
||||
}
|
||||
break;
|
||||
|
||||
case "v1":
|
||||
core.info(`cache version: v1`);
|
||||
|
||||
try {
|
||||
const compressionMethod: CompressionMethod =
|
||||
await utils.getCompressionMethod();
|
||||
const cacheFilePath = path.join(__dirname, "cache.txt");
|
||||
core.info(`cacheFilePath ${cacheFilePath}`);
|
||||
|
||||
const cacheEntry: ArtifactCacheEntry = await getCacheEntry(
|
||||
[cacheKey],
|
||||
[cacheFilePath],
|
||||
{
|
||||
compressionMethod: compressionMethod,
|
||||
}
|
||||
);
|
||||
const url = new URL(cacheEntry.archiveLocation);
|
||||
core.info(
|
||||
`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`
|
||||
);
|
||||
|
||||
confg.allowed_endpoints += ` ${url.hostname}:443`;
|
||||
} catch (exception) {
|
||||
// some exception has occurred.
|
||||
core.info(`Unable to fetch cacheURL ${exception}`);
|
||||
if (confg.egress_policy === "block") {
|
||||
core.info("Switching egress-policy to audit mode");
|
||||
confg.egress_policy = "audit";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const confgStr = JSON.stringify(confg);
|
||||
cp.execSync("sudo mkdir -p /home/agent");
|
||||
cp.execSync("sudo chown -R $USER /home/agent");
|
||||
|
||||
// Note: to avoid github rate limiting
|
||||
let token = core.getInput("token");
|
||||
let auth = `token ${token}`;
|
||||
|
||||
const downloadPath: string = await tc.downloadTool(
|
||||
"https://github.com/step-security/agent/releases/download/v0.12.1/agent_0.12.1_linux_amd64.tar.gz",
|
||||
undefined,
|
||||
auth
|
||||
);
|
||||
|
||||
verifyChecksum(downloadPath); // NOTE: verifying agent's checksum, before extracting
|
||||
const extractPath = await tc.extractTar(downloadPath);
|
||||
|
||||
if (!confg.disable_telemetry || confg.egress_policy === "audit") {
|
||||
common.printInfo(web_url);
|
||||
}
|
||||
|
||||
let cmd = "cp",
|
||||
args = [path.join(extractPath, "agent"), "/home/agent/agent"];
|
||||
cp.execFileSync(cmd, args);
|
||||
cp.execSync("chmod +x /home/agent/agent");
|
||||
|
||||
fs.writeFileSync("/home/agent/agent.json", confgStr);
|
||||
|
||||
cmd = "sudo";
|
||||
args = [
|
||||
"cp",
|
||||
path.join(__dirname, "agent.service"),
|
||||
"/etc/systemd/system/agent.service",
|
||||
];
|
||||
cp.execFileSync(cmd, args);
|
||||
cp.execSync("sudo systemctl daemon-reload");
|
||||
cp.execSync("sudo service agent start", { timeout: 15000 });
|
||||
|
||||
// Check that the file exists locally
|
||||
var statusFile = "/home/agent/agent.status";
|
||||
var logFile = "/home/agent/agent.log";
|
||||
var counter = 0;
|
||||
while (true) {
|
||||
if (!fs.existsSync(statusFile)) {
|
||||
counter++;
|
||||
if (counter > 30) {
|
||||
console.log("timed out");
|
||||
if (fs.existsSync(logFile)) {
|
||||
var content = fs.readFileSync(logFile, "utf-8");
|
||||
console.log(content);
|
||||
}
|
||||
break;
|
||||
}
|
||||
await sleep(300);
|
||||
} // The file *does* exist
|
||||
else {
|
||||
// Read the file
|
||||
var content = fs.readFileSync(statusFile, "utf-8");
|
||||
console.log(content);
|
||||
break;
|
||||
if (isARCRunner()) {
|
||||
console.log(`[!] ${common.ARC_RUNNER_MESSAGE}`);
|
||||
if (confg.egress_policy === "block") {
|
||||
sendAllowedEndpoints(confg.allowed_endpoints);
|
||||
await sleep(10000);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const runnerName = process.env.RUNNER_NAME || "";
|
||||
core.info(`RUNNER_NAME: ${runnerName}`);
|
||||
if (!isGithubHosted()) {
|
||||
fs.appendFileSync(process.env.GITHUB_STATE, `selfHosted=true${EOL}`, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
|
||||
core.info(common.SELF_HOSTED_RUNNER_MESSAGE);
|
||||
|
||||
if (confg.egress_policy === "block") {
|
||||
sendAllowedEndpoints(confg.allowed_endpoints);
|
||||
await sleep(5000);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isGithubHosted() && process.env.STEP_SECURITY_HARDEN_RUNNER === "true") {
|
||||
fs.appendFileSync(process.env.GITHUB_STATE, `customVMImage=true${EOL}`, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
|
||||
core.info("This job is running on a custom VM image with Harden Runner installed.");
|
||||
|
||||
if (confg.egress_policy === "block") {
|
||||
sendAllowedEndpoints(confg.allowed_endpoints);
|
||||
await sleep(5000);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isGithubHosted() && fs.existsSync("/home/agent/agent.status")) {
|
||||
console.log("Agent already installed, skipping installation");
|
||||
return;
|
||||
}
|
||||
|
||||
let _http = new httpm.HttpClient();
|
||||
let statusCode: number | undefined;
|
||||
_http.requestOptions = { socketTimeout: 3 * 1000 };
|
||||
let addSummary = "false";
|
||||
try {
|
||||
const monitorRequestData = {
|
||||
correlation_id: correlation_id,
|
||||
job: process.env["GITHUB_JOB"],
|
||||
};
|
||||
const resp = await _http.postJson<MonitorResponse>(
|
||||
`${api_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}/monitor`,
|
||||
monitorRequestData
|
||||
);
|
||||
|
||||
const responseData = resp.result;
|
||||
statusCode = resp.statusCode; // adding error code to check whether agent is getting installed or not.
|
||||
fs.appendFileSync(
|
||||
process.env.GITHUB_STATE,
|
||||
`monitorStatusCode=${statusCode}${EOL}`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
);
|
||||
|
||||
if (statusCode === 200 && responseData) {
|
||||
console.log(`Runner IP Address: ${responseData.runner_ip_address}`);
|
||||
confg.one_time_key = responseData.one_time_key;
|
||||
addSummary = responseData.monitoring_started ? "true" : "false";
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(`error in connecting to ${api_url}: ${e}`);
|
||||
}
|
||||
fs.appendFileSync(
|
||||
process.env.GITHUB_STATE,
|
||||
`addSummary=${addSummary}${EOL}`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
);
|
||||
fs.appendFileSync(
|
||||
process.env.GITHUB_STATE,
|
||||
`correlation_id=${correlation_id}${EOL}`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
);
|
||||
|
||||
console.log(`Step Security Job Correlation ID: ${correlation_id}`);
|
||||
if (String(statusCode) === common.STATUS_HARDEN_RUNNER_UNAVAILABLE) {
|
||||
console.log(common.HARDEN_RUNNER_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
const confgStr = JSON.stringify(confg);
|
||||
|
||||
switch (platform) {
|
||||
case "linux":
|
||||
cp.execSync("sudo mkdir -p /home/agent");
|
||||
common.chownForFolder(process.env.USER, "/home/agent");
|
||||
|
||||
let isTLS = await isTLSEnabled(context.repo.owner);
|
||||
|
||||
const agentInstalled = await installAgent(isTLS, confgStr);
|
||||
|
||||
if (agentInstalled) {
|
||||
// Check that the file exists locally
|
||||
var statusFile = "/home/agent/agent.status";
|
||||
var logFile = "/home/agent/agent.log";
|
||||
var counter = 0;
|
||||
while (true) {
|
||||
if (!fs.existsSync(statusFile)) {
|
||||
counter++;
|
||||
if (counter > 30) {
|
||||
console.log("timed out");
|
||||
if (fs.existsSync(logFile)) {
|
||||
var content = fs.readFileSync(logFile, "utf-8");
|
||||
console.log(content);
|
||||
}
|
||||
break;
|
||||
}
|
||||
await sleep(300);
|
||||
} // The file *does* exist
|
||||
else {
|
||||
// Read the file
|
||||
var content = fs.readFileSync(statusFile, "utf-8");
|
||||
console.log(content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case "darwin":
|
||||
const installed = await installMacosAgent(confgStr);
|
||||
if (!installed) {
|
||||
core.warning("😭 macos agent installation failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
// see https://github.com/ruby/setup-ruby/issues/543
|
||||
process.exit(0);
|
||||
})();
|
||||
|
||||
function sleep(ms) {
|
||||
export function sleep(ms: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import nock from "nock";
|
||||
import { STEPSECURITY_API_URL } from "./configs";
|
||||
import { isTLSEnabled } from "./tls-inspect";
|
||||
|
||||
test("tls-inspect enabled", async () => {
|
||||
let owner = "h0x0er";
|
||||
let expected = true;
|
||||
|
||||
const resp = nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/actions/tls-inspection-status`)
|
||||
.reply(200, "");
|
||||
|
||||
let got = await isTLSEnabled(owner);
|
||||
|
||||
expect(got).toEqual(expected);
|
||||
});
|
||||
|
||||
test("tls-inspect not enabled", async () => {
|
||||
let owner = "step-security";
|
||||
let expected = false;
|
||||
|
||||
const resp = nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/actions/tls-inspection-status`)
|
||||
.reply(401, "");
|
||||
|
||||
let got = await isTLSEnabled(owner);
|
||||
|
||||
expect(got).toEqual(expected);
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import { HttpClient } from "@actions/http-client";
|
||||
import { STEPSECURITY_API_URL } from "./configs";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
export async function isTLSEnabled(owner: string): Promise<boolean> {
|
||||
let tlsStatusEndpoint = `${STEPSECURITY_API_URL}/github/${owner}/actions/tls-inspection-status`;
|
||||
let httpClient = new HttpClient();
|
||||
httpClient.requestOptions = { socketTimeout: 3 * 1000 };
|
||||
core.info(`[!] Checking TLS_STATUS: ${owner}`);
|
||||
let isEnabled = false;
|
||||
try {
|
||||
let resp = await httpClient.get(tlsStatusEndpoint);
|
||||
if (resp.message.statusCode === 200) {
|
||||
isEnabled = true;
|
||||
core.info(`[!] TLS_ENABLED: ${owner}`);
|
||||
} else {
|
||||
core.info(`[!] TLS_NOT_ENABLED: ${owner}`);
|
||||
}
|
||||
} catch (e) {
|
||||
core.info(`[!] Unable to check TLS_STATUS`);
|
||||
}
|
||||
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
export function isGithubHosted() {
|
||||
const runnerEnvironment = process.env.RUNNER_ENVIRONMENT || "";
|
||||
return runnerEnvironment === "github-hosted";
|
||||
}
|
||||
@@ -14,4 +14,4 @@
|
||||
"exclude": [
|
||||
"src/**/*.test.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||