mirror of
https://github.com/step-security/harden-runner.git
synced 2026-06-05 19:53:33 +00:00
Compare commits
190 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9af89fc715 |
||
|
|
485dce8cb5 |
||
|
|
ab7a9404c0 |
||
|
|
ec41b783c2 |
||
|
|
9ca718d3bf |
||
|
|
1dee3df8d2 |
||
|
|
a5ad31d6a1 |
||
|
|
6e928567d7 |
||
|
|
4e0504ee08 |
||
|
|
8d3c67de8e |
||
|
|
6c3c2f2c1c |
||
|
|
376d25a97f |
||
|
|
f808768d15 |
||
|
|
fe10465874 |
||
|
|
fa2e9d605c |
||
|
|
58077d3c7e |
||
|
|
a90bcbc653 |
||
|
|
f0a59d8853 |
||
|
|
5ef0c079ce |
||
|
|
eb43c7b3fd | ||
|
|
e3f713f2d8 |
||
|
|
423acdda6f | ||
|
|
0ddb86cf03 | ||
|
|
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 |
48 changed files with 138781 additions and 63695 deletions
2
.github/workflows/canary.yml
vendored
2
.github/workflows/canary.yml
vendored
|
|
@ -22,7 +22,7 @@ jobs:
|
|||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v1
|
||||
- uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v1
|
||||
with:
|
||||
egress-policy: audit
|
||||
allowed-endpoints:
|
||||
|
|
|
|||
23
.github/workflows/code-review.yml
vendored
23
.github/workflows/code-review.yml
vendored
|
|
@ -1,23 +0,0 @@
|
|||
name: Code Review
|
||||
on:
|
||||
pull_request:
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
code-review:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
|
||||
with:
|
||||
disable-sudo: true
|
||||
egress-policy: block
|
||||
allowed-endpoints: >
|
||||
api.github.com:443
|
||||
int.api.stepsecurity.io:443
|
||||
|
||||
- name: Code Review
|
||||
uses: step-security/ai-codewise@int
|
||||
8
.github/workflows/codeql-analysis.yml
vendored
8
.github/workflows/codeql-analysis.yml
vendored
|
|
@ -41,7 +41,7 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ jobs:
|
|||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@cdcdbb579706841c47f7063dda365e292e5cad7a
|
||||
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@cdcdbb579706841c47f7063dda365e292e5cad7a
|
||||
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@cdcdbb579706841c47f7063dda365e292e5cad7a
|
||||
uses: github/codeql-action/analyze@2d790406f505036ef40ecba973cc774a50395aac
|
||||
|
|
|
|||
2
.github/workflows/dependency-review.yml
vendored
2
.github/workflows/dependency-review.yml
vendored
|
|
@ -17,7 +17,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
|
|
|||
28
.github/workflows/publish-immutable-actions.yml
vendored
Normal file
28
.github/workflows/publish-immutable-actions.yml
vendored
Normal file
|
|
@ -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
|
||||
4
.github/workflows/recurring-int-tests.yml
vendored
4
.github/workflows/recurring-int-tests.yml
vendored
|
|
@ -13,7 +13,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
|
|
|
|||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
|
@ -25,7 +25,7 @@ jobs:
|
|||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6
|
||||
- uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde
|
||||
with:
|
||||
egress-policy: audit
|
||||
allowed-endpoints:
|
||||
|
|
|
|||
179
.github/workflows/runs-on.yml
vendored
Normal file
179
.github/workflows/runs-on.yml
vendored
Normal file
|
|
@ -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
|
||||
|
||||
|
||||
8
.github/workflows/scorecards.yml
vendored
8
.github/workflows/scorecards.yml
vendored
|
|
@ -25,7 +25,7 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ jobs:
|
|||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914e534 # tag=v1.1.1
|
||||
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # tag=v1.1.1
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
|
|
@ -54,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@0b2256b8c012f0828dc542b3febcab082c67f72b # tag=v3.0.0
|
||||
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # tag=v4.6.1
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
|
|
@ -62,6 +62,6 @@ jobs:
|
|||
|
||||
# Upload the results to GitHub's code scanning dashboard.
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@cdcdbb579706841c47f7063dda365e292e5cad7a # tag=v1.0.26
|
||||
uses: github/codeql-action/upload-sarif@2d790406f505036ef40ecba973cc774a50395aac # tag=v1.0.26
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
|
|
|||
33
.github/workflows/test.yml
vendored
33
.github/workflows/test.yml
vendored
|
|
@ -19,7 +19,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
|
||||
uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
|
||||
with:
|
||||
disable-sudo: true
|
||||
egress-policy: audit
|
||||
|
|
@ -39,8 +39,37 @@ jobs:
|
|||
run: npm test -- --coverage
|
||||
- uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
|
||||
- name: Publish Test Results
|
||||
uses: step-security/publish-unit-test-result-action@v1
|
||||
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
|
||||
|
|
|
|||
477
README.md
477
README.md
|
|
@ -1,7 +1,7 @@
|
|||
<p align="center">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="images/banner.png" width="400">
|
||||
<img alt="Dark Banner" src="images/banner-dark.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,54 +13,134 @@
|
|||
|
||||
</div>
|
||||
|
||||
## Table of Contents
|
||||
# Harden-Runner
|
||||
|
||||
- [Introduction](#introduction)
|
||||
- [3,500+ open source projects use Harden-Runner](#3500-open-source-projects-use-harden-runner)
|
||||
- [Trusted By](#trusted-by)
|
||||
- [Case Studies](#case-studies)
|
||||
- [Why use Harden-Runner](#why-use-harden-runner)
|
||||
- [Getting Started](#getting-started)
|
||||
- [Hardening GitHub-Hosted Runners](#hardening-github-hosted-runners)
|
||||
- [Hands-On Tutorials](#hands-on-tutorials)
|
||||
- [Support for Private Repositories](#support-for-private-repositories)
|
||||
- [Hardening Self-Hosted Runners](#hardening-self-hosted-runners)
|
||||
- [Self-Hosted Actions Runner Controller (ARC) Runners](#self-hosted-actions-runner-controller-arc-runners)
|
||||
- [Self-Hosted VM Runners (e.g. on EC2)](#self-hosted-vm-runners-eg-on-ec2)
|
||||
- [Features at a glance](#features-at-a-glance)
|
||||
- [View outbound network traffic at the job level](#view-outbound-network-traffic-at-the-job-level)
|
||||
- [View outbound network traffic at the organization level](#view-outbound-network-traffic-at-the-organization-level)
|
||||
- [View outbound HTTPS traffic at the job level](#view-outbound-https-traffic-at-the-job-level)
|
||||
- [Detect anomalous outbound network traffic](#detect-anomalous-outbound-network-traffic)
|
||||
- [Filter outbound network traffic to allowed endpoints](#filter-outbound-network-traffic-to-allowed-endpoints)
|
||||
- [Determine minimum GITHUB_TOKEN permissions using Harden-Runner](#determine-minimum-github_token-permissions-using-harden-runner)
|
||||
- [View the name and path of every file written during the build process](#view-the-name-and-path-of-every-file-written-during-the-build-process)
|
||||
- [View process names and arguments](#view-process-names-and-arguments)
|
||||
- [Detect tampering of source code during build](#detect-tampering-of-source-code-during-build)
|
||||
- [Run your job without sudo access](#run-your-job-without-sudo-access)
|
||||
- [Get real-time security alerts](#get-real-time-security-alerts)
|
||||
- [Discussions](#discussions)
|
||||
- [How does it work?](#how-does-it-work)
|
||||
- [GitHub-Hosted Runners](#github-hosted-runners-1)
|
||||
- [Self-Hosted Actions Runner Controller (ARC) Runners](#self-hosted-actions-runner-controller-arc-runners-1)
|
||||
- [Self-Hosted VM Runners (e.g. on EC2)](#self-hosted-vm-runners-eg-on-ec2-1)
|
||||
- [Limitations](#limitations)
|
||||
- [GitHub-Hosted Runners](#github-hosted-runners-2)
|
||||
- [Self-Hosted Actions Runner Controller (ARC) Runners](#self-hosted-actions-runner-controller-arc-runners-2)
|
||||
- [Self-Hosted VM Runners (e.g. on EC2)](#self-hosted-vm-runners-eg-on-ec2-2)
|
||||
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, with support for Linux, Windows, and macOS 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 Compromised axios npm Package Dropping a Remote Access Trojan](https://www.stepsecurity.io/blog/axios-compromised-on-npm-malicious-versions-drop-remote-access-trojan) ([backstage/backstage#33693](https://github.com/backstage/backstage/issues/33693), [block/elasticgraph#1103](https://github.com/block/elasticgraph/issues/1103))
|
||||
- [Harden-Runner Detected the Trivy Compromise with Malicious v0.69.4 Release](https://www.stepsecurity.io/blog/trivy-compromised-a-second-time---malicious-v0-69-4-release) ([k8gb-io/k8gb#2294](https://github.com/k8gb-io/k8gb/issues/2294))
|
||||
- [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 the Sha1-Hulud Supply Chain Attack in CNCF’s Backstage Repository](https://www.stepsecurity.io/blog/how-harden-runner-detected-the-sha1-hulud-supply-chain-attack-in-cncfs-backstage-repository)
|
||||
- [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 Google’s Open-Source Project Flank](https://www.stepsecurity.io/case-studies/flank)
|
||||
- [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 **25 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)
|
||||
|
||||
---
|
||||
|
||||
## Introduction
|
||||
|
||||
Harden-Runner provides network egress filtering and runtime security for GitHub-hosted and self-hosted runners. It is called Harden-Runner because it `hardens` the `runner` on which GitHub Actions workflows run.
|
||||
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).
|
||||
|
||||
Learn how Harden-Runner works through the video below, which shows how it detected a supply chain attack on a Google open-source project.
|
||||
<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>
|
||||
|
||||
<a href="https://youtu.be/Yz72qAOrN9s" target="_blank"><img src="images/case-study-thumbnail1.png" alt="Harden-Runner detected supply chain attack in a Google open-source project" title="This case study video shows how StepSecurity Harden-Runner detected a CI/CD supply chain attack in real-time in Google’s open-source project Flank"></a>
|
||||
---
|
||||
## Getting Started
|
||||
|
||||
## 3,500+ open source projects use Harden-Runner
|
||||
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).
|
||||
|
||||
Harden-Runner is trusted by leading open source projects and enterprises to secure their CI/CD pipelines.
|
||||
### **Step 1: Add Harden-Runner to Your Workflow**
|
||||
|
||||
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:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
**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>
|
||||
|
||||
### **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>
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
## Why Choose Harden-Runner?
|
||||
|
||||
- **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.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
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).
|
||||
|
||||
### Community (Free)
|
||||
|
||||
- **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.
|
||||
|
||||
### Enterprise (Paid)
|
||||
|
||||
Includes all features in the **Community** tier, plus:
|
||||
|
||||
- **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.
|
||||
|
||||
For a detailed comparison and more information, please visit our [Pricing Page](https://www.stepsecurity.io/pricing).
|
||||
|
||||
Explore the full feature set in the [Features Documentation](https://docs.stepsecurity.io/harden-runner).
|
||||
|
||||
---
|
||||
|
||||
## Trusted By and Case Studies
|
||||
|
||||
Harden-Runner is trusted by over 11,000 leading open-source projects and enterprises, including Microsoft, Google, Kubernetes, and more.
|
||||
|
||||
### Trusted by
|
||||
|
||||
|
|
@ -69,304 +149,49 @@ Harden-Runner is trusted by leading open source projects and enterprises to secu
|
|||
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **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) |
|
||||
|
||||
### Case Studies
|
||||
### Enterprise Case Studies
|
||||
|
||||
- [Harden-Runner Detects CI/CD Supply Chain Attack in Google’s Open-Source Project Flank](https://www.stepsecurity.io/case-studies/flank)
|
||||
- [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)
|
||||
- [How Mercari Secures GitHub Actions with StepSecurity](https://www.stepsecurity.io/case-studies/mercari)
|
||||
- [How Omnissa Secures GitHub Actions with StepSecurity](https://www.stepsecurity.io/case-studies/omnissa)
|
||||
- [Chainguard Secures GitHub Actions with StepSecurity](https://www.stepsecurity.io/case-studies/chainguard)
|
||||
- [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)
|
||||
|
||||
---
|
||||
|
||||
## Why use Harden-Runner
|
||||
## Environment Compatibility Matrix
|
||||
|
||||
There are two main threats from compromised workflows, dependencies, and build tools in a CI/CD environment:
|
||||
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).
|
||||
|
||||
1. Exfiltration of CI/CD credentials and source code
|
||||
2. Tampering of source code, dependencies, or artifacts during the build to inject a backdoor
|
||||
| Environment Type | Compatibility | Audit Mode Deployment | Workflow Changes for Audit/Block Mode |
|
||||
|------------------|---------------|--------------------------|-------------------|
|
||||
| GitHub-hosted runners (Linux) | ✅ Full support | Add Harden-Runner Action to workflow | Yes |
|
||||
| GitHub-hosted runners (Windows, macOS) | ✅ Audit mode only | 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 |
|
||||
|
||||
Harden-Runner monitors process, file, and network activity to:
|
||||
## How It Works
|
||||
|
||||
| | Countermeasure | Prevent Security Breach |
|
||||
| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1. | Monitor and block outbound network traffic at the DNS, HTTPS (Layer 7), and network layers (Layers 3 and 4) to prevent exfiltration of code and CI/CD credentials | To prevent the [Codecov breach](https://github.com/step-security/github-actions-goat/blob/main/docs/Vulnerabilities/ExfiltratingCICDSecrets.md) scenario |
|
||||
| 2. | Detect if source code is being tampered during the build process to inject a backdoor | To detect the [XZ Utils](https://www.stepsecurity.io/blog/analysis-of-backdoored-xz-utils-build-process-with-harden-runner) and [SolarWinds incident](https://github.com/step-security/github-actions-goat/blob/main/docs/Vulnerabilities/TamperingDuringBuild.md) scenarios |
|
||||
| 3. | Detect poisoned workflows and compromised dependencies that exhibit suspicious behavior | To detect [Dependency confusion](https://github.com/step-security/github-actions-goat/blob/main/docs/Vulnerabilities/ExfiltratingCICDSecrets.md#dependency-confusion-attacks) and [Malicious dependencies](https://github.com/step-security/github-actions-goat/blob/main/docs/Vulnerabilities/ExfiltratingCICDSecrets.md#compromised-dependencies) scenarios |
|
||||
| 4. | Determine minimum GITHUB_TOKEN permissions by monitoring HTTPS calls to GitHub APIs | To set [minimum GITHUB_TOKEN permissions](https://www.stepsecurity.io/blog/determine-minimum-github-token-permissions-using-ebpf-with-stepsecurity-harden-runner) to reduce the impact of exfiltration |
|
||||
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).
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Hardening GitHub-Hosted Runners
|
||||
|
||||
1. Add the `step-security/harden-runner` GitHub Action to your GitHub Actions workflow file as the first step in each job. You can automate adding Harden-Runner Action to your workflow file by pasting your workflow in the [StepSecurity online tool](https://app.stepsecurity.io/secureworkflow).
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
|
||||
with:
|
||||
egress-policy: audit
|
||||
```
|
||||
|
||||
2. In the workflow logs and the job markdown summary, you will see a link to security insights and recommendations.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/buildlog1.png" alt="Link in build log" >
|
||||
</p>
|
||||
|
||||
3. Click on the link ([example link](https://app.stepsecurity.io/github/step-security/github-actions-goat/actions/runs/7704454287)). You will see a process monitor view of network and file events correlated with each step of the job.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/network-events1.png" alt="Insights from harden-runner" >
|
||||
</p>
|
||||
|
||||
4. In the `Recommended Policy` tab, you'll find a recommended block policy based on outbound calls aggregated from the current and past runs of the job. You can update your workflow file with this policy, or alternatively, use the [Policy Store](https://docs.stepsecurity.io/harden-runner/how-tos/block-egress-traffic#2-add-the-policy-using-the-policy-store) to apply the policy without modifying the workflow file. From now on, any outbound calls not in the allowed list will be blocked.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/recommended-policy1.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
|
||||
#### Hands-On Tutorials
|
||||
|
||||
You can use [GitHub Actions Goat](https://github.com/step-security/github-actions-goat) to try Harden-Runner. You only need a GitHub Account and a web browser.
|
||||
|
||||
Hands-on Tutorials for GitHub Actions Runtime Security:
|
||||
|
||||
1. [Filter Egress Network Traffic](https://github.com/step-security/github-actions-goat/blob/main/docs/Solutions/RestrictOutboundTraffic.md)
|
||||
2. [Detect File Tampering](https://github.com/step-security/github-actions-goat/blob/main/docs/Solutions/MonitorSourceCode.md)
|
||||
|
||||
### Support for Private Repositories
|
||||
|
||||
Hardening of runners used in private repositories is supported with a commercial license. Check out the [documentation](https://docs.stepsecurity.io/stepsecurity-platform/billing) for more details.
|
||||
|
||||
- To use Harden-Runner in a `Private` repository, you must install the [StepSecurity GitHub App](https://github.com/apps/stepsecurity-actions-security).
|
||||
- This is needed to access the GitHub Actions API and to authenticate users to access the dashboard for private repositories.
|
||||
- If you use Harden-Runner GitHub Action in a private repository, the generated insights URL is NOT public. Only those who have access to the repository can view it.
|
||||
|
||||
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 private repositories.
|
||||
|
||||
### Hardening Self-Hosted Runners
|
||||
|
||||
Hardening of self-hosted runners is supported with a commercial license. Check out the [documentation](https://docs.stepsecurity.io/stepsecurity-platform/billing) for more details. For hardening of self-hosted runners you must install the [StepSecurity GitHub App](https://github.com/apps/stepsecurity-actions-security).
|
||||
|
||||
#### Self-Hosted Actions Runner Controller (ARC) Runners
|
||||
|
||||
> Explore demo workflows using self-hosted ARC Runner and ARC Harden-Runner [here](https://docs.stepsecurity.io/harden-runner/how-tos/enable-runtime-security-arc).
|
||||
|
||||
Actions Runner Controller (ARC) is a Kubernetes operator that orchestrates self-hosted runners for GitHub Actions.
|
||||
|
||||
- Instead of adding the Harden-Runner GitHub Action in each job, you'll need to install the ARC Harden-Runner daemonset on your Kubernetes cluster.
|
||||
- Upon installation, the ARC Harden-Runner daemonset monitors all jobs run on the cluster; you do NOT need to add the Harden-Runner GitHub Action to each job for `audit` mode. You do need to add the Harden-Runner GitHub Action to jobs where you want to enable `block` mode.
|
||||
- The instructions for installing the ARC-Harden-Runner daemonset are shown in the dashboard. To enable access to these instructions, please email support@stepsecurity.io.
|
||||
|
||||
#### Self-Hosted VM Runners (e.g. on EC2)
|
||||
|
||||
> Explore demo workflows using self-hosted VM Runners and Harden-Runner [here](https://docs.stepsecurity.io/harden-runner/how-tos/enable-runtime-security-vm).
|
||||
|
||||
- Instead of adding the Harden-Runner GitHub Action in each job, you'll need to install the Harden-Runner agent on your runner image (e.g. AMI). This is typically done using packer or as a post-install step when using the https://github.com/philips-labs/terraform-aws-github-runner project to setup runners.
|
||||
- The Harden-Runner agent monitors all jobs run on the VM, both ephemeral and persistent runners are supported; you do NOT need to add the Harden-Runner GitHub Action to each job for `audit` mode. You do need to add the Harden-Runner GitHub Action to jobs where you want to enable `block` mode.
|
||||
- The instructions for installing the Harden-Runner agent on your self-hosted VM runners are shown in the dashboard. To enable access to these instructions, please email support@stepsecurity.io. This agent is different than the one used for GitHub-hosted runners.
|
||||
|
||||
## Features at a glance
|
||||
|
||||
For details, check out the documentation at https://docs.stepsecurity.io
|
||||
|
||||
### View outbound network traffic at the job level
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
Harden-Runner monitors all outbound traffic from each job at the DNS and network layers
|
||||
|
||||
- After the workflow completes, each outbound call is correlated with each step of the job, and shown in the insights page
|
||||
- For self-hosted runners, no changes are needed to workflow files to monitor egress traffic
|
||||
- A filtering (block) egress policy is suggested in the insights page based on the current and past job runs
|
||||
|
||||
<p align="left">
|
||||
<img src="images/network-events1.png" alt="Insights from harden-runner" >
|
||||
</p>
|
||||
|
||||
### View outbound network traffic at the organization level
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
You can view all unique network destinations from all workflow runs in your organization on the `Runtime Security` tab.
|
||||
|
||||
- The `All Observed Endpoints` menu provides a detailed list of all network destinations contacted by your Actions runners.
|
||||
- For each listed endpoint, the `View Sample Workflow Runs` option enables you to examine individual GitHub Actions workflow runs that interacted with the endpoint.
|
||||
|
||||
For more details refer [Unified Network Egress View: Centralize GitHub Actions Network Destinations for Your Enterprise](https://www.stepsecurity.io/blog/unified-network-egress-view-centralize-github-actions-network-destinations-for-your-enterprise)
|
||||
|
||||
<p align="left">
|
||||
<img src="images/org-level.png" width="400" alt="View outbound network traffic at the organization level" >
|
||||
</p>
|
||||
|
||||
### View outbound HTTPS traffic at the job level
|
||||
|
||||
> Applies to GitHub-hosted and self-hosted VM runners
|
||||
|
||||
Harden-Runner can monitor outbound HTTPS requests. This feature is supported with a commercial license.
|
||||
|
||||
- HTTPS events are monitored using eBPF (no MITM proxy is used)
|
||||
- If a HTTP PUT/ POST/ PATCH call is made to GitHub APIs to a HTTP Path with a different organization than where the workflow is running, the call is marked as anomalous
|
||||
- As of now, only HTTPS calls to `github.com`, `api.github.com`, `*.pkg.github.com`, and `ghcr.io` hosts are monitoried.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/https-events.png" alt="View outbound HTTPS traffic at the job level" >
|
||||
</p>
|
||||
|
||||
### Detect anomalous outbound network traffic
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
You can detect suspicious/ anomalous traffic using this feature even in `egress-policy:audit` mode.
|
||||
|
||||
- Anomaly detection feature creates a machine learning model of outbound network calls by analyzing the historical data of the same workflow in previous runs
|
||||
- After the baseline is created, any anomalous outbound destinations are marked as anomalous in the insights page, and real-time alerts are triggered
|
||||
- You can view the list of all anomalous outbound network traffic in the `Runtime detections` page on the dashboard
|
||||
|
||||
For more details, refer to [Anomalous Outbound Call Detection Using Machine Learning](https://www.stepsecurity.io/blog/announcing-anomalous-outbound-call-detection-using-machine-learning)
|
||||
|
||||
### Filter outbound network traffic to allowed endpoints
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
You can see recommended egress block policy in the `Recommendations` tab for each job. This is based on observed traffic across multiple runs of the job.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/recommended-policy1.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
|
||||
Once you set these allowed endpoints in the workflow file, or in the [Policy Store](https://docs.stepsecurity.io/harden-runner/how-tos/block-egress-traffic#2-add-the-policy-using-the-policy-store) and switch to using `egress-policy:block`
|
||||
|
||||
- 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
|
||||
- Wildcard domains are supported, e.g. you can add `*.data.mcr.microsoft.com:443` to the allowed list, and egress traffic will be allowed to `eastus.data.mcr.microsoft.com:443` and `westus.data.mcr.microsoft.com:443`
|
||||
|
||||
<p align="left">
|
||||
<img src="images/blocked-outbound-call-3.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
|
||||
### Determine minimum GITHUB_TOKEN permissions using Harden-Runner
|
||||
|
||||
> Applies to GitHub-hosted runners
|
||||
|
||||
Harden-Runner monitors outbound HTTPS requests using eBPF and uses the PATHs and VERBs of these HTTPS calls to recommend the minimum GITHUB_TOKEN permissions for each job in your workflow. This feature is supported with a commercial license.
|
||||
|
||||
- GITHUB_TOKEN is an automatically generated secret used to authenticate to GitHub APIs from GitHub Actions workflows.
|
||||
- Harden-Runner can monitor the VERBs (e.g., `GET`, `POST`) and PATHs (e.g., `/repos/owner/repo/issues`) for calls made to the GitHub APIs from the runner.
|
||||
- Each GitHub Actions API call requires a corresponding GITHUB_TOKEN permission. For instance, a GET request to the `/repos/org/repo/info/refs?service=git-upload-pack` endpoint requires the `contents: read` permission.
|
||||
- The recommendation for the minimum GITHUB_TOKEN permissions are show in the `Recommendations` tab.
|
||||
|
||||
For more details, refer to [Determine Minimum GITHUB_TOKEN Permissions Using eBPF with Harden-Runner.
|
||||
](https://www.stepsecurity.io/blog/determine-minimum-github-token-permissions-using-ebpf-with-stepsecurity-harden-runner)
|
||||
|
||||
<p align="left">
|
||||
<img src="images/token-perms-recommendation.png" alt="View recommendation for minimum GITHUB_TOKEN permissions" >
|
||||
</p>
|
||||
|
||||
### View the name and path of every file written during the build process
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
View the name and path of every file that was written during the build process. This feature is supported with a commercial license.
|
||||
|
||||
- Harden-Runner tracks every file written to the GitHub Actions working directory during the build process.
|
||||
- In the insights page in the `File Write Events` tab you can see a file explorer view of each file that was written to.
|
||||
- Clicking on any file reveals a list of processes that wrote to it, providing complete transparency.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/file-write-events.png" alt="View the name and path of every file written during the build process" >
|
||||
</p>
|
||||
|
||||
### View process names and arguments
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
View process names, PIDs, and process arguments. This feature is supported with a commercial license.
|
||||
|
||||
- Harden-Runner tracks every process that is run during the build process.
|
||||
- Clicking on any process ID (PID) in the network events, file events, or HTTPS events shows the process that caused the event, along with the process arguments.
|
||||
- You can walk up the process tree by clicking `View Parent Process` to understand the build process and detect suspicious activity.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/process-events-3.png" alt="View process names and arguments" >
|
||||
</p>
|
||||
|
||||
### Detect tampering of source code during build
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
Harden-Runner monitors file writes and can detect if a file is overwritten.
|
||||
|
||||
- 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
|
||||
- For self-hosted runners, no changes are needed to workflow files for file monitoring
|
||||
|
||||
<p align="left">
|
||||
<img src="images/file-events.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
|
||||
### Run your job without sudo access
|
||||
|
||||
> Applies to GitHub-hosted runners
|
||||
|
||||
GitHub-hosted runner uses passwordless sudo for running jobs.
|
||||
|
||||
- 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 GitHub-hosted Ubuntu VM
|
||||
|
||||
<p align="left">
|
||||
<img src="images/recommended-policy1.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
|
||||
### Get real-time security alerts
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
Install the [StepSecurity GitHub App](https://github.com/apps/stepsecurity-actions-security) to get security alerts/ notifications.
|
||||
|
||||
- Email, Slack, and Teams notifications are supported
|
||||
- Notifications are sent when anomalous outbound network/ HTTPS traffic is detected, outbound traffic is blocked, or source code is overwritten
|
||||
- Notifications are not repeated for the same alert for a given workflow
|
||||
|
||||
## Discussions
|
||||
|
||||
- If you have questions or ideas, please use [discussions](https://github.com/step-security/harden-runner/discussions).
|
||||
- For support for self-hosted runners and private repositories, email support@stepsecurity.io.
|
||||
- If you use a different CI/CD Provider (e.g. Jenkins, Gitlab CI, etc), and would like to use Harden Runner in your environment, please email interest@stepsecurity.io
|
||||
|
||||
## How does it work?
|
||||
|
||||
### 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 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)
|
||||
|
||||
### 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).
|
||||
- Agent for self-hosted VMs is NOT open source.
|
||||
---
|
||||
|
||||
## Limitations
|
||||
|
||||
### GitHub-Hosted Runners
|
||||
While Harden-Runner offers powerful features, there are certain limitations. See the complete list in [Known Limitations](docs/limitations.md).
|
||||
|
||||
1. 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).
|
||||
2. 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`. Note: This is not a limitation for Self-Hosted runners.
|
||||
---
|
||||
|
||||
### Self-Hosted Actions Runner Controller (ARC) Runners
|
||||
## Discussions
|
||||
|
||||
1. Since ARC Harden Runner uses eBPF, only Linux jobs are supported. Windows and MacOS jobs are not supported.
|
||||
Join the conversation! For questions, ideas, or feedback, visit our [Discussions Page](https://github.com/step-security/harden-runner/discussions).
|
||||
|
||||
### Self-Hosted VM Runners (e.g. on EC2)
|
||||
For enterprise support, email support@stepsecurity.io. Interested in using Harden-Runner in other CI/CD platforms? Reach out to interest@stepsecurity.io.
|
||||
|
||||
1. Only Ubuntu VM is supported. Windows and MacOS jobs are not supported.
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
Harden-Runner is open source. See the [LICENSE](LICENSE) file for details.
|
||||
|
|
|
|||
22
action.yml
22
action.yml
|
|
@ -17,7 +17,11 @@ 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:
|
||||
|
|
@ -25,15 +29,27 @@ inputs:
|
|||
required: false
|
||||
default: "false"
|
||||
policy:
|
||||
description: "Policy name to be used from the policy store"
|
||||
description: "Policy name to be used from the policy store. Requires id-token: write permission."
|
||||
required: false
|
||||
default: ""
|
||||
api-key:
|
||||
description: "StepSecurity API key for authenticating with the policy store. Required when use-policy-store is set to true."
|
||||
required: false
|
||||
default: ""
|
||||
use-policy-store:
|
||||
description: "Set to true to fetch policy from the policy store using the API key. This is the preferred method over the policy input which requires id-token: write permission. Policies can be defined and attached at workflow, repo, org, or cluster (for ARC) level in the policy store. The most granular policy will apply."
|
||||
required: false
|
||||
default: "false"
|
||||
deploy-on-self-hosted-vm:
|
||||
description: "Set to true to deploy the Harden Runner agent directly on a self-hosted runner VM (Linux only). The recommended approach for self-hosted VMs is to bake the agent into the VM image; see docs.stepsecurity.io. Use this option only if baking is not possible, and only for ephemeral runners."
|
||||
required: false
|
||||
default: "false"
|
||||
|
||||
branding:
|
||||
icon: "check-square"
|
||||
color: "green"
|
||||
runs:
|
||||
using: "node20"
|
||||
using: "node24"
|
||||
pre: "dist/pre/index.js"
|
||||
main: "dist/index.js"
|
||||
post: "dist/post/index.js"
|
||||
|
|
|
|||
30715
dist/index.js
vendored
30715
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
31056
dist/post/index.js
vendored
31056
dist/post/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/post/index.js.map
vendored
2
dist/post/index.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/post/sourcemap-register.js
vendored
2
dist/post/sourcemap-register.js
vendored
File diff suppressed because one or more lines are too long
112741
dist/pre/index.js
vendored
112741
dist/pre/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/pre/index.js.map
vendored
2
dist/pre/index.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/pre/sourcemap-register.js
vendored
2
dist/pre/sourcemap-register.js
vendored
File diff suppressed because one or more lines are too long
2
dist/sourcemap-register.js
vendored
2
dist/sourcemap-register.js
vendored
File diff suppressed because one or more lines are too long
20
docs/how-it-works.md
Normal file
20
docs/how-it-works.md
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
## 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 for Linux is open-source and can be found [here](https://github.com/step-security/agent). The enterprise agent for Linux and agents for Windows and macOS are closed-source.
|
||||
|
||||
### 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.
|
||||
8
docs/limitations.md
Normal file
8
docs/limitations.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
## Limitations
|
||||
|
||||
### GitHub-Hosted Runners
|
||||
* 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.
|
||||
BIN
images/case-study.png
Normal file
BIN
images/case-study.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 407 KiB |
BIN
images/harden-runner-new.png
Normal file
BIN
images/harden-runner-new.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
BIN
images/network-events.png
Normal file
BIN
images/network-events.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 278 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 134 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 188 KiB |
15
osv-scanner.toml
Normal file
15
osv-scanner.toml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[[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"
|
||||
|
||||
[[IgnoredVulns]]
|
||||
id = "GHSA-g9mf-h72j-4rw9"
|
||||
reason = "undici fetch() is only used to call GitHub API; exploitation requires a malicious server"
|
||||
2458
package-lock.json
generated
2458
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -23,12 +23,13 @@
|
|||
},
|
||||
"homepage": "https://github.com/step-security/harden-runner#readme",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.1.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",
|
||||
|
|
@ -39,7 +40,7 @@
|
|||
"@types/node": "^16.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
||||
"@typescript-eslint/parser": "^6.1.0",
|
||||
"@vercel/ncc": "^0.30.0",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"jest": "^29.3.1",
|
||||
|
|
|
|||
|
|
@ -1,20 +1,9 @@
|
|||
import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
|
||||
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();
|
||||
let isArc: boolean = await isARCRunner();
|
||||
expect(isArc).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
it("should write endpoint files", ()=>{
|
||||
process.env["isTest"] = "1"
|
||||
|
||||
let allowed_endpoints = ["github.com:443", "*.google.com:443", "youtube.com"].join(" ");
|
||||
sendAllowedEndpoints(allowed_endpoints);
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import * as cp from "child_process";
|
||||
import * as fs from "fs";
|
||||
import { sleep } from "./setup";
|
||||
import path from "path";
|
||||
|
||||
export function isArcRunner(): boolean {
|
||||
export function isARCRunner(): boolean {
|
||||
const runnerUserAgent = process.env["GITHUB_ACTIONS_RUNNER_EXTRA_USER_AGENT"];
|
||||
|
||||
let isARC = false;
|
||||
|
|
@ -18,45 +18,40 @@ export function isArcRunner(): boolean {
|
|||
|
||||
function isSecondaryPod(): boolean {
|
||||
const workDir = "/__w";
|
||||
return fs.existsSync(workDir);
|
||||
}
|
||||
|
||||
function getRunnerTempDir(): string {
|
||||
const isTest = process.env["isTest"];
|
||||
|
||||
if (isTest === "1") {
|
||||
return "/tmp";
|
||||
}
|
||||
|
||||
return process.env["RUNNER_TEMP"] || "/tmp";
|
||||
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
|
||||
|
||||
for (const endpoint of allowedEndpoints) {
|
||||
if (endpoint) {
|
||||
const encodedEndpoint = Buffer.from(endpoint).toString("base64");
|
||||
cp.execSync(
|
||||
`echo "${endpoint}" > "${getRunnerTempDir()}/step_policy_endpoint_${encodedEndpoint}"`
|
||||
);
|
||||
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 (allowedEndpoints.length > 0) {
|
||||
applyPolicy(allowedEndpoints.length);
|
||||
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 {
|
||||
const fileName = `step_policy_apply_${count}`;
|
||||
cp.execSync(`echo "${fileName}" > "${getRunnerTempDir()}/${fileName}"`);
|
||||
let applyPolicyStr = `step_policy_apply_${count}`;
|
||||
echo(applyPolicyStr);
|
||||
}
|
||||
|
||||
export function removeStepPolicyFiles() {
|
||||
cp.execSync(`rm ${getRunnerTempDir()}/step_policy_*`);
|
||||
}
|
||||
|
||||
export function arcCleanUp() {
|
||||
cp.execSync(`echo "cleanup" > "${getRunnerTempDir()}/step_policy_cleanup"`);
|
||||
function echo(content: string) {
|
||||
cp.execFileSync("echo", [content]);
|
||||
}
|
||||
|
|
|
|||
81
src/bravo-config.test.ts
Normal file
81
src/bravo-config.test.ts
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
import { buildBravoConfig } from "./bravo-config";
|
||||
import { Configuration } from "./interfaces";
|
||||
|
||||
const base: Configuration = {
|
||||
repo: "org/repo",
|
||||
run_id: "123",
|
||||
correlation_id: "depot-abc",
|
||||
working_directory: "/w",
|
||||
api_url: "https://int.api.stepsecurity.io/v1",
|
||||
telemetry_url: "https://int.app-api.stepsecurity.io/v1",
|
||||
allowed_endpoints: "github.com:443",
|
||||
egress_policy: "audit",
|
||||
disable_telemetry: false,
|
||||
disable_sudo: false,
|
||||
disable_sudo_and_containers: false,
|
||||
disable_file_monitoring: false,
|
||||
is_github_hosted: false,
|
||||
private: "true" as unknown as string,
|
||||
is_debug: false,
|
||||
one_time_key: "otk-xyz",
|
||||
api_key: "tenant-key",
|
||||
use_policy_store: false,
|
||||
deploy_on_self_hosted_vm: false,
|
||||
};
|
||||
|
||||
describe("buildBravoConfig", () => {
|
||||
test("forces is_github_hosted=true so agent honors passed correlation_id", () => {
|
||||
expect(buildBravoConfig(base).is_github_hosted).toBe(true);
|
||||
});
|
||||
|
||||
test("omits api_key (agent authenticates via one_time_key, not vm-api-key)", () => {
|
||||
expect(buildBravoConfig(base)).not.toHaveProperty("api_key");
|
||||
});
|
||||
|
||||
test("omits customer (server infers tenant from repo)", () => {
|
||||
expect(buildBravoConfig(base)).not.toHaveProperty("customer");
|
||||
});
|
||||
|
||||
test("omits use_policy_store (action-side concern, not agent)", () => {
|
||||
expect(buildBravoConfig(base)).not.toHaveProperty("use_policy_store");
|
||||
});
|
||||
|
||||
test("forwards telemetry_url so network events hit configured env", () => {
|
||||
expect(buildBravoConfig(base).telemetry_url).toBe(base.telemetry_url);
|
||||
});
|
||||
|
||||
test("forwards one_time_key so agent can auth to presigned URL endpoint", () => {
|
||||
expect(buildBravoConfig(base).one_time_key).toBe("otk-xyz");
|
||||
});
|
||||
|
||||
test("forwards repo, run_id, correlation_id so server can attribute events", () => {
|
||||
const cfg = buildBravoConfig(base);
|
||||
expect(cfg.repo).toBe("org/repo");
|
||||
expect(cfg.run_id).toBe("123");
|
||||
expect(cfg.correlation_id).toBe("depot-abc");
|
||||
});
|
||||
|
||||
test("forwards private flag", () => {
|
||||
expect(buildBravoConfig(base).private).toBe(base.private);
|
||||
});
|
||||
|
||||
test("forwards egress_policy and allowed_endpoints", () => {
|
||||
const cfg = buildBravoConfig(base);
|
||||
expect(cfg.egress_policy).toBe("audit");
|
||||
expect(cfg.allowed_endpoints).toBe("github.com:443");
|
||||
});
|
||||
|
||||
test("forwards disable_* flags", () => {
|
||||
const cfg = buildBravoConfig({
|
||||
...base,
|
||||
disable_telemetry: true,
|
||||
disable_sudo: true,
|
||||
disable_sudo_and_containers: true,
|
||||
disable_file_monitoring: true,
|
||||
});
|
||||
expect(cfg.disable_telemetry).toBe(true);
|
||||
expect(cfg.disable_sudo).toBe(true);
|
||||
expect(cfg.disable_sudo_and_containers).toBe(true);
|
||||
expect(cfg.disable_file_monitoring).toBe(true);
|
||||
});
|
||||
});
|
||||
21
src/bravo-config.ts
Normal file
21
src/bravo-config.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { Configuration } from "./interfaces";
|
||||
|
||||
export function buildBravoConfig(confg: Configuration) {
|
||||
return {
|
||||
repo: confg.repo,
|
||||
run_id: confg.run_id,
|
||||
correlation_id: confg.correlation_id,
|
||||
working_directory: confg.working_directory,
|
||||
api_url: confg.api_url,
|
||||
telemetry_url: confg.telemetry_url,
|
||||
one_time_key: confg.one_time_key,
|
||||
allowed_endpoints: confg.allowed_endpoints,
|
||||
egress_policy: confg.egress_policy,
|
||||
disable_telemetry: confg.disable_telemetry,
|
||||
disable_sudo: confg.disable_sudo,
|
||||
disable_sudo_and_containers: confg.disable_sudo_and_containers,
|
||||
disable_file_monitoring: confg.disable_file_monitoring,
|
||||
private: confg.private,
|
||||
is_github_hosted: true,
|
||||
};
|
||||
}
|
||||
98
src/checksum.test.ts
Normal file
98
src/checksum.test.ts
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import * as fs from "fs";
|
||||
import * as crypto from "crypto";
|
||||
import * as core from "@actions/core";
|
||||
import { verifyChecksum, CHECKSUMS } from "./checksum";
|
||||
|
||||
jest.mock("fs", () => ({
|
||||
...jest.requireActual("fs"),
|
||||
readFileSync: jest.fn(),
|
||||
}));
|
||||
jest.mock("crypto", () => ({
|
||||
...jest.requireActual("crypto"),
|
||||
createHash: jest.fn(),
|
||||
}));
|
||||
jest.mock("@actions/core");
|
||||
|
||||
const mockReadFile = fs.readFileSync as jest.MockedFunction<typeof fs.readFileSync>;
|
||||
const mockSetFailed = core.setFailed as jest.MockedFunction<typeof core.setFailed>;
|
||||
const mockCreateHash = crypto.createHash as jest.MockedFunction<typeof crypto.createHash>;
|
||||
|
||||
function stubHash(hash: string) {
|
||||
mockCreateHash.mockReturnValue({
|
||||
update: jest.fn().mockReturnThis(),
|
||||
digest: jest.fn().mockReturnValue(hash),
|
||||
} as unknown as crypto.Hash);
|
||||
}
|
||||
|
||||
const WRONG_HASH = "0".repeat(64);
|
||||
|
||||
describe("verifyChecksum", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockReadFile.mockReturnValue(Buffer.from("test-payload"));
|
||||
});
|
||||
|
||||
describe("agentType=bravo", () => {
|
||||
test("passes with matching bravo amd64 checksum", () => {
|
||||
stubHash(CHECKSUMS.bravo.amd64);
|
||||
expect(verifyChecksum("/tmp/f", true, "amd64", "linux", "bravo")).toBe(true);
|
||||
expect(mockSetFailed).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("passes with matching bravo arm64 checksum", () => {
|
||||
stubHash(CHECKSUMS.bravo.arm64);
|
||||
expect(verifyChecksum("/tmp/f", true, "arm64", "linux", "bravo")).toBe(true);
|
||||
});
|
||||
|
||||
test("uses bravo checksum even when isTLS=false", () => {
|
||||
stubHash(CHECKSUMS.bravo.amd64);
|
||||
expect(verifyChecksum("/tmp/f", false, "amd64", "linux", "bravo")).toBe(true);
|
||||
});
|
||||
|
||||
test("fails on mismatched bravo checksum", () => {
|
||||
stubHash(WRONG_HASH);
|
||||
expect(verifyChecksum("/tmp/f", true, "amd64", "linux", "bravo")).toBe(false);
|
||||
expect(mockSetFailed).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("agentType default (omitted)", () => {
|
||||
test("uses TLS checksum when isTLS=true", () => {
|
||||
stubHash(CHECKSUMS.tls.amd64);
|
||||
expect(verifyChecksum("/tmp/f", true, "amd64", "linux")).toBe(true);
|
||||
});
|
||||
|
||||
test("uses non_tls checksum when isTLS=false", () => {
|
||||
stubHash(CHECKSUMS.non_tls.amd64);
|
||||
expect(verifyChecksum("/tmp/f", false, "amd64", "linux")).toBe(true);
|
||||
});
|
||||
|
||||
test("TLS mismatch fails", () => {
|
||||
stubHash(CHECKSUMS.bravo.amd64);
|
||||
expect(verifyChecksum("/tmp/f", true, "amd64", "linux")).toBe(false);
|
||||
expect(mockSetFailed).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("darwin", () => {
|
||||
test("passes with matching darwin checksum", () => {
|
||||
stubHash(CHECKSUMS.darwin);
|
||||
expect(verifyChecksum("/tmp/f", false, "", "darwin")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("win32", () => {
|
||||
test("passes with matching windows amd64 checksum", () => {
|
||||
stubHash(CHECKSUMS.windows.amd64);
|
||||
expect(verifyChecksum("/tmp/f", false, "amd64", "win32")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("unsupported platform", () => {
|
||||
test("returns false without calling setFailed", () => {
|
||||
stubHash(CHECKSUMS.bravo.amd64);
|
||||
expect(verifyChecksum("/tmp/f", true, "amd64", "freebsd")).toBe(false);
|
||||
expect(mockSetFailed).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -2,26 +2,68 @@ import * as core from "@actions/core";
|
|||
import * as crypto from "crypto";
|
||||
import * as fs from "fs";
|
||||
|
||||
export function verifyChecksum(downloadPath: string, is_tls: boolean) {
|
||||
export const CHECKSUMS = {
|
||||
tls: {
|
||||
amd64: "d58a9c1c5245155ce4c71507a61e213a29925a7c39c0d20bfd00bef0d281bdbb", // v1.8.6
|
||||
arm64: "084fa95e74d17321dd1c37c93abeb8577e53ddf5266410e19f52aa79a02ae33e",
|
||||
},
|
||||
non_tls: {
|
||||
amd64: "e38de61e1afd98dd339bb9acce4996183875d482be1638fb198ab02b3e25bbef", // v0.16.0
|
||||
},
|
||||
bravo: {
|
||||
amd64: "495f607a891d89f12214849301f247bdca565afe67deb170fe7e5d6d361852ca", // v1.8.6
|
||||
arm64: "f96f66ab946097aae1fc887e12fe1cefcc5d510bce179221c7185374e4adf538",
|
||||
},
|
||||
darwin: "fe26a1f6af4afe9f1a854d8633832f5d18ab542827003cae445b3a64021d612c", // v0.0.5
|
||||
windows: {
|
||||
amd64: "93f1e5d87c6647e6eca7963d5f4b4bd73107029430f8e6945ffece93007a89f5", // v1.0.2
|
||||
},
|
||||
};
|
||||
|
||||
// verifyChecksum returns true if checksum is valid
|
||||
export function verifyChecksum(
|
||||
downloadPath: string,
|
||||
isTLS: boolean,
|
||||
variant: string,
|
||||
platform: string,
|
||||
agentType: "default" | "bravo" = "default"
|
||||
) {
|
||||
const fileBuffer: Buffer = fs.readFileSync(downloadPath);
|
||||
const checksum: string = crypto
|
||||
.createHash("sha256")
|
||||
.update(fileBuffer)
|
||||
.digest("hex"); // checksum of downloaded file
|
||||
|
||||
let expectedChecksum: string =
|
||||
"a9f1842e3d7f3d38c143dbe8ffe1948e6c8173cd04da072d9f9d128bb400844a"; // checksum for v0.13.7
|
||||
let expectedChecksum: string = "";
|
||||
|
||||
if (is_tls) {
|
||||
expectedChecksum =
|
||||
"e45b85e29216eb1d217aad368bdb056bbd868a308925e7b2cf9133b06ab435d0"; // checksum for tls_agent
|
||||
switch (platform) {
|
||||
case "linux":
|
||||
if (agentType === "bravo") {
|
||||
expectedChecksum = CHECKSUMS["bravo"][variant];
|
||||
} else {
|
||||
expectedChecksum = isTLS
|
||||
? CHECKSUMS["tls"][variant]
|
||||
: CHECKSUMS["non_tls"][variant];
|
||||
}
|
||||
break;
|
||||
case "darwin":
|
||||
expectedChecksum = CHECKSUMS["darwin"];
|
||||
break;
|
||||
case "win32":
|
||||
expectedChecksum = CHECKSUMS["windows"][variant];
|
||||
break;
|
||||
default:
|
||||
console.log(`Unsupported platform: ${platform}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (checksum !== expectedChecksum) {
|
||||
core.setFailed(
|
||||
`Checksum verification failed, expected ${expectedChecksum} instead got ${checksum}`
|
||||
`❌ Checksum verification failed, expected ${expectedChecksum} instead got ${checksum}`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
core.debug("Checksum verification passed.");
|
||||
core.info(`✅ Checksum verification passed. checksum=${checksum}`);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
294
src/cleanup.ts
294
src/cleanup.ts
|
|
@ -1,30 +1,51 @@
|
|||
import * as fs from "fs";
|
||||
import * as cp from "child_process";
|
||||
import * as common from "./common";
|
||||
import * as cp from "child_process";
|
||||
import * as path from "path";
|
||||
import isDocker from "is-docker";
|
||||
import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
||||
import { isARCRunner } from "./arc-runner";
|
||||
import { isGithubHosted } from "./tls-inspect";
|
||||
import { context } from "@actions/github";
|
||||
import { isPlatformSupported, isAgentInstalled, detectThirdPartyRunnerProvider } from "./utils";
|
||||
|
||||
(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()) {
|
||||
|
||||
if (!isPlatformSupported(process.platform)) {
|
||||
console.log(common.UNSUPPORTED_RUNNER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (isGithubHosted() && isDocker()) {
|
||||
console.log(common.CONTAINER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isArcRunner()) {
|
||||
console.log(`[!] ${common.ARC_RUNNER_MESSAGE}`);
|
||||
arcCleanUp();
|
||||
removeStepPolicyFiles();
|
||||
if (isGithubHosted() && process.platform === "linux" && !process.env.USER) {
|
||||
console.log(common.UBUNTU_SLIM_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isARCRunner()) {
|
||||
console.log(`[!] ${common.ARC_RUNNER_MESSAGE}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const thirdPartyProvider = detectThirdPartyRunnerProvider();
|
||||
|
||||
if (process.env.STATE_selfHosted === "true") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.STATE_customVMImage === "true") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
String(process.env.STATE_monitorStatusCode) ===
|
||||
common.STATUS_HARDEN_RUNNER_UNAVAILABLE
|
||||
|
|
@ -33,6 +54,71 @@ import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
|||
return;
|
||||
}
|
||||
|
||||
switch (process.platform) {
|
||||
case "linux":
|
||||
if (thirdPartyProvider) {
|
||||
await handleAgentBravoCleanup();
|
||||
} else {
|
||||
await handleLinuxCleanup();
|
||||
}
|
||||
break;
|
||||
case "win32":
|
||||
await handleWindowsCleanup();
|
||||
break;
|
||||
case "darwin":
|
||||
await handleMacosCleanup();
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
await common.addSummary();
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
})();
|
||||
|
||||
async function handleAgentBravoCleanup() {
|
||||
cp.execFileSync("/usr/bin/echo", ["step_policy_jobend"]);
|
||||
|
||||
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);
|
||||
} else {
|
||||
console.log(fs.readFileSync(doneFile, "utf-8"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const log = "/home/agent/agent.log";
|
||||
if (fs.existsSync(log)) {
|
||||
console.log("log:");
|
||||
console.log(fs.readFileSync(log, "utf-8"));
|
||||
}
|
||||
|
||||
const status = "/home/agent/agent.status";
|
||||
if (fs.existsSync(status)) {
|
||||
console.log("status:");
|
||||
console.log(fs.readFileSync(status, "utf-8"));
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLinuxCleanup() {
|
||||
if (process.env.STATE_isTLS === "false" && process.arch === "arm64") {
|
||||
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" })
|
||||
|
|
@ -49,8 +135,8 @@ import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
|||
break;
|
||||
}
|
||||
await sleep(1000);
|
||||
} // The file *does* exist
|
||||
else {
|
||||
} else {
|
||||
// The file *does* exist
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -77,20 +163,184 @@ import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
|||
}
|
||||
|
||||
var disable_sudo = process.env.STATE_disableSudo;
|
||||
if (disable_sudo !== "true") {
|
||||
var journalLog = cp.execSync("sudo journalctl -u agent.service", {
|
||||
encoding: "utf8",
|
||||
});
|
||||
console.log("Service log:");
|
||||
console.log(journalLog);
|
||||
var disable_sudo_and_containers = process.env.STATE_disableSudoAndContainers;
|
||||
|
||||
if (disable_sudo !== "true" && disable_sudo_and_containers !== "true") {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handleMacosCleanup() {
|
||||
const post_event = "/opt/step-security/post_event.json";
|
||||
|
||||
if (isGithubHosted() && fs.existsSync(post_event)) {
|
||||
console.log("Post step already executed, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await common.addSummary();
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
fs.writeFileSync(post_event, JSON.stringify({ event: "post" }));
|
||||
|
||||
// if agent is installed; wait for it to create done.json
|
||||
if (isAgentInstalled(process.platform)) {
|
||||
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 macAgentLog = "/opt/step-security/agent.log";
|
||||
if (fs.existsSync(macAgentLog)) {
|
||||
console.log("macAgentLog:");
|
||||
var content = fs.readFileSync(macAgentLog, "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: 5000, // 5 seconds timeout
|
||||
}
|
||||
);
|
||||
console.log(logStreamOutput);
|
||||
} catch (error) {
|
||||
console.log("Warning: Could not fetch system log stream:", error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleWindowsCleanup() {
|
||||
// windows cleanup
|
||||
const agentDir = process.env.STATE_agentDir || "C:\\agent";
|
||||
const postEventFile = path.join(agentDir, "post_event.json");
|
||||
|
||||
if (isGithubHosted() && fs.existsSync(postEventFile)) {
|
||||
console.log("Windows post step already executed, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.arch === "arm64") {
|
||||
console.log(common.ARM64_WINDOWS_RUNNER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
const p = cp.spawn(
|
||||
"powershell.exe",
|
||||
[
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-Command",
|
||||
"query user; exit $LASTEXITCODE",
|
||||
],
|
||||
{ stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true }
|
||||
);
|
||||
p.unref();
|
||||
|
||||
fs.writeFileSync(postEventFile, JSON.stringify({ event: "post" }));
|
||||
|
||||
// if agent is installed; wait for it to create done.json
|
||||
if (isAgentInstalled(process.platform)) {
|
||||
const doneFile = path.join(agentDir, "done.json");
|
||||
let counter = 0;
|
||||
while (true) {
|
||||
if (!fs.existsSync(doneFile)) {
|
||||
counter++;
|
||||
if (counter > 10) {
|
||||
console.log("timed out");
|
||||
break;
|
||||
}
|
||||
await sleep(1000);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("stopping windows agent process...");
|
||||
const pidFile = path.join(agentDir, "agent.pid");
|
||||
|
||||
try {
|
||||
if (!fs.existsSync(pidFile)) {
|
||||
console.log("PID file not found. Agent may not be running.");
|
||||
return;
|
||||
}
|
||||
|
||||
const pid = parseInt(fs.readFileSync(pidFile, "utf8").trim());
|
||||
console.log(`agent PID from file: ${pid}`);
|
||||
|
||||
try {
|
||||
process.kill(pid, 0); // signal 0 just checks if process exists
|
||||
} catch {
|
||||
console.log("agent process not running.");
|
||||
fs.unlinkSync(pidFile);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`stopping agent process (PID: ${pid})...`);
|
||||
process.kill(pid, "SIGINT");
|
||||
|
||||
let gracefulShutdown = false;
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await sleep(1000);
|
||||
|
||||
try {
|
||||
process.kill(pid, 0); // check if still exists
|
||||
} catch {
|
||||
gracefulShutdown = true;
|
||||
console.log("agent process stopped gracefully");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!gracefulShutdown) {
|
||||
console.log("graceful shutdown timeout (10s), forcing termination...");
|
||||
process.kill(pid, "SIGKILL");
|
||||
console.log("agent process terminated forcefully");
|
||||
}
|
||||
|
||||
if (fs.existsSync(pidFile)) {
|
||||
fs.unlinkSync(pidFile);
|
||||
console.log("PID file cleaned up");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("warning: error stopping agent process:", error.message);
|
||||
}
|
||||
|
||||
const log = path.join(agentDir, "agent.log");
|
||||
if (fs.existsSync(log)) {
|
||||
console.log("agent log:");
|
||||
const content = fs.readFileSync(log, "utf-8");
|
||||
console.log(content);
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
|
|
|
|||
129
src/common.ts
129
src/common.ts
|
|
@ -1,6 +1,6 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as fs from "fs";
|
||||
import { STEPSECURITY_WEB_URL } from "./configs";
|
||||
import { STEPSECURITY_API_URL, STEPSECURITY_WEB_URL } from "./configs";
|
||||
import { getAnnotationLogs } from "./utils";
|
||||
|
||||
export function printInfo(web_url) {
|
||||
console.log(
|
||||
|
|
@ -35,8 +35,15 @@ export const processLogLine = (
|
|||
if (matches) {
|
||||
const [ipAddress, domain, pid, process] = matches.slice(1);
|
||||
|
||||
// Check if all values are non-empty
|
||||
if (pid && process && domain && ipAddress) {
|
||||
// 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";
|
||||
|
|
@ -52,18 +59,19 @@ export async function addSummary() {
|
|||
return;
|
||||
}
|
||||
|
||||
const web_url = STEPSECURITY_WEB_URL;
|
||||
const insights_url = `${web_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}`;
|
||||
|
||||
const log = "/home/agent/agent.log";
|
||||
if (!fs.existsSync(log)) {
|
||||
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")) {
|
||||
let data = getAnnotationLogs(process.platform);
|
||||
if (
|
||||
data !== undefined &&
|
||||
data.includes("StepSecurity Harden Runner is disabled")
|
||||
) {
|
||||
needsSubscription = true;
|
||||
}
|
||||
} catch (err) {
|
||||
|
|
@ -89,88 +97,57 @@ export async function addSummary() {
|
|||
return;
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(log, "utf-8");
|
||||
const lines = content.split("\n");
|
||||
// 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"];
|
||||
|
||||
let tableEntries = [];
|
||||
|
||||
for (const line of lines) {
|
||||
processLogLine(line, tableEntries);
|
||||
}
|
||||
|
||||
if (tableEntries.length === 0) {
|
||||
if (!owner || !repo || !run_id || !correlation_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const insightsRow = `<p><b><a href="${insights_url}">📄 View Full Report</a></b></p>`;
|
||||
// Fetch job summary from API
|
||||
const apiUrl = `${STEPSECURITY_API_URL}/github/${owner}/${repo}/actions/runs/${run_id}/correlation/${correlation_id}/job-markdown-summary`;
|
||||
|
||||
await core.summary.addSeparator().addRaw(`<h2>🛡 StepSecurity Report</h2>`);
|
||||
|
||||
tableEntries.sort((a, b) => {
|
||||
if (a.status === "❌ Blocked" && b.status !== "❌ Blocked") {
|
||||
return -1;
|
||||
} else if (a.status !== "❌ Blocked" && b.status === "❌ Blocked") {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
try {
|
||||
const response = await fetch(apiUrl);
|
||||
if (!response.ok) {
|
||||
console.error(`Failed to fetch job summary: ${response.status} ${response.statusText}`);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
tableEntries = tableEntries.slice(0, 3);
|
||||
const markdownSummary = await response.text();
|
||||
|
||||
await core.summary.addRaw(`
|
||||
<blockquote>
|
||||
<p>Preview of the outbound network calls during this workflow run.</p></blockquote>
|
||||
<h3>Network Calls</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Process</th>
|
||||
<th>Destination</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${tableEntries
|
||||
.map(
|
||||
(entry) => `<tr>
|
||||
<td><code>${entry.process}</code></td>
|
||||
<td>${entry.domain.replace(/\.$/, "")}</td>
|
||||
<td>${entry.status}</td>
|
||||
</tr>`
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<td><code>...</code></td>
|
||||
<td><code>...</code></td>
|
||||
<td><code>...</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
${insightsRow}
|
||||
`);
|
||||
|
||||
await core.summary
|
||||
.addRaw(
|
||||
`<p><i>Markdown generated by the <a href="https://github.com/step-security/harden-runner">Harden-Runner GitHub Action</a>.</i></p>`
|
||||
)
|
||||
.addSeparator()
|
||||
.write();
|
||||
// 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 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 UNSUPPORTED_RUNNER_MESSAGE =
|
||||
"This job is not running in a GitHub Actions Hosted Runner. Harden Runner is only supported on GitHub-hosted runners (Ubuntu, Windows, and macOS). This job will not be monitored.";
|
||||
|
||||
export const SELF_HOSTED_NO_AGENT_MESSAGE =
|
||||
"This job is running on a self-hosted runner, but the runner does not have Harden-Runner installed. 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";
|
||||
"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.";
|
||||
|
||||
export const ARM64_WINDOWS_RUNNER_MESSAGE =
|
||||
"Windows ARM runners are not yet supported by Harden-Runner.";
|
||||
|
||||
export const UBUNTU_SLIM_MESSAGE =
|
||||
"This job is running on an ubuntu-slim runner. Harden Runner is not supported on ubuntu-slim runners. This job will not be monitored.";
|
||||
|
|
|
|||
|
|
@ -2,4 +2,7 @@ export const STEPSECURITY_ENV = "agent"; // agent or int
|
|||
|
||||
export const STEPSECURITY_API_URL = `https://${STEPSECURITY_ENV}.api.stepsecurity.io/v1`;
|
||||
|
||||
export const STEPSECURITY_TELEMETRY_URL =
|
||||
"https://prod.app-api.stepsecurity.io/v1";
|
||||
|
||||
export const STEPSECURITY_WEB_URL = "https://app.stepsecurity.io";
|
||||
|
|
|
|||
21
src/index.ts
21
src/index.ts
|
|
@ -2,13 +2,24 @@ 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";
|
||||
import { isPlatformSupported } from "./utils";
|
||||
|
||||
(async () => {
|
||||
if (process.platform !== "linux") {
|
||||
console.log(common.UBUNTU_MESSAGE);
|
||||
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 (isDocker()) {
|
||||
|
||||
if (!isPlatformSupported(process.platform)) {
|
||||
console.log(common.UNSUPPORTED_RUNNER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (isGithubHosted() && isDocker()) {
|
||||
console.log(common.CONTAINER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
|
@ -21,6 +32,10 @@ import { STEPSECURITY_WEB_URL } from "./configs";
|
|||
return;
|
||||
}
|
||||
|
||||
if (process.env.STATE_isTLS === "false" && process.arch === "arm64") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
core.getBooleanInput("disable-telemetry") &&
|
||||
core.getInput("egress-policy") === "block"
|
||||
|
|
|
|||
278
src/install-agent.ts
Normal file
278
src/install-agent.ts
Normal file
|
|
@ -0,0 +1,278 @@
|
|||
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, ARM64_WINDOWS_RUNNER_MESSAGE } from "./common";
|
||||
import { chownForFolder } from "./utils";
|
||||
|
||||
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.8.6/harden-runner_1.8.6_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.16.0/agent_0.16.0_linux_amd64.tar.gz",
|
||||
undefined,
|
||||
auth
|
||||
);
|
||||
}
|
||||
|
||||
if (!verifyChecksum(downloadPath, isTLS, variant, "linux")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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 installAgentBravo(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";
|
||||
const downloadPath = await tc.downloadTool(
|
||||
`https://github.com/step-security/agent-ebpf/releases/download/v1.8.6/harden-runner-bravo_1.8.6_linux_${variant}.tar.gz`,
|
||||
undefined,
|
||||
auth
|
||||
);
|
||||
|
||||
if (!verifyChecksum(downloadPath, true, variant, "linux", "bravo")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const extractPath = await tc.extractTar(downloadPath);
|
||||
cp.execFileSync("cp", [path.join(extractPath, "agent"), "/home/agent/agent"]);
|
||||
|
||||
cp.execSync("chmod +x /home/agent/agent");
|
||||
|
||||
fs.writeFileSync("/home/agent/agent.json", configStr);
|
||||
|
||||
const logStream = fs.openSync("/home/agent/agent.stdout", "a");
|
||||
const agentProcess = cp.spawn("sudo", ["/home/agent/agent"], {
|
||||
cwd: "/home/agent",
|
||||
detached: true,
|
||||
stdio: ["ignore", logStream, logStream],
|
||||
});
|
||||
agentProcess.unref();
|
||||
|
||||
const agentStatus = "/home/agent/agent.status";
|
||||
const deadline = Date.now() + 10000;
|
||||
while (true) {
|
||||
if (!fs.existsSync(agentStatus)) {
|
||||
if (Date.now() >= deadline) {
|
||||
console.log("timed out waiting for bravo agent");
|
||||
if (fs.existsSync("/home/agent/agent.stdout")) {
|
||||
console.log(fs.readFileSync("/home/agent/agent.stdout", "utf-8"));
|
||||
}
|
||||
if (fs.existsSync("/home/agent/agent.log")) {
|
||||
console.log(fs.readFileSync("/home/agent/agent.log", "utf-8"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
} else {
|
||||
console.log(fs.readFileSync(agentStatus, "utf-8"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function installMacosAgent(configStr: 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", configStr);
|
||||
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/v0.0.5-mac/macos-installer-0.0.5.tar.gz";
|
||||
core.info(`Downloading macOS installer.. : ${downloadUrl}`);
|
||||
const downloadPath = await tc.downloadTool(downloadUrl, undefined, auth);
|
||||
core.info(`✓ Successfully downloaded installer to: ${downloadPath}`);
|
||||
|
||||
// Verify SHA256 checksum
|
||||
core.info("Verifying SHA256 checksum of downloaded tar file...");
|
||||
if (!verifyChecksum(downloadPath, false, "", "darwin")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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");
|
||||
const installerBinaryPath = "/opt/step-security/Installer";
|
||||
|
||||
core.info(
|
||||
`Copying Installer from ${installerSourcePath} to /opt/step-security...`
|
||||
);
|
||||
cp.execFileSync("cp", [installerSourcePath, installerBinaryPath]);
|
||||
core.info("✓ Successfully copied Installer to /opt/step-security");
|
||||
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
export async function installWindowsAgent(configStr: string): Promise<boolean> {
|
||||
const token = core.getInput("token", { required: true });
|
||||
const auth = `token ${token}`;
|
||||
|
||||
const variant = process.arch === "x64" ? "amd64" : "arm64";
|
||||
if (variant === "arm64") {
|
||||
console.log(ARM64_WINDOWS_RUNNER_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
|
||||
const agentDir = "C:\\agent";
|
||||
core.info(`Creating agent directory: ${agentDir}`);
|
||||
if (!fs.existsSync(agentDir)) {
|
||||
fs.mkdirSync(agentDir, { recursive: true });
|
||||
}
|
||||
fs.appendFileSync(process.env.GITHUB_STATE, `agentDir=${agentDir}${EOL}`, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
const agentExePath = path.join(agentDir, "agent.exe");
|
||||
|
||||
const downloadPath = await tc.downloadTool(
|
||||
`https://github.com/step-security/agent-releases/releases/download/v1.0.2-win/harden-runner-agent-windows_1.0.2_windows_amd64.tar.gz`,
|
||||
undefined,
|
||||
auth
|
||||
);
|
||||
|
||||
// validate the checksum
|
||||
if (!verifyChecksum(downloadPath, false, variant, process.platform)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const extractPath = await tc.extractTar(downloadPath);
|
||||
|
||||
const extractedAgentPath = path.join(extractPath, "agent.exe");
|
||||
fs.copyFileSync(extractedAgentPath, agentExePath);
|
||||
core.info(`Copied agent from ${extractedAgentPath} to ${agentExePath}`);
|
||||
|
||||
const configPath = path.join(agentDir, "config.json");
|
||||
fs.writeFileSync(configPath, configStr);
|
||||
core.info(`Created config file: ${configPath}`);
|
||||
|
||||
core.info("Starting Windows Agent...");
|
||||
|
||||
try {
|
||||
const logPath = path.join(agentDir, "agent.log");
|
||||
const logStream = fs.openSync(logPath, "a");
|
||||
core.info(`Agent logs will be written to: ${logPath}`);
|
||||
|
||||
const agentProcess = cp.spawn(agentExePath, [], {
|
||||
cwd: agentDir,
|
||||
detached: true,
|
||||
stdio: ["ignore", logStream, logStream],
|
||||
windowsHide: false,
|
||||
shell: false,
|
||||
});
|
||||
|
||||
const pidFile = path.join(agentDir, "agent.pid");
|
||||
fs.writeFileSync(pidFile, agentProcess.pid.toString());
|
||||
core.info(`Agent process started with PID: ${agentProcess.pid}`);
|
||||
core.info(`PID saved to: ${pidFile}`);
|
||||
|
||||
agentProcess.unref();
|
||||
|
||||
core.info("Windows Agent process started successfully");
|
||||
return true;
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
core.setFailed(`Failed to start Windows agent process: ${errorMessage}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,15 +4,20 @@ export interface Configuration {
|
|||
correlation_id: string;
|
||||
working_directory: string;
|
||||
api_url: string;
|
||||
telemetry_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;
|
||||
api_key: string;
|
||||
use_policy_store: boolean;
|
||||
deploy_on_self_hosted_vm: boolean;
|
||||
}
|
||||
|
||||
export interface PolicyResponse {
|
||||
|
|
@ -20,7 +25,9 @@ export interface PolicyResponse {
|
|||
policyName?: string;
|
||||
allowed_endpoints?: string[];
|
||||
disable_sudo?: boolean;
|
||||
disable_sudo_and_containers?: boolean;
|
||||
disable_file_monitoring?: boolean;
|
||||
disable_telemetry?: boolean;
|
||||
egress_policy?: string;
|
||||
policy_name?: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,15 +32,20 @@ test("merge configs", async () => {
|
|||
correlation_id: "aaaaa",
|
||||
working_directory: "/xyz",
|
||||
api_url: "xyz",
|
||||
telemetry_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: "",
|
||||
api_key: "",
|
||||
use_policy_store: false,
|
||||
deploy_on_self_hosted_vm: false,
|
||||
};
|
||||
let policyResponse: PolicyResponse = {
|
||||
owner: "h0x0er",
|
||||
|
|
@ -58,17 +63,331 @@ test("merge configs", async () => {
|
|||
correlation_id: "aaaaa",
|
||||
working_directory: "/xyz",
|
||||
api_url: "xyz",
|
||||
telemetry_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: "",
|
||||
api_key: "",
|
||||
use_policy_store: false,
|
||||
deploy_on_self_hosted_vm: false,
|
||||
};
|
||||
|
||||
localConfig = mergeConfigs(localConfig, policyResponse);
|
||||
expect(localConfig).toStrictEqual(expectedConfiguration);
|
||||
});
|
||||
|
||||
// ==================== additional fetchPolicy tests ====================
|
||||
|
||||
test("fetchPolicy throws when idToken is empty", async () => {
|
||||
await expect(fetchPolicy("owner", "policy1", "")).rejects.toThrow(
|
||||
"[PolicyFetch]: id-token in empty"
|
||||
);
|
||||
});
|
||||
|
||||
test("fetchPolicy retries on failure and succeeds", async () => {
|
||||
const owner = "test-owner";
|
||||
const policyName = "test-policy";
|
||||
const response = {
|
||||
allowed_endpoints: ["example.com:443"],
|
||||
egress_policy: "block",
|
||||
};
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/actions/policies/${policyName}`)
|
||||
.replyWithError("connection timeout");
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/actions/policies/${policyName}`)
|
||||
.reply(200, response);
|
||||
|
||||
const policy = await fetchPolicy(owner, policyName, "token123");
|
||||
expect(policy).toStrictEqual(response);
|
||||
});
|
||||
|
||||
test("fetchPolicy throws after all retries exhausted", async () => {
|
||||
const owner = "test-owner";
|
||||
const policyName = "test-policy";
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/actions/policies/${policyName}`)
|
||||
.times(3)
|
||||
.replyWithError("connection timeout");
|
||||
|
||||
await expect(
|
||||
fetchPolicy(owner, policyName, "token123")
|
||||
).rejects.toThrow("[Policy Fetch]");
|
||||
});
|
||||
|
||||
test("fetchPolicy preserves statusCode from error", async () => {
|
||||
const owner = "test-owner";
|
||||
const policyName = "test-policy";
|
||||
|
||||
const errorWithStatus = new Error("Not Found");
|
||||
(errorWithStatus as any).statusCode = 404;
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/actions/policies/${policyName}`)
|
||||
.times(3)
|
||||
.replyWithError(errorWithStatus);
|
||||
|
||||
try {
|
||||
await fetchPolicy(owner, policyName, "token123");
|
||||
fail("should have thrown");
|
||||
} catch (err) {
|
||||
expect(err.message).toContain("[Policy Fetch]");
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== fetchPolicyFromStore ====================
|
||||
|
||||
import { fetchPolicyFromStore } from "./policy-utils";
|
||||
|
||||
const policyStoreQueryString = (workflow: string, runId: string, correlationId: string) =>
|
||||
`workflow=${encodeURIComponent(workflow)}&run_id=${encodeURIComponent(runId)}&correlationId=${encodeURIComponent(correlationId)}`;
|
||||
|
||||
test("success: fetches policy from store", async () => {
|
||||
const owner = "test-owner";
|
||||
const repo = "test-repo";
|
||||
const workflow = "ci.yml";
|
||||
const runId = "12345";
|
||||
const correlationId = "abc-def";
|
||||
const response = {
|
||||
allowed_endpoints: ["registry.npmjs.org:443", "github.com:443"],
|
||||
egress_policy: "block",
|
||||
disable_sudo: true,
|
||||
disable_file_monitoring: false,
|
||||
};
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/${repo}/actions/policies/workflow-policy?${policyStoreQueryString(workflow, runId, correlationId)}`)
|
||||
.reply(200, response);
|
||||
|
||||
const result = await fetchPolicyFromStore(owner, repo, "my-api-key", workflow, runId, correlationId);
|
||||
expect(result).toStrictEqual(response);
|
||||
});
|
||||
|
||||
test("fetchPolicyFromStore throws when apiKey is empty", async () => {
|
||||
await expect(
|
||||
fetchPolicyFromStore("owner", "repo", "", "ci.yml", "123", "abc")
|
||||
).rejects.toThrow("[PolicyStoreFetch]: api-key is empty");
|
||||
});
|
||||
|
||||
test("fetchPolicyFromStore returns null when policy not found (404)", async () => {
|
||||
const owner = "test-owner";
|
||||
const repo = "test-repo";
|
||||
const workflow = "ci.yml";
|
||||
const runId = "12345";
|
||||
const correlationId = "abc-def";
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/${repo}/actions/policies/workflow-policy?${policyStoreQueryString(workflow, runId, correlationId)}`)
|
||||
.reply(404, { message: "not found" });
|
||||
|
||||
const result = await fetchPolicyFromStore(owner, repo, "my-api-key", workflow, runId, correlationId);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
test("fetchPolicyFromStore returns null when API returns empty policy", async () => {
|
||||
const owner = "test-owner";
|
||||
const repo = "nonexistent-repo";
|
||||
const workflow = "ci.yml";
|
||||
const runId = "12345";
|
||||
const correlationId = "abc-def";
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/${repo}/actions/policies/workflow-policy?${policyStoreQueryString(workflow, runId, correlationId)}`)
|
||||
.reply(200, { allowed_endpoints: [], egress_policy: "", policy_name: "" });
|
||||
|
||||
const result = await fetchPolicyFromStore(owner, repo, "my-api-key", workflow, runId, correlationId);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
test("fetchPolicyFromStore retries on failure and succeeds", async () => {
|
||||
const owner = "test-owner";
|
||||
const repo = "test-repo";
|
||||
const workflow = "ci.yml";
|
||||
const runId = "12345";
|
||||
const correlationId = "abc-def";
|
||||
const response = {
|
||||
allowed_endpoints: ["example.com:443"],
|
||||
egress_policy: "audit",
|
||||
};
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/${repo}/actions/policies/workflow-policy?${policyStoreQueryString(workflow, runId, correlationId)}`)
|
||||
.replyWithError("timeout");
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/${repo}/actions/policies/workflow-policy?${policyStoreQueryString(workflow, runId, correlationId)}`)
|
||||
.reply(200, response);
|
||||
|
||||
const result = await fetchPolicyFromStore(owner, repo, "my-api-key", workflow, runId, correlationId);
|
||||
expect(result).toStrictEqual(response);
|
||||
});
|
||||
|
||||
test("fetchPolicyFromStore throws after all retries exhausted", async () => {
|
||||
const owner = "test-owner";
|
||||
const repo = "test-repo";
|
||||
const workflow = "ci.yml";
|
||||
const runId = "12345";
|
||||
const correlationId = "abc-def";
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/${repo}/actions/policies/workflow-policy?${policyStoreQueryString(workflow, runId, correlationId)}`)
|
||||
.times(3)
|
||||
.replyWithError("connection refused");
|
||||
|
||||
await expect(
|
||||
fetchPolicyFromStore(owner, repo, "my-api-key", workflow, runId, correlationId)
|
||||
).rejects.toThrow("[Policy Store Fetch]");
|
||||
});
|
||||
|
||||
test("fetchPolicyFromStore preserves statusCode from error", async () => {
|
||||
const owner = "test-owner";
|
||||
const repo = "test-repo";
|
||||
const workflow = "ci.yml";
|
||||
const runId = "12345";
|
||||
const correlationId = "abc-def";
|
||||
|
||||
const errorWithStatus = new Error("Unauthorized");
|
||||
(errorWithStatus as any).statusCode = 401;
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`)
|
||||
.get(`/github/${owner}/${repo}/actions/policies/workflow-policy?${policyStoreQueryString(workflow, runId, correlationId)}`)
|
||||
.times(3)
|
||||
.replyWithError(errorWithStatus);
|
||||
|
||||
try {
|
||||
await fetchPolicyFromStore(owner, repo, "my-api-key", workflow, runId, correlationId);
|
||||
fail("should have thrown");
|
||||
} catch (err) {
|
||||
expect(err.message).toContain("[Policy Store Fetch]");
|
||||
}
|
||||
});
|
||||
|
||||
test("fetchPolicyFromStore sends correct authorization header", async () => {
|
||||
const owner = "test-owner";
|
||||
const repo = "test-repo";
|
||||
const apiKey = "secret-key-123";
|
||||
const workflow = "ci.yml";
|
||||
const runId = "12345";
|
||||
const correlationId = "abc-def";
|
||||
|
||||
nock(`${STEPSECURITY_API_URL}`, {
|
||||
reqheaders: {
|
||||
Authorization: `vm-api-key ${apiKey}`,
|
||||
Source: "github-actions",
|
||||
},
|
||||
})
|
||||
.get(`/github/${owner}/${repo}/actions/policies/workflow-policy?${policyStoreQueryString(workflow, runId, correlationId)}`)
|
||||
.reply(200, { allowed_endpoints: [], egress_policy: "audit" });
|
||||
|
||||
const result = await fetchPolicyFromStore(owner, repo, apiKey, workflow, runId, correlationId);
|
||||
expect(result).toStrictEqual({
|
||||
allowed_endpoints: [],
|
||||
egress_policy: "audit",
|
||||
});
|
||||
});
|
||||
|
||||
// ==================== additional mergeConfigs tests ====================
|
||||
|
||||
test("mergeConfigs does not override local allowed_endpoints if not empty", () => {
|
||||
let localConfig: Configuration = {
|
||||
repo: "test/repo",
|
||||
run_id: "xyx",
|
||||
correlation_id: "aaaaa",
|
||||
working_directory: "/xyz",
|
||||
api_url: "xyz",
|
||||
telemetry_url: "xyz",
|
||||
allowed_endpoints: "local.endpoint: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: "",
|
||||
api_key: "",
|
||||
use_policy_store: false,
|
||||
deploy_on_self_hosted_vm: false,
|
||||
};
|
||||
let policyResponse: PolicyResponse = {
|
||||
allowed_endpoints: ["remote.endpoint:443"],
|
||||
egress_policy: "block",
|
||||
};
|
||||
|
||||
localConfig = mergeConfigs(localConfig, policyResponse);
|
||||
expect(localConfig.allowed_endpoints).toBe("local.endpoint:443");
|
||||
expect(localConfig.egress_policy).toBe("block");
|
||||
});
|
||||
|
||||
test("mergeConfigs overrides disable_sudo_and_containers from remote", () => {
|
||||
let localConfig: Configuration = {
|
||||
repo: "test/repo",
|
||||
run_id: "xyx",
|
||||
correlation_id: "aaaaa",
|
||||
working_directory: "/xyz",
|
||||
api_url: "xyz",
|
||||
telemetry_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: "",
|
||||
api_key: "",
|
||||
use_policy_store: false,
|
||||
deploy_on_self_hosted_vm: false,
|
||||
};
|
||||
let policyResponse: PolicyResponse = {
|
||||
allowed_endpoints: [],
|
||||
disable_sudo_and_containers: true,
|
||||
};
|
||||
|
||||
localConfig = mergeConfigs(localConfig, policyResponse);
|
||||
expect(localConfig.disable_sudo_and_containers).toBe(true);
|
||||
});
|
||||
|
||||
test("mergeConfigs does not override fields when remote values are undefined", () => {
|
||||
let localConfig: Configuration = {
|
||||
repo: "test/repo",
|
||||
run_id: "xyx",
|
||||
correlation_id: "aaaaa",
|
||||
working_directory: "/xyz",
|
||||
api_url: "xyz",
|
||||
telemetry_url: "xyz",
|
||||
allowed_endpoints: "",
|
||||
egress_policy: "block",
|
||||
disable_telemetry: false,
|
||||
disable_sudo: true,
|
||||
disable_sudo_and_containers: true,
|
||||
disable_file_monitoring: true,
|
||||
private: "true",
|
||||
is_github_hosted: true,
|
||||
is_debug: false,
|
||||
one_time_key: "",
|
||||
api_key: "",
|
||||
use_policy_store: false,
|
||||
deploy_on_self_hosted_vm: false,
|
||||
};
|
||||
let policyResponse: PolicyResponse = {
|
||||
allowed_endpoints: [],
|
||||
};
|
||||
|
||||
localConfig = mergeConfigs(localConfig, policyResponse);
|
||||
expect(localConfig.disable_sudo).toBe(true);
|
||||
expect(localConfig.disable_sudo_and_containers).toBe(true);
|
||||
expect(localConfig.disable_file_monitoring).toBe(true);
|
||||
expect(localConfig.egress_policy).toBe("block");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -39,12 +39,76 @@ export async function fetchPolicy(
|
|||
}
|
||||
|
||||
if (response === undefined && err !== undefined) {
|
||||
throw new Error(`[Policy Fetch] ${err}`);
|
||||
// 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 async function fetchPolicyFromStore(
|
||||
owner: string,
|
||||
repo: string,
|
||||
apiKey: string,
|
||||
workflow: string,
|
||||
runId: string,
|
||||
correlationId: string
|
||||
): Promise<PolicyResponse | null> {
|
||||
if (apiKey === "") {
|
||||
throw new Error("[PolicyStoreFetch]: api-key is empty");
|
||||
}
|
||||
|
||||
let policyEndpoint = `${STEPSECURITY_API_URL}/github/${owner}/${repo}/actions/policies/workflow-policy?workflow=${encodeURIComponent(workflow)}&run_id=${encodeURIComponent(runId)}&correlationId=${encodeURIComponent(correlationId)}`;
|
||||
|
||||
let httpClient = new HttpClient();
|
||||
|
||||
let headers = {};
|
||||
headers["Authorization"] = `vm-api-key ${apiKey}`;
|
||||
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) {
|
||||
const error = new Error(`[Policy Store Fetch] ${err}`);
|
||||
if (err.statusCode !== undefined) {
|
||||
(error as any).statusCode = err.statusCode;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (response.statusCode === 404) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const result = response.result;
|
||||
if (!result || (!result.egress_policy && (!result.allowed_endpoints || result.allowed_endpoints.length === 0))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function mergeConfigs(
|
||||
localConfig: Configuration,
|
||||
remoteConfig: PolicyResponse
|
||||
|
|
@ -56,6 +120,10 @@ export function mergeConfigs(
|
|||
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;
|
||||
}
|
||||
|
|
@ -66,7 +134,7 @@ export function mergeConfigs(
|
|||
return localConfig;
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
|
|
|
|||
512
src/setup.ts
512
src/setup.ts
|
|
@ -5,8 +5,6 @@ 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";
|
||||
|
|
@ -18,13 +16,30 @@ import {
|
|||
isValidEvent,
|
||||
} from "./cache";
|
||||
import { Configuration, PolicyResponse } from "./interfaces";
|
||||
import { fetchPolicy, mergeConfigs } from "./policy-utils";
|
||||
import { fetchPolicy, fetchPolicyFromStore, 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 { isARCRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
import {
|
||||
STEPSECURITY_API_URL,
|
||||
STEPSECURITY_TELEMETRY_URL,
|
||||
STEPSECURITY_WEB_URL,
|
||||
} from "./configs";
|
||||
import { isGithubHosted, isTLSEnabled } from "./tls-inspect";
|
||||
import {
|
||||
installAgent,
|
||||
installAgentBravo,
|
||||
installMacosAgent,
|
||||
installWindowsAgent,
|
||||
} from "./install-agent";
|
||||
|
||||
import { chownForFolder, detectThirdPartyRunnerProvider, isAgentInstalled, isPlatformSupported, shouldDeployAgentOnSelfHosted } from "./utils";
|
||||
import { buildBravoConfig } from "./bravo-config";
|
||||
|
||||
interface MonitorResponse {
|
||||
runner_ip_address?: string;
|
||||
|
|
@ -34,15 +49,28 @@ interface MonitorResponse {
|
|||
|
||||
(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()) {
|
||||
|
||||
if (!isPlatformSupported(process.platform)) {
|
||||
console.log(common.UNSUPPORTED_RUNNER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (isGithubHosted() && isDocker()) {
|
||||
console.log(common.CONTAINER_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isGithubHosted() && process.platform === "linux" && !process.env.USER) {
|
||||
console.log(common.UBUNTU_SLIM_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
var correlation_id = uuidv4();
|
||||
var api_url = STEPSECURITY_API_URL;
|
||||
var web_url = STEPSECURITY_WEB_URL;
|
||||
|
|
@ -53,19 +81,68 @@ interface MonitorResponse {
|
|||
correlation_id: correlation_id,
|
||||
working_directory: process.env["GITHUB_WORKSPACE"],
|
||||
api_url: api_url,
|
||||
telemetry_url: STEPSECURITY_TELEMETRY_URL,
|
||||
allowed_endpoints: core.getInput("allowed-endpoints"),
|
||||
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 || false,
|
||||
is_github_hosted: isGithubHosted(),
|
||||
is_debug: core.isDebug(),
|
||||
one_time_key: "",
|
||||
api_key: core.getInput("api-key"),
|
||||
use_policy_store: core.getBooleanInput("use-policy-store"),
|
||||
deploy_on_self_hosted_vm: core.getBooleanInput("deploy-on-self-hosted-vm"),
|
||||
};
|
||||
|
||||
if (confg.api_key !== "") {
|
||||
core.setSecret(confg.api_key);
|
||||
}
|
||||
|
||||
let policyName = core.getInput("policy");
|
||||
if (policyName !== "") {
|
||||
if (confg.use_policy_store) {
|
||||
console.log(`Fetching policy from policy store`);
|
||||
if (confg.api_key === "") {
|
||||
core.warning(
|
||||
"api-key is not set while use-policy-store is true. Defaulting to audit mode."
|
||||
);
|
||||
confg.egress_policy = "audit";
|
||||
} else {
|
||||
try {
|
||||
const repoName = (process.env["GITHUB_REPOSITORY"] || "").split("/")[1] || "";
|
||||
const workflowRef = process.env["GITHUB_WORKFLOW_REF"] || "";
|
||||
const workflow = workflowRef.replace(/.*\.github\/workflows\//, "").replace(/@.*/, "");
|
||||
let result: PolicyResponse | null = await fetchPolicyFromStore(
|
||||
context.repo.owner,
|
||||
repoName,
|
||||
confg.api_key,
|
||||
workflow,
|
||||
confg.run_id,
|
||||
confg.correlation_id
|
||||
);
|
||||
if (result !== null) {
|
||||
core.info(`Policy found: ${result.policy_name || "unnamed"}`);
|
||||
confg = mergeConfigs(confg, result);
|
||||
} else {
|
||||
core.info("No policy found in policy store. Defaulting to audit mode.");
|
||||
confg.egress_policy = "audit";
|
||||
}
|
||||
} catch (err) {
|
||||
core.info(`[!] ${err}`);
|
||||
if (err.statusCode >= 400 && err.statusCode < 500) {
|
||||
core.info("Policy not found in policy store. Defaulting to audit mode.");
|
||||
confg.egress_policy = "audit";
|
||||
} else {
|
||||
core.error(`Unexpected error fetching from policy store: ${err}. Falling back to audit mode.`);
|
||||
confg.egress_policy = "audit";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (policyName !== "") {
|
||||
console.log(`Fetching policy from API with name: ${policyName}`);
|
||||
try {
|
||||
let idToken: string = await core.getIDToken();
|
||||
|
|
@ -77,7 +154,18 @@ interface MonitorResponse {
|
|||
confg = mergeConfigs(confg, result);
|
||||
} catch (err) {
|
||||
core.info(`[!] ${err}`);
|
||||
core.setFailed(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(
|
||||
|
|
@ -87,6 +175,13 @@ interface MonitorResponse {
|
|||
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") {
|
||||
|
|
@ -113,28 +208,78 @@ interface MonitorResponse {
|
|||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
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 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";
|
||||
}
|
||||
}
|
||||
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 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +287,7 @@ interface MonitorResponse {
|
|||
common.printInfo(web_url);
|
||||
}
|
||||
|
||||
if (isArcRunner()) {
|
||||
if (isARCRunner()) {
|
||||
console.log(`[!] ${common.ARC_RUNNER_MESSAGE}`);
|
||||
if (confg.egress_policy === "block") {
|
||||
sendAllowedEndpoints(confg.allowed_endpoints);
|
||||
|
|
@ -154,30 +299,73 @@ interface MonitorResponse {
|
|||
const runnerName = process.env.RUNNER_NAME || "";
|
||||
core.info(`RUNNER_NAME: ${runnerName}`);
|
||||
if (!isGithubHosted()) {
|
||||
const thirdPartyProvider = detectThirdPartyRunnerProvider();
|
||||
if (thirdPartyProvider) {
|
||||
const providerLabel = thirdPartyProvider.charAt(0).toUpperCase() + thirdPartyProvider.slice(1);
|
||||
if (process.platform !== "linux") {
|
||||
core.info(`Detected ${providerLabel} runner on ${process.platform}. Bravo agent is Linux-only, skipping install.`);
|
||||
return;
|
||||
}
|
||||
core.info(`Detected ${providerLabel} runner environment. Installing agent-bravo.`);
|
||||
confg.correlation_id = runnerName || confg.correlation_id;
|
||||
await callMonitorEndpoint(api_url, confg);
|
||||
await installAgentForBravo(context.repo.owner, confg);
|
||||
return;
|
||||
}
|
||||
|
||||
fs.appendFileSync(process.env.GITHUB_STATE, `selfHosted=true${EOL}`, {
|
||||
encoding: "utf8",
|
||||
});
|
||||
if (!fs.existsSync("/home/agent/agent")) {
|
||||
core.info(common.SELF_HOSTED_NO_AGENT_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (confg.egress_policy === "block") {
|
||||
try {
|
||||
if (process.env.USER) {
|
||||
cp.execSync(`sudo chown -R ${process.env.USER} /home/agent`);
|
||||
}
|
||||
const confgStr = JSON.stringify(confg);
|
||||
fs.writeFileSync("/home/agent/block_event.json", confgStr);
|
||||
await sleep(5000);
|
||||
} catch (error) {
|
||||
core.info(`[!] Unable to write block_event.json: ${error}`);
|
||||
|
||||
core.info(common.SELF_HOSTED_RUNNER_MESSAGE);
|
||||
|
||||
const inContainer = isDocker();
|
||||
const alreadyInstalled = isAgentInstalled(process.platform);
|
||||
|
||||
if (shouldDeployAgentOnSelfHosted(confg.deploy_on_self_hosted_vm, inContainer, alreadyInstalled)) {
|
||||
if (process.platform !== "linux") {
|
||||
core.info("deploy-on-self-hosted-vm is only supported on Linux. Skipping agent deployment.");
|
||||
} else {
|
||||
core.info("deploy-on-self-hosted-vm is enabled. Installing agent on self-hosted runner.");
|
||||
await installAgentForSelfHosted(context.repo.owner, confg);
|
||||
}
|
||||
} else {
|
||||
if (confg.deploy_on_self_hosted_vm && inContainer) {
|
||||
core.info("Skipping agent deployment: running inside a container.");
|
||||
}
|
||||
if (confg.deploy_on_self_hosted_vm && alreadyInstalled) {
|
||||
core.info("Agent already installed on self-hosted runner, skipping installation.");
|
||||
}
|
||||
}
|
||||
|
||||
if (confg.egress_policy === "block" && !confg.deploy_on_self_hosted_vm) {
|
||||
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() && isAgentInstalled(process.platform)) {
|
||||
console.log("Agent already installed, skipping installation");
|
||||
return;
|
||||
}
|
||||
|
||||
let _http = new httpm.HttpClient();
|
||||
let statusCode;
|
||||
let statusCode: number | undefined;
|
||||
_http.requestOptions = { socketTimeout: 3 * 1000 };
|
||||
let addSummary = "false";
|
||||
try {
|
||||
|
|
@ -215,6 +403,13 @@ interface MonitorResponse {
|
|||
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) {
|
||||
|
|
@ -222,74 +417,68 @@ interface MonitorResponse {
|
|||
return;
|
||||
}
|
||||
|
||||
const confgStr = JSON.stringify(confg);
|
||||
cp.execSync("sudo mkdir -p /home/agent");
|
||||
cp.execSync("sudo chown -R $USER /home/agent");
|
||||
const { api_key, use_policy_store, ...agentConfig } = confg;
|
||||
const configStr = JSON.stringify(agentConfig);
|
||||
|
||||
// Note: to avoid github rate limiting
|
||||
let token = core.getInput("token");
|
||||
let auth = `token ${token}`;
|
||||
// platform specific
|
||||
let statusFile = "";
|
||||
let logFile = "";
|
||||
let agentInstalled = false;
|
||||
|
||||
let downloadPath: string;
|
||||
switch (process.platform) {
|
||||
case "linux":
|
||||
statusFile = "/home/agent/agent.status";
|
||||
logFile = "/home/agent/agent.log";
|
||||
|
||||
if (await isTLSEnabled(context.repo.owner)) {
|
||||
downloadPath = await tc.downloadTool(
|
||||
"https://packages.stepsecurity.io/github-hosted/harden-runner_1.2.2_linux_amd64.tar.gz"
|
||||
);
|
||||
verifyChecksum(downloadPath, true); // NOTE: verifying tls_agent's checksum, before extracting
|
||||
} else {
|
||||
downloadPath = await tc.downloadTool(
|
||||
"https://github.com/step-security/agent/releases/download/v0.13.7/agent_0.13.7_linux_amd64.tar.gz",
|
||||
undefined,
|
||||
auth
|
||||
);
|
||||
cp.execSync("sudo mkdir -p /home/agent");
|
||||
chownForFolder(process.env.USER, "/home/agent");
|
||||
|
||||
verifyChecksum(downloadPath, false); // NOTE: verifying agent's checksum, before extracting
|
||||
let isTLS = await isTLSEnabled(context.repo.owner);
|
||||
agentInstalled = await installAgent(isTLS, configStr);
|
||||
|
||||
break;
|
||||
case "win32":
|
||||
core.info("Installing Windows Agent...");
|
||||
agentInstalled = await installWindowsAgent(configStr);
|
||||
|
||||
const agentDir = process.env.STATE_agentDir || "C:\\agent";
|
||||
statusFile = path.join(agentDir, "agent.status");
|
||||
logFile = path.join(agentDir, "agent.log");
|
||||
|
||||
break;
|
||||
case "darwin":
|
||||
const installed = await installMacosAgent(configStr);
|
||||
if (!installed) {
|
||||
core.warning("😭 macos agent installation failed");
|
||||
}
|
||||
return; // early return
|
||||
default:
|
||||
throw new Error(
|
||||
`Setup failed because of unsupported platform: ${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", 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);
|
||||
if (agentInstalled) {
|
||||
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;
|
||||
}
|
||||
await sleep(300);
|
||||
} // The file *does* exist
|
||||
else {
|
||||
// Read the file
|
||||
var content = fs.readFileSync(statusFile, "utf-8");
|
||||
console.log(content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
@ -299,8 +488,117 @@ interface MonitorResponse {
|
|||
process.exit(0);
|
||||
})();
|
||||
|
||||
export function sleep(ms) {
|
||||
export function sleep(ms: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
async function callMonitorEndpoint(api_url: string, confg: Configuration) {
|
||||
const _http = new httpm.HttpClient();
|
||||
_http.requestOptions = { socketTimeout: 3 * 1000 };
|
||||
let statusCode: number | undefined;
|
||||
let addSummary = "false";
|
||||
try {
|
||||
const monitorRequestData = {
|
||||
correlation_id: confg.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
|
||||
);
|
||||
statusCode = resp.statusCode;
|
||||
if (resp.statusCode === 200 && resp.result) {
|
||||
console.log(`Runner IP Address: ${resp.result.runner_ip_address}`);
|
||||
confg.one_time_key = resp.result.one_time_key;
|
||||
addSummary = resp.result.monitoring_started ? "true" : "false";
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(`error in connecting to ${api_url}: ${e}`);
|
||||
}
|
||||
fs.appendFileSync(process.env.GITHUB_STATE, `monitorStatusCode=${statusCode}${EOL}`, { encoding: "utf8" });
|
||||
fs.appendFileSync(process.env.GITHUB_STATE, `addSummary=${addSummary}${EOL}`, { encoding: "utf8" });
|
||||
fs.appendFileSync(process.env.GITHUB_STATE, `correlation_id=${confg.correlation_id}${EOL}`, { encoding: "utf8" });
|
||||
}
|
||||
|
||||
export async function installAgentForSelfHosted(owner: string, confg: Configuration) {
|
||||
try {
|
||||
console.log("Installing Harden Runner agent for self-hosted runner");
|
||||
|
||||
let isTLS = await isTLSEnabled(owner);
|
||||
|
||||
if (!isTLS) {
|
||||
console.log("TLS is not enabled for this organization. Agent installation skipped for self-hosted runner.");
|
||||
return;
|
||||
}
|
||||
|
||||
const selfHostedConfig = {
|
||||
customer: owner,
|
||||
working_directory: confg.working_directory,
|
||||
api_url: confg.api_url,
|
||||
api_key: uuidv4(),
|
||||
allowed_endpoints: confg.allowed_endpoints,
|
||||
egress_policy: confg.egress_policy,
|
||||
disable_telemetry: confg.disable_telemetry,
|
||||
disable_sudo: confg.disable_sudo,
|
||||
disable_sudo_and_containers: confg.disable_sudo_and_containers,
|
||||
disable_file_monitoring: confg.disable_file_monitoring,
|
||||
is_github_hosted: false,
|
||||
};
|
||||
const selfHostedConfigStr = JSON.stringify(selfHostedConfig);
|
||||
|
||||
cp.execSync("sudo mkdir -p /home/agent");
|
||||
chownForFolder(process.env.USER, "/home/agent");
|
||||
|
||||
const agentInstalled = await installAgent(isTLS, selfHostedConfigStr);
|
||||
|
||||
if (agentInstalled) {
|
||||
const statusFile = "/home/agent/agent.status";
|
||||
const logFile = "/home/agent/agent.log";
|
||||
let counter = 0;
|
||||
while (true) {
|
||||
if (!fs.existsSync(statusFile)) {
|
||||
counter++;
|
||||
if (counter > 30) {
|
||||
console.log("timed out");
|
||||
if (fs.existsSync(logFile)) {
|
||||
const content = fs.readFileSync(logFile, "utf-8");
|
||||
console.log(content);
|
||||
}
|
||||
break;
|
||||
}
|
||||
await sleep(300);
|
||||
} else {
|
||||
const content = fs.readFileSync(statusFile, "utf-8");
|
||||
console.log(content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Failed to install agent for self-hosted runner: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function installAgentForBravo(owner: string, confg: Configuration) {
|
||||
try {
|
||||
console.log("Installing Harden Runner bravo agent for third-party runner");
|
||||
|
||||
let isTLS = await isTLSEnabled(owner);
|
||||
|
||||
if (!isTLS) {
|
||||
console.log("TLS is not enabled for this organization. Bravo agent installation skipped.");
|
||||
return;
|
||||
}
|
||||
|
||||
const bravoConfigStr = JSON.stringify(buildBravoConfig(confg));
|
||||
|
||||
cp.execSync("sudo mkdir -p /home/agent");
|
||||
chownForFolder(process.env.USER, "/home/agent");
|
||||
|
||||
await installAgentBravo(bravoConfigStr);
|
||||
} catch (error) {
|
||||
console.log(`Failed to install bravo agent: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
158
src/utils.test.ts
Normal file
158
src/utils.test.ts
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
import { shouldDeployAgentOnSelfHosted, isAgentInstalled, isPlatformSupported, getAnnotationLogs, detectThirdPartyRunnerProvider } from "./utils";
|
||||
import * as fs from "fs";
|
||||
|
||||
jest.mock("fs", () => ({
|
||||
...jest.requireActual("fs"),
|
||||
existsSync: jest.fn(),
|
||||
}));
|
||||
|
||||
const mockedExistsSync = fs.existsSync as jest.MockedFunction<typeof fs.existsSync>;
|
||||
|
||||
describe("shouldDeployAgentOnSelfHosted", () => {
|
||||
test("returns true when deploy flag is true, not container, agent not installed", () => {
|
||||
expect(shouldDeployAgentOnSelfHosted(true, false, false)).toBe(true);
|
||||
});
|
||||
|
||||
test("returns false when deploy flag is false", () => {
|
||||
expect(shouldDeployAgentOnSelfHosted(false, false, false)).toBe(false);
|
||||
});
|
||||
|
||||
test("returns false when running in a container", () => {
|
||||
expect(shouldDeployAgentOnSelfHosted(true, true, false)).toBe(false);
|
||||
});
|
||||
|
||||
test("returns false when agent is already installed", () => {
|
||||
expect(shouldDeployAgentOnSelfHosted(true, false, true)).toBe(false);
|
||||
});
|
||||
|
||||
test("returns false when in container and agent installed", () => {
|
||||
expect(shouldDeployAgentOnSelfHosted(true, true, true)).toBe(false);
|
||||
});
|
||||
|
||||
test("returns false when all conditions are negative", () => {
|
||||
expect(shouldDeployAgentOnSelfHosted(false, true, true)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isAgentInstalled", () => {
|
||||
afterEach(() => {
|
||||
mockedExistsSync.mockReset();
|
||||
});
|
||||
|
||||
test("returns false for linux when status file does not exist", () => {
|
||||
mockedExistsSync.mockReturnValue(false);
|
||||
expect(isAgentInstalled("linux")).toBe(false);
|
||||
expect(mockedExistsSync).toHaveBeenCalledWith("/home/agent/agent.status");
|
||||
});
|
||||
|
||||
test("returns true for linux when status file exists", () => {
|
||||
mockedExistsSync.mockReturnValue(true);
|
||||
expect(isAgentInstalled("linux")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns false for win32 when status file does not exist", () => {
|
||||
mockedExistsSync.mockReturnValue(false);
|
||||
expect(isAgentInstalled("win32")).toBe(false);
|
||||
expect(mockedExistsSync).toHaveBeenCalledWith("C:\\agent\\agent.status");
|
||||
});
|
||||
|
||||
test("returns false for darwin when status file does not exist", () => {
|
||||
mockedExistsSync.mockReturnValue(false);
|
||||
expect(isAgentInstalled("darwin")).toBe(false);
|
||||
expect(mockedExistsSync).toHaveBeenCalledWith("/opt/step-security/agent.status");
|
||||
});
|
||||
|
||||
test("returns false for unsupported platform", () => {
|
||||
expect(isAgentInstalled("freebsd" as NodeJS.Platform)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isPlatformSupported", () => {
|
||||
test("returns true for linux", () => {
|
||||
expect(isPlatformSupported("linux")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns true for win32", () => {
|
||||
expect(isPlatformSupported("win32")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns true for darwin", () => {
|
||||
expect(isPlatformSupported("darwin")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns false for unsupported platform", () => {
|
||||
expect(isPlatformSupported("freebsd" as NodeJS.Platform)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAnnotationLogs", () => {
|
||||
test("throws for unsupported platform", () => {
|
||||
expect(() => getAnnotationLogs("freebsd" as NodeJS.Platform)).toThrow("platform not supported");
|
||||
});
|
||||
});
|
||||
|
||||
describe("detectThirdPartyRunnerProvider", () => {
|
||||
const originalEnv = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
process.env = { ...originalEnv };
|
||||
delete process.env.DEPOT_RUNNER;
|
||||
delete process.env.NAMESPACE_GITHUB_RUNTIME;
|
||||
delete process.env.RUNNER_NAME;
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
|
||||
test("returns depot when DEPOT_RUNNER=1", () => {
|
||||
process.env.DEPOT_RUNNER = "1";
|
||||
expect(detectThirdPartyRunnerProvider()).toBe("depot");
|
||||
});
|
||||
|
||||
test("returns null when DEPOT_RUNNER=0", () => {
|
||||
process.env.DEPOT_RUNNER = "0";
|
||||
expect(detectThirdPartyRunnerProvider()).toBeNull();
|
||||
});
|
||||
|
||||
test("returns namespace when NAMESPACE_GITHUB_RUNTIME is set", () => {
|
||||
process.env.NAMESPACE_GITHUB_RUNTIME = "something";
|
||||
expect(detectThirdPartyRunnerProvider()).toBe("namespace");
|
||||
});
|
||||
|
||||
test("returns warp for RUNNER_NAME prefix warp-", () => {
|
||||
process.env.RUNNER_NAME = "warp-4x-x64-abc";
|
||||
expect(detectThirdPartyRunnerProvider()).toBe("warp");
|
||||
});
|
||||
|
||||
test("returns blacksmith for RUNNER_NAME prefix blacksmith-", () => {
|
||||
process.env.RUNNER_NAME = "blacksmith-01kpj-4vcpu";
|
||||
expect(detectThirdPartyRunnerProvider()).toBe("blacksmith");
|
||||
});
|
||||
|
||||
test("returns null when no env vars match", () => {
|
||||
expect(detectThirdPartyRunnerProvider()).toBeNull();
|
||||
});
|
||||
|
||||
test("returns null for a non-matching RUNNER_NAME", () => {
|
||||
process.env.RUNNER_NAME = "GitHub Actions 1";
|
||||
expect(detectThirdPartyRunnerProvider()).toBeNull();
|
||||
});
|
||||
|
||||
test("depot takes precedence over namespace", () => {
|
||||
process.env.DEPOT_RUNNER = "1";
|
||||
process.env.NAMESPACE_GITHUB_RUNTIME = "something";
|
||||
expect(detectThirdPartyRunnerProvider()).toBe("depot");
|
||||
});
|
||||
|
||||
test("namespace takes precedence over warp runner name prefix", () => {
|
||||
process.env.NAMESPACE_GITHUB_RUNTIME = "something";
|
||||
process.env.RUNNER_NAME = "warp-x";
|
||||
expect(detectThirdPartyRunnerProvider()).toBe("namespace");
|
||||
});
|
||||
|
||||
test("warp takes precedence over blacksmith when both prefixes seen (warp wins on name check order)", () => {
|
||||
process.env.RUNNER_NAME = "warp-x";
|
||||
expect(detectThirdPartyRunnerProvider()).toBe("warp");
|
||||
});
|
||||
});
|
||||
65
src/utils.ts
Normal file
65
src/utils.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import * as cp from "child_process";
|
||||
import * as fs from "fs";
|
||||
|
||||
export function isPlatformSupported(platform: NodeJS.Platform) {
|
||||
switch (platform) {
|
||||
case "linux":
|
||||
case "win32":
|
||||
case "darwin":
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function chownForFolder(newOwner: string, target: string) {
|
||||
let cmd = "sudo";
|
||||
let args = ["chown", "-R", newOwner, target];
|
||||
cp.execFileSync(cmd, args);
|
||||
}
|
||||
|
||||
export function isAgentInstalled(platform: NodeJS.Platform) {
|
||||
switch (platform) {
|
||||
case "linux":
|
||||
return fs.existsSync("/home/agent/agent.status");
|
||||
case "win32":
|
||||
return fs.existsSync("C:\\agent\\agent.status");
|
||||
case "darwin":
|
||||
return fs.existsSync("/opt/step-security/agent.status");
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldDeployAgentOnSelfHosted(
|
||||
deployOnSelfHostedVm: boolean,
|
||||
isContainer: boolean,
|
||||
agentAlreadyInstalled: boolean
|
||||
): boolean {
|
||||
return deployOnSelfHostedVm && !isContainer && !agentAlreadyInstalled;
|
||||
}
|
||||
|
||||
export type ThirdPartyRunnerProvider = "depot" | "namespace" | "warp" | "blacksmith";
|
||||
|
||||
export function detectThirdPartyRunnerProvider(): ThirdPartyRunnerProvider | null {
|
||||
if (process.env["DEPOT_RUNNER"] === "1") return "depot";
|
||||
if (process.env["NAMESPACE_GITHUB_RUNTIME"]) return "namespace";
|
||||
const runnerName = process.env["RUNNER_NAME"] ?? "";
|
||||
if (runnerName.startsWith("warp-")) return "warp";
|
||||
if (runnerName.startsWith("blacksmith-")) return "blacksmith";
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getAnnotationLogs(platform: NodeJS.Platform) {
|
||||
switch (platform) {
|
||||
case "linux":
|
||||
return fs.readFileSync("/home/agent/annotation.log", "utf8");
|
||||
case "win32":
|
||||
return fs.readFileSync("C:\\agent\\annotation.log", "utf8");
|
||||
case "darwin":
|
||||
return fs.readFileSync("/opt/step-security/annotation.log", "utf8");
|
||||
default:
|
||||
throw new Error("platform not supported");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue