Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aefd2a8358 | ||
|
|
4fcd5054a5 | ||
|
|
840250fc42 | ||
|
|
61c2ffb99a |
@@ -1,33 +0,0 @@
|
||||
module.exports = {
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"files": [
|
||||
".eslintrc.{js,cjs}"
|
||||
],
|
||||
"parserOptions": {
|
||||
"sourceType": "script"
|
||||
}
|
||||
}
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,13 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v1
|
||||
- uses: step-security/harden-runner@1f99358870fe1c846a3ccba386cc2b2246836776 # v1
|
||||
with:
|
||||
egress-policy: audit
|
||||
allowed-endpoints:
|
||||
allowed-endpoints:
|
||||
api.github.com:443
|
||||
github.com:443
|
||||
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v2
|
||||
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v2
|
||||
- name: Update the rc tag
|
||||
uses: step-security/publish-action@b438f840875fdcb7d1de4fc3d1d30e86cf6acb5d
|
||||
with:
|
||||
|
||||
@@ -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@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
|
||||
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
|
||||
@@ -41,16 +41,16 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423
|
||||
uses: step-security/harden-runner@1f99358870fe1c846a3ccba386cc2b2246836776
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@cdcdbb579706841c47f7063dda365e292e5cad7a
|
||||
uses: github/codeql-action/init@16964e90ba004cdf0cd845b866b5df21038b7723
|
||||
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@16964e90ba004cdf0cd845b866b5df21038b7723
|
||||
|
||||
# ℹ️ 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@16964e90ba004cdf0cd845b866b5df21038b7723
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
# Dependency Review Action
|
||||
#
|
||||
# This Action will scan dependency manifest files that change as part of a Pull Request,
|
||||
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
|
||||
# Once installed, if the workflow run is marked as required,
|
||||
# PRs introducing known-vulnerable packages will be blocked from merging.
|
||||
#
|
||||
# Source repository: https://github.com/actions/dependency-review-action
|
||||
name: 'Dependency Review'
|
||||
on: [pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
dependency-review:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: 'Checkout Repository'
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
- name: 'Dependency Review'
|
||||
uses: actions/dependency-review-action@6c5ccdad469c9f8a2996bfecaec55a631a347034 # v3.1.0
|
||||
@@ -6,14 +6,14 @@ on:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
|
||||
jobs:
|
||||
int-tests:
|
||||
name: int tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423
|
||||
uses: step-security/harden-runner@1f99358870fe1c846a3ccba386cc2b2246836776
|
||||
with:
|
||||
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
|
||||
|
||||
|
||||
@@ -25,14 +25,13 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423
|
||||
- uses: step-security/harden-runner@1f99358870fe1c846a3ccba386cc2b2246836776
|
||||
with:
|
||||
egress-policy: audit
|
||||
allowed-endpoints:
|
||||
allowed-endpoints:
|
||||
api.github.com:443
|
||||
github.com:443
|
||||
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||
- name: Update the rc tag
|
||||
uses: step-security/publish-action@b438f840875fdcb7d1de4fc3d1d30e86cf6acb5d
|
||||
with:
|
||||
|
||||
@@ -24,18 +24,13 @@ jobs:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
|
||||
with:
|
||||
egress-policy: audit
|
||||
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v3.0.0
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # tag=v3.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # tag=v1.1.1
|
||||
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # tag=v1.1.1
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
@@ -54,7 +49,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@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # tag=v3.0.0
|
||||
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # tag=v3.0.0
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
@@ -62,6 +57,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@16964e90ba004cdf0cd845b866b5df21038b7723 # tag=v1.0.26
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
||||
@@ -16,12 +16,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
|
||||
uses: step-security/harden-runner@1f99358870fe1c846a3ccba386cc2b2246836776 # v2.2.1
|
||||
with:
|
||||
disable-sudo: true
|
||||
egress-policy: audit
|
||||
egress-policy: block
|
||||
allowed-endpoints: >
|
||||
api.github.com:443
|
||||
codecov.io:443
|
||||
github.com:443
|
||||
registry.npmjs.org:443
|
||||
@@ -29,9 +28,9 @@ jobs:
|
||||
uploader.codecov.io:443
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
- name: Run coverage
|
||||
run: npm test -- --coverage
|
||||
- uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
|
||||
- uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
|
||||
@@ -104,4 +104,4 @@ typings/
|
||||
.tern-port
|
||||
|
||||
# vscode files
|
||||
.vscode
|
||||
.vscode
|
||||
@@ -1,15 +0,0 @@
|
||||
exclude: ^dist/
|
||||
repos:
|
||||
- repo: https://github.com/gitleaks/gitleaks
|
||||
rev: v8.16.3
|
||||
hooks:
|
||||
- id: gitleaks
|
||||
- repo: https://github.com/pre-commit/mirrors-eslint
|
||||
rev: v8.38.0
|
||||
hooks:
|
||||
- id: eslint
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
hooks:
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
@@ -1,7 +1,7 @@
|
||||
<p align="center">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="images/banner.png" width="400">
|
||||
<img alt="Dark Banner" src="images/banner-dark.png" width="400">
|
||||
<img src="images/banner.png" width="400">
|
||||
</picture>
|
||||
</p>
|
||||
|
||||
@@ -13,221 +13,160 @@
|
||||
|
||||
</div>
|
||||
|
||||
## GitHub Actions Runtime Security
|
||||
---
|
||||
|
||||
Harden-Runner provides runtime security for GitHub-hosted and self-hosted environments.
|
||||
Harden-Runner GitHub Action installs a security agent on the GitHub-hosted runner (Ubuntu VM) to
|
||||
|
||||
For self-hosted environments, Harden-Runner supports:
|
||||
1. Prevent exfiltration of credentials
|
||||
2. Detect tampering of source code during build
|
||||
3. Detect compromised dependencies and build tools
|
||||
|
||||
1. Kubernetes runners setup using Actions Runner Controller (ARC)
|
||||
2. Virtual Machine runners (e.g. on EC2) - both ephemeral and persistent runners are supported
|
||||
|
||||
[](https://youtu.be/fpdwX5hYACo)
|
||||
|
||||
## Explore open source projects using Harden-Runner
|
||||
|
||||
| [](https://app.stepsecurity.io/github/cisagov/skeleton-generic/actions/runs/6199340224) | [](https://app.stepsecurity.io/github/microsoft/ebpf-for-windows/actions/runs/5559160177) | [](https://app.stepsecurity.io/github/GoogleCloudPlatform/functions-framework-ruby/actions/runs/5546354505) | [](https://app.stepsecurity.io/github/DataDog/stratus-red-team/actions/runs/5387101451) | [](https://app.stepsecurity.io/github/intel/cve-bin-tool/actions/runs/5579910614) | [](https://app.stepsecurity.io/github/kubernetes-sigs/cluster-api-provider-azure/actions/runs/5581511101) | [](https://app.stepsecurity.io/github/nodejs/node/actions/runs/5563468674) | [](https://app.stepsecurity.io/github/Mastercard/flow/actions/runs/5542112873) |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **CISA**<br>[Explore](https://app.stepsecurity.io/github/cisagov/skeleton-generic/actions/runs/6199340224) | **Microsoft**<br>[Explore](https://app.stepsecurity.io/github/microsoft/ebpf-for-windows/actions/runs/5559160177) | **Google**<br>[Explore](https://app.stepsecurity.io/github/GoogleCloudPlatform/functions-framework-ruby/actions/runs/5546354505) | **DataDog**<br>[Explore](https://app.stepsecurity.io/github/DataDog/stratus-red-team/actions/runs/5387101451) | **Intel**<br>[Explore](https://app.stepsecurity.io/github/intel/cve-bin-tool/actions/runs/5579910614) | **Kubernetes**<br>[Explore](https://app.stepsecurity.io/github/kubernetes-sigs/cluster-api-provider-azure/actions/runs/5581511101) | **Node.js**<br>[Explore](https://app.stepsecurity.io/github/nodejs/node/actions/runs/5563468674) | **Mastercard**<br>[Explore](https://app.stepsecurity.io/github/Mastercard/flow/actions/runs/5542112873) |
|
||||
|
||||
## 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)
|
||||
<p align="center">
|
||||
<img src="images/demo.gif" alt="Harden Runner demo">
|
||||
</p>
|
||||
|
||||
## Why
|
||||
|
||||
Compromised workflows, dependencies, and build tools typically make outbound calls to exfiltrate credentials, or may tamper source code, dependencies, or artifacts during the build.
|
||||
Compromised dependencies and build tools typically make outbound calls to exfiltrate credentials, or may tamper source code, dependencies, or artifacts during the build.
|
||||
|
||||
Harden-Runner monitors process, file, and network activity to:
|
||||
Harden-Runner GitHub Actions installs a daemon that monitors process, file, and network activity to:
|
||||
|
||||
| | Countermeasure | Prevent Security Breach |
|
||||
| --- | ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1. | Block egress traffic at the DNS (Layer 7) and network layers (Layers 3 and 4) to prevent exfiltration of code and CI/CD credentials | To prevent [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 [SolarWinds incident](https://github.com/step-security/github-actions-goat/blob/main/docs/Vulnerabilities/TamperingDuringBuild.md) scenario |
|
||||
| 3. | Detect poisoned workflows and compromised dependencies | 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) |
|
||||
| | Countermeasure | Threat |
|
||||
| --- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1. | Block outbound calls that are not in the allowed list to prevent exfiltration of credentials | To prevent [Codecov breach](https://github.com/step-security/attack-simulator/blob/main/docs/RestrictOutboundTraffic.md) scenario |
|
||||
| 2. | Detect if source code is being overwritten during the build process to inject a backdoor | To detect [SolarWinds incident scenario](https://github.com/step-security/attack-simulator/blob/main/docs/MonitorSourceCode.md) |
|
||||
| 3. | Detect compromised dependencies that make unexpected outbound network calls | To detect [Dependency confusion](https://github.com/step-security/attack-simulator/blob/main/docs/DNSExfiltration.md) and [Malicious dependencies](https://github.com/step-security/attack-simulator/blob/main/docs/CompromisedDependency.md) |
|
||||
|
||||
Read this [case study](https://infosecwriteups.com/detecting-malware-packages-in-github-actions-7b93a9985635) on how Harden-Runner detected malicious packages in the NPM registry.
|
||||
|
||||
## How
|
||||
|
||||
### GitHub-Hosted Runners
|
||||
|
||||
1. Add `step-security/harden-runner` GitHub Action to your GitHub Actions workflow file as the first step in each job.
|
||||
1. Add `step-security/harden-runner` to your GitHub Actions workflow file as the first step in each job.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: step-security/harden-runner@1b05615854632b887b69ae1be8cbefe72d3ae423 # v2.6.0
|
||||
- uses: step-security/harden-runner@1f99358870fe1c846a3ccba386cc2b2246836776 # v2.2.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.
|
||||
2. In the workflow logs, 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/microsoft/msquic/actions/runs/5577342236)). You will see a process monitor view of network and file events correlated with each step of the job.
|
||||
3. Click on the link ([example link](https://app.stepsecurity.io/github/ossf/scorecard/actions/runs/2265028928)). You will see a process monitor view of file and network activities correlated with each step of the job.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/insights-5.png" alt="Insights from harden-runner" >
|
||||
<img src="images/insights2.png" alt="Insights from harden-runner" >
|
||||
</p>
|
||||
|
||||
4. Under the insights section, you'll find a Recommended Policy. You can either 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.
|
||||
4. Under the insights section, you'll find a suggested policy. You can either 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.
|
||||
|
||||
<p align="left">
|
||||
<img src="images/rec-policy1.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
|
||||
### 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 and scales self-hosted runners for GitHub Actions.
|
||||
|
||||
- Instead of adding the Harden-Runner GitHub Action in each workflow, you'll need to install the ARC Harden-Runner daemonset on your Kubernetes cluster.
|
||||
- Upon installation, the ARC Harden-Runner daemonset constantly monitors each workflow run; 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 for `block` mode.
|
||||
- You can access security insights and runtime detections under the `Runtime Security` tab in your dashboard.
|
||||
|
||||
### 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 workflow, you'll need to install the Harden-Runner agent on your runner image (e.g. AMI). This is typically done using packer.
|
||||
- The Harden-Runner agent monitors each job 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 for `block` mode.
|
||||
- You can access security insights and runtime detections under the `Runtime Security` tab in your dashboard.
|
||||
|
||||
## Support for Self-Hosted Runners and Private Repositories
|
||||
|
||||
Runtime security for self-hosted runners and private repositories are supported with a commercial license. Check out the [documentation](https://docs.stepsecurity.io/stepsecurity-platform/billing) for more details.
|
||||
|
||||
- Install the [StepSecurity Actions Security GitHub App](https://github.com/apps/stepsecurity-actions-security) to use Harden-Runner GitHub Action for `Private` repositories.
|
||||
- If you use Harden-Runner GitHub Action in a private repository, the generated insights URL is NOT public.
|
||||
- You need to authenticate first to access insights URL for private repository. Only those who have access to the repository can view it.
|
||||
|
||||
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.
|
||||
|
||||
## Features at a glance
|
||||
|
||||
For details, check out the documentation at https://docs.stepsecurity.io
|
||||
|
||||
### 👀 Monitor egress traffic
|
||||
<p align="left">
|
||||
<img src="images/main-screenshot1.png" alt="Policy recommended by harden-runner">
|
||||
</p>
|
||||
|
||||
> 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 past job runs
|
||||
|
||||
### 🚦 Filter egress traffic to allowed endpoints
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
### Restrict egress traffic to allowed endpoints
|
||||
|
||||
Once allowed endpoints are set in the policy 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)
|
||||
|
||||
- Harden-Runner blocks egress traffic at the DNS (Layer 7) and network layers (Layers 3 and 4)
|
||||
- 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`
|
||||
- Blocks outbound traffic using IP tables
|
||||
|
||||
<p align="left">
|
||||
<img src="images/blocked-outbound-call-2.png" alt="Policy recommended by harden-runner" >
|
||||
<img src="images/block-outbound-call.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
|
||||
### 🤖 Select GitHub Actions with Confidence
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
Before integrating a GitHub Action into your workflow, evaluate its network activity.
|
||||
|
||||
- Access network behavior data for hundreds of GitHub Actions, compiled from thousands of workflow runs that use Harden-Runner in public repositories
|
||||
- Search for a GitHub Action and view a comprehensive report of its outbound network traffic
|
||||
- Use this insight to make educated choices about incorporating GitHub Actions into your projects
|
||||
|
||||
<p align="left">
|
||||
<img src="images/network-behavior.png" alt="Networking behavior of an Action" >
|
||||
</p>
|
||||
|
||||
### 📁 Detect tampering of source code during build
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
### Detect tampering of source code during build
|
||||
|
||||
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-overwritten.png" alt="Policy recommended by harden-runner" >
|
||||
<img src="images/fileoverwrite.png" alt="Policy recommended by harden-runner" >
|
||||
</p>
|
||||
|
||||
### 🚫 Run your job without sudo access
|
||||
|
||||
> Applies to GitHub-hosted runners
|
||||
### Run your job without sudo access
|
||||
|
||||
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
|
||||
- When you set `disable-sudo` to `true`, the job steps run without sudo access to the Ubuntu VM
|
||||
|
||||
### 🔔 Get security alerts
|
||||
### Get security alerts
|
||||
|
||||
> Applies to both GitHub-hosted and self-hosted runners
|
||||
|
||||
Install the [StepSecurity Actions Security GitHub App](https://github.com/apps/stepsecurity-actions-security) to get security alerts.
|
||||
Install the [Harden Runner App](https://github.com/marketplace/harden-runner-app) to get security alerts.
|
||||
|
||||
- Email and Slack notifications are supported
|
||||
- Notifications are sent when outbound traffic is blocked or source code is overwritten
|
||||
- Notifications are not repeated for the same alert for a given workflow
|
||||
|
||||
## Support for private repositories
|
||||
|
||||
Private repositories are supported if they have a commercial license. Check out the [documentation](https://docs.stepsecurity.io/harden-runner/installation/business-enterprise-license) for more details.
|
||||
|
||||
Install the [Harden Runner App](https://github.com/marketplace/harden-runner-app) to use Harden-Runner GitHub Action for `Private` repositories.
|
||||
|
||||
- If you use Harden-Runner GitHub Action in a private repository, the generated insights URL is NOT public.
|
||||
- You need to authenticate first to access insights URL for private repository. Only those who have access to the repository can view it.
|
||||
- [Harden Runner App](https://github.com/marketplace/harden-runner-app) only needs `actions: read` permissions on your repositories.
|
||||
|
||||
Read this [case study on how Kapiche uses Harden Runner](https://www.stepsecurity.io/case-studies/kapiche/) to improve software supply chain security in their open source and private repositories.
|
||||
|
||||
## 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
|
||||
If you have questions or ideas, please use [discussions](https://github.com/step-security/harden-runner/discussions).
|
||||
|
||||
1. [Support for private repositories](https://github.com/step-security/harden-runner/discussions/74)
|
||||
2. [Where should allowed-endpoints be stored?](https://github.com/step-security/harden-runner/discussions/84)
|
||||
3. [Cryptographically verify tools run as part of the CI/ CD pipeline](https://github.com/step-security/harden-runner/discussions/94)
|
||||
|
||||
## Limitations
|
||||
|
||||
1. Harden-Runner GitHub Action only works for GitHub-hosted runners. Self-hosted runners are not supported. We have started work on supporting [Kubernetes-Based Self-Hosted Actions Runners](https://github.com/step-security/harden-runner/issues/104).
|
||||
2. Only Ubuntu VM is supported. Windows and MacOS GitHub-hosted runners are not supported. There is a discussion about that [here](https://github.com/step-security/harden-runner/discussions/121).
|
||||
3. Harden-Runner is not supported when [job is run in a container](https://docs.github.com/en/actions/using-jobs/running-jobs-in-a-container) as it needs sudo access on the Ubuntu VM to run. It can be used to monitor jobs that use containers to run steps. The limitation is if the entire job is run in a container. That is not common for GitHub Actions workflows, as most of them run directly on `ubuntu-latest`.
|
||||
|
||||
## Testimonials
|
||||
|
||||
> _I think this is a great idea and for the threat model of build-time, an immediate network egress request monitoring makes a lot of sense_ - [Liran Tal](https://stars.github.com/profiles/lirantal/), GitHub Star, and Author of Essential Node.js Security
|
||||
|
||||
> _Harden-Runner strikes an elegant balance between ease-of-use, maintainability, and mitigation that I intend to apply to all of my 300+ npm packages. I look forward to the tool’s improvement over time_ - [Jordan Harband](https://github.com/ljharb), Open Source Maintainer
|
||||
|
||||
> _Harden runner from Step security is such a nice solution, it is another piece of the puzzle in helping treat the CI environment like production and solving supply chain security. I look forward to seeing it evolve._ - Cam Parry, Staff Site Reliability Engineer, Kapiche
|
||||
|
||||
## Workflows using harden-runner
|
||||
|
||||
Some important workflows using harden-runner:
|
||||
| |Repository |Link to insights|
|
||||
|--|----------|----------------|
|
||||
|1.|[nvm-sh/nvm](https://github.com/nvm-sh/nvm/blob/master/.github/workflows/lint.yml)|[Link to insights](https://app.stepsecurity.io/github/nvm-sh/nvm/actions/runs/1757959262)|
|
||||
|2.|[jsx-eslint/eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/.github/workflows/release.yml)|[Link to insights](https://app.stepsecurity.io/github/yannickcr/eslint-plugin-react/actions/runs/1930818585)
|
||||
|3.|[microsoft/msquic](https://github.com/microsoft/msquic/blob/main/.github/workflows/docker-publish.yml)|[Link to insights](https://app.stepsecurity.io/github/microsoft/msquic/actions/runs/1759010243)
|
||||
|4.|[ossf/scorecard](https://github.com/ossf/scorecard/blob/main/.github/workflows/codeql-analysis.yml)|[Link to insights](https://app.stepsecurity.io/github/ossf/scorecard/actions/runs/2006162141)
|
||||
|5.|[Automattic/vip-go-mu-plugins](https://github.com/Automattic/vip-go-mu-plugins/blob/master/.github/workflows/e2e.yml)|[Link to insights](https://app.stepsecurity.io/github/Automattic/vip-go-mu-plugins/actions/runs/1758760957)
|
||||
|
||||
## How does it work?
|
||||
|
||||
### GitHub-Hosted Runners
|
||||
|
||||
For GitHub-hosted runners, Harden-Runner GitHub Action downloads and installs the StepSecurity Agent.
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
1. Since ARC Harden Runner uses eBPF, only Linux jobs are supported. Windows and MacOS jobs are not supported.
|
||||
|
||||
### Self-Hosted VM Runners (e.g. on EC2)
|
||||
|
||||
1. Only Ubuntu VM is supported. Windows and MacOS jobs are not supported.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: "Harden-Runner"
|
||||
description: "Harden-Runner provides runtime security for GitHub-hosted and self-hosted runners"
|
||||
name: "Harden Runner"
|
||||
description: "Security agent for GitHub-hosted runner to monitor the build process"
|
||||
inputs:
|
||||
allowed-endpoints:
|
||||
description: "Only these endpoints will be allowed if egress-policy is set to block"
|
||||
@@ -33,7 +33,7 @@ branding:
|
||||
icon: "check-square"
|
||||
color: "green"
|
||||
runs:
|
||||
using: "node20"
|
||||
using: "node16"
|
||||
pre: "dist/pre/index.js"
|
||||
main: "dist/index.js"
|
||||
post: "dist/post/index.js"
|
||||
|
||||
|
Before Width: | Height: | Size: 3.9 MiB |
|
Before Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 456 KiB |
|
Before Width: | Height: | Size: 66 KiB |
@@ -1,5 +1,5 @@
|
||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
export default {
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
};
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "step-security-harden-runner",
|
||||
"version": "2.6.1",
|
||||
"description": "Security agent for GitHub-hosted runner: block egress traffic & detect code overwrite to prevent breaches",
|
||||
"version": "2.3.0",
|
||||
"description": "Security agent for GitHub-hosted runner to monitor the build process",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "npm run main && npm run pre && npm run post",
|
||||
@@ -26,27 +26,26 @@
|
||||
"@actions/cache": "^3.1.4",
|
||||
"@actions/core": "^1.5.0",
|
||||
"@actions/exec": "^1.1.0",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@actions/github": "^5.0.0",
|
||||
"@actions/http-client": "^2.0.1",
|
||||
"@actions/tool-cache": "^1.7.1",
|
||||
"ansi-regex": ">=5.0.1",
|
||||
"axios": "^1.6.1",
|
||||
"is-docker": "^3.0.0",
|
||||
"node-fetch": ">=3.2.0",
|
||||
"uuid": "^9.0.1"
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.8",
|
||||
"@types/node": "^20.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
||||
"@typescript-eslint/parser": "^6.1.0",
|
||||
"@vercel/ncc": "0.38.0",
|
||||
"eslint": "^8.53.0",
|
||||
"@types/jest": "^27.5.2",
|
||||
"@types/node": "^16.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.29.2",
|
||||
"@typescript-eslint/parser": "^4.29.2",
|
||||
"@vercel/ncc": "^0.30.0",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"jest": "^29.3.1",
|
||||
"jest-junit": ">=13.0.0",
|
||||
"nock": "^13.3.0",
|
||||
"ts-jest": "^29.0.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.2.2"
|
||||
"typescript": "^4.3.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
|
||||
|
||||
it("should correctly recognize arc based runner", async () => {
|
||||
process.env["GITHUB_ACTIONS_RUNNER_EXTRA_USER_AGENT"] =
|
||||
"actions-runner-controller/2.0.1";
|
||||
|
||||
let isArc: boolean = await isArcRunner();
|
||||
expect(isArc).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
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,62 +0,0 @@
|
||||
import * as cp from "child_process";
|
||||
import * as fs from "fs";
|
||||
import { sleep } from "./setup";
|
||||
|
||||
export function isArcRunner(): boolean {
|
||||
const runnerUserAgent = process.env["GITHUB_ACTIONS_RUNNER_EXTRA_USER_AGENT"];
|
||||
|
||||
let isARC = false;
|
||||
|
||||
if (!runnerUserAgent) {
|
||||
isARC = false;
|
||||
} else {
|
||||
isARC = runnerUserAgent.includes("actions-runner-controller/");
|
||||
}
|
||||
|
||||
return isARC || isSecondaryPod();
|
||||
}
|
||||
|
||||
function isSecondaryPod(): boolean {
|
||||
const workDir = "/__w";
|
||||
return fs.existsSync(workDir);
|
||||
}
|
||||
|
||||
function getRunnerTempDir(): string {
|
||||
const isTest = process.env["isTest"];
|
||||
|
||||
if (isTest === "1") {
|
||||
return "/tmp";
|
||||
}
|
||||
|
||||
return process.env["RUNNER_TEMP"] || "/tmp";
|
||||
}
|
||||
|
||||
export function sendAllowedEndpoints(endpoints: string): void {
|
||||
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}"`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (allowedEndpoints.length > 0) {
|
||||
applyPolicy(allowedEndpoints.length);
|
||||
}
|
||||
}
|
||||
|
||||
function applyPolicy(count: number): void {
|
||||
const fileName = `step_policy_apply_${count}`;
|
||||
cp.execSync(`echo "${fileName}" > "${getRunnerTempDir()}/${fileName}"`);
|
||||
}
|
||||
|
||||
export function removeStepPolicyFiles() {
|
||||
cp.execSync(`rm ${getRunnerTempDir()}/step_policy_*`);
|
||||
}
|
||||
|
||||
export function arcCleanUp() {
|
||||
cp.execSync(`echo "cleanup" > "${getRunnerTempDir()}/step_policy_cleanup"`);
|
||||
}
|
||||
@@ -19,4 +19,4 @@ export enum CompressionMethod {
|
||||
const RefKey = "GITHUB_REF";
|
||||
export function isValidEvent(): boolean {
|
||||
return RefKey in process.env && Boolean(process.env[RefKey]);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ export function verifyChecksum(downloadPath: string) {
|
||||
.digest("hex"); // checksum of downloaded file
|
||||
|
||||
const expectedChecksum: string =
|
||||
"ceb925c78e5c79af4f344f08f59bbdcf3376d20d15930a315f9b24b6c4d0328a"; // checksum for v0.13.5
|
||||
"10fd5587cfeba6aac4125be78ee32f60d5e780de10929f454525670c4c16935d"; // checksum for v0.12.2
|
||||
|
||||
if (checksum !== expectedChecksum) {
|
||||
core.setFailed(
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import * as fs from "fs";
|
||||
import * as cp from "child_process";
|
||||
import * as core from "@actions/core";
|
||||
import * as common from "./common";
|
||||
import isDocker from "is-docker";
|
||||
import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
||||
import * as cache from "@actions/cache";
|
||||
import { cacheFile, cacheKey, isValidEvent } from "./cache";
|
||||
import path from "path";
|
||||
|
||||
(async () => {
|
||||
if (process.platform !== "linux") {
|
||||
@@ -14,17 +17,6 @@ import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
||||
return;
|
||||
}
|
||||
|
||||
if (isArcRunner()) {
|
||||
console.log(`[!] ${common.ARC_RUNNER_MESSAGE}`);
|
||||
arcCleanUp();
|
||||
removeStepPolicyFiles();
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.STATE_selfHosted === "true") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
String(process.env.STATE_monitorStatusCode) ===
|
||||
common.STATUS_HARDEN_RUNNER_UNAVAILABLE
|
||||
@@ -38,8 +30,8 @@ import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
||||
JSON.stringify({ event: "post" })
|
||||
);
|
||||
|
||||
const doneFile = "/home/agent/done.json";
|
||||
let counter = 0;
|
||||
var doneFile = "/home/agent/done.json";
|
||||
var counter = 0;
|
||||
while (true) {
|
||||
if (!fs.existsSync(doneFile)) {
|
||||
counter++;
|
||||
@@ -55,7 +47,7 @@ import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
||||
}
|
||||
}
|
||||
|
||||
const log = "/home/agent/agent.log";
|
||||
var log = "/home/agent/agent.log";
|
||||
if (fs.existsSync(log)) {
|
||||
console.log("log:");
|
||||
var content = fs.readFileSync(log, "utf-8");
|
||||
@@ -69,6 +61,15 @@ import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
||||
console.log(content);
|
||||
}
|
||||
|
||||
// write annotations
|
||||
var annotationsFile = "/home/agent/annotation.log";
|
||||
if (fs.existsSync(annotationsFile)) {
|
||||
var content = fs.readFileSync(annotationsFile, "utf-8");
|
||||
content.split(/\r?\n/).forEach((line) => {
|
||||
core.error(line);
|
||||
});
|
||||
}
|
||||
|
||||
var disable_sudo = process.env.STATE_disableSudo;
|
||||
if (disable_sudo !== "true") {
|
||||
var journalLog = cp.execSync("sudo journalctl -u agent.service", {
|
||||
@@ -78,6 +79,18 @@ import { arcCleanUp, isArcRunner, removeStepPolicyFiles } from "./arc-runner";
|
||||
console.log(journalLog);
|
||||
}
|
||||
|
||||
if (isValidEvent()) {
|
||||
try {
|
||||
const cmd = "cp";
|
||||
const args = [path.join(__dirname, "cache.txt"), cacheFile];
|
||||
cp.execFileSync(cmd, args);
|
||||
const cacheResult = await cache.saveCache([cacheFile], cacheKey);
|
||||
console.log(cacheResult);
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await common.addSummary();
|
||||
} catch (exception) {
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
import { processLogLine } from "./common"; // import the function
|
||||
import { addSummary } from "./common";
|
||||
import * as cp from "child_process";
|
||||
|
||||
describe("processLogLine function", () => {
|
||||
it("correctly processes the log line and adds an entry to the array", () => {
|
||||
const tableEntries: {
|
||||
pid: string;
|
||||
process: string;
|
||||
domain: string;
|
||||
ipAddress: string;
|
||||
status: string;
|
||||
}[] = [];
|
||||
const logLine =
|
||||
"Thu, 15 Jun 2023 05:35:29 GMT:endpoint called ip address:port 104.16.24.35:443, domain: registry.npmjs.org., pid: 2135, process: node.";
|
||||
test("adding stepsecurity summary in github_summary", async () => {
|
||||
let expected = `<hr>
|
||||
<img src="https://github.com/step-security/harden-runner/raw/main/images/banner.png" alt="StepSecurity Harden-Runner" width="200">
|
||||
<a href="https://app.stepsecurity.io/github/step-security/test/actions/runs/12345">View security insights and recommended policy</a>
|
||||
<hr>
|
||||
`;
|
||||
|
||||
processLogLine(logLine, tableEntries);
|
||||
const github_summary = "/tmp/github_summary";
|
||||
cp.execSync(`touch ${github_summary}`);
|
||||
|
||||
// Check if a single entry is added to the array
|
||||
expect(tableEntries.length).toBe(1);
|
||||
process.env["STATE_monitorStatusCode"] = "200";
|
||||
process.env["GITHUB_STEP_SUMMARY"] = github_summary;
|
||||
process.env["GITHUB_REPOSITORY"] = "step-security/test";
|
||||
process.env["GITHUB_RUN_ID"] = "12345";
|
||||
|
||||
// Check if the entry's properties are set correctly
|
||||
const entry = tableEntries[0];
|
||||
expect(entry.pid).toBe("2135");
|
||||
expect(entry.process).toBe("node");
|
||||
expect(entry.domain).toBe("registry.npmjs.org.");
|
||||
expect(entry.ipAddress).toBe("104.16.24.35:443");
|
||||
expect(entry.status).toBe("✅ Allowed"); // Since the IP address is not '54.185.253.63', status should be '✔️ Allowed'
|
||||
});
|
||||
});
|
||||
await addSummary();
|
||||
|
||||
let output = cp.execSync(`cat ${github_summary}`).toString();
|
||||
cp.execSync(`rm ${github_summary}`);
|
||||
|
||||
expect(output).toMatch(expected);
|
||||
|
||||
});
|
||||
@@ -1,6 +1,4 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as fs from "fs";
|
||||
|
||||
export function printInfo(web_url) {
|
||||
console.log(
|
||||
"\x1b[32m%s\x1b[0m",
|
||||
@@ -11,150 +9,22 @@ export function printInfo(web_url) {
|
||||
`${web_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}`
|
||||
);
|
||||
}
|
||||
|
||||
export const processLogLine = (
|
||||
line: string,
|
||||
tableEntries: {
|
||||
pid: string;
|
||||
process: string;
|
||||
domain: string;
|
||||
ipAddress: string;
|
||||
status: string;
|
||||
}[]
|
||||
): void => {
|
||||
if (
|
||||
line.includes("pid") &&
|
||||
line.includes("process") &&
|
||||
line.includes("domain") &&
|
||||
line.includes("ip address")
|
||||
) {
|
||||
const matches = line.match(
|
||||
/ip address:port ([\d.:]+), domain: ([\w.-]+), pid: (\d+), process: (\w+)/
|
||||
);
|
||||
if (matches) {
|
||||
const [ipAddress, domain, pid, process] = matches.slice(1);
|
||||
|
||||
// Check if all values are non-empty
|
||||
if (pid && process && domain && ipAddress) {
|
||||
const status = ipAddress.startsWith("54.185.253.63")
|
||||
? "❌ Blocked"
|
||||
: "✅ Allowed";
|
||||
|
||||
tableEntries.push({ pid, process, domain, ipAddress, status });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export async function addSummary() {
|
||||
if (process.env.STATE_monitorStatusCode !== "200") {
|
||||
return;
|
||||
}
|
||||
if (process.env.STATE_monitorStatusCode === "200") {
|
||||
const web_url = "https://app.stepsecurity.io";
|
||||
const insights_url = `${web_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}`;
|
||||
|
||||
const web_url = "https://app.stepsecurity.io";
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let needsSubscription = false;
|
||||
try {
|
||||
let data = fs.readFileSync("/home/agent/annotation.log", "utf8");
|
||||
if (data.includes("StepSecurity Harden Runner is disabled")) {
|
||||
needsSubscription = true;
|
||||
}
|
||||
} catch (err) {
|
||||
//console.error(err);
|
||||
}
|
||||
|
||||
if (needsSubscription) {
|
||||
await core.summary
|
||||
.addSeparator()
|
||||
.addRaw(
|
||||
`<h2>⚠️ Your GitHub Actions Runtime Security is currently disabled!</h2>`
|
||||
);
|
||||
|
||||
await core.summary
|
||||
.addRaw(
|
||||
`
|
||||
<p>It appears that you're using the <a href="https://github.com/step-security/harden-runner">Harden-Runner GitHub Action</a> by StepSecurity within a private repository. However, runtime security is not enabled as your organization hasn't signed up for a free trial or a paid subscription yet.</p>
|
||||
<p>To enable runtime security, start a free trial today by installing the <a href="https://github.com/apps/stepsecurity-actions-security">StepSecurity Actions Security GitHub App</a>. For more information or assistance, feel free to reach out to us through our <a href="https://www.stepsecurity.io/contact">contact form</a>.</p>
|
||||
`
|
||||
.addImage(
|
||||
"https://github.com/step-security/harden-runner/raw/main/images/banner.png",
|
||||
"StepSecurity Harden-Runner",
|
||||
{ width: "200" }
|
||||
)
|
||||
.addLink("View security insights and recommended policy", insights_url)
|
||||
.addSeparator()
|
||||
.write();
|
||||
return;
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(log, "utf-8");
|
||||
const lines = content.split("\n");
|
||||
|
||||
let tableEntries = [];
|
||||
|
||||
for (const line of lines) {
|
||||
processLogLine(line, tableEntries);
|
||||
}
|
||||
|
||||
if (tableEntries.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const insightsRow = `<p><b><a href="${insights_url}">📄 View Full Report</a></b></p>`;
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
tableEntries = tableEntries.slice(0, 3);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
export const STATUS_HARDEN_RUNNER_UNAVAILABLE = "409";
|
||||
@@ -165,11 +35,5 @@ export const CONTAINER_MESSAGE =
|
||||
export const UBUNTU_MESSAGE =
|
||||
"This job is not running in a GitHub Actions Hosted Runner Ubuntu VM. Harden Runner is only supported on Ubuntu VM. This job will not be monitored.";
|
||||
|
||||
export const SELF_HOSTED_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 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";
|
||||
|
||||
@@ -18,7 +18,7 @@ test("success: fetching policy", async () => {
|
||||
.get(`/github/${owner}/actions/policies/${policyName}`)
|
||||
.reply(200, response);
|
||||
|
||||
let idToken = "xyz";
|
||||
let idToken = "xyz";
|
||||
let policy = await fetchPolicy(owner, policyName, idToken);
|
||||
console.log(policy);
|
||||
expect(policy).toStrictEqual(response);
|
||||
|
||||
@@ -23,7 +23,7 @@ export async function fetchPolicy(
|
||||
|
||||
let response = undefined;
|
||||
let err = undefined;
|
||||
|
||||
|
||||
let retry = 0;
|
||||
while(retry < 3){
|
||||
try{
|
||||
@@ -72,4 +72,4 @@ function sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as cp from "child_process";
|
||||
import * as fs from "fs";
|
||||
import axios from "axios";
|
||||
import * as httpm from "@actions/http-client";
|
||||
import * as path from "path";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import * as common from "./common";
|
||||
@@ -19,10 +19,9 @@ import {
|
||||
} from "./cache";
|
||||
import { Configuration, PolicyResponse } from "./interfaces";
|
||||
import { fetchPolicy, mergeConfigs } from "./policy-utils";
|
||||
import * as cache from "@actions/cache";
|
||||
import { getCacheEntry } from "@actions/cache/lib/internal/cacheHttpClient";
|
||||
import * as utils from "@actions/cache/lib/internal/cacheUtils";
|
||||
import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
|
||||
import {getCacheEntry} from "@actions/cache/lib/internal/cacheHttpClient"
|
||||
import * as utils from '@actions/cache/lib/internal/cacheUtils'
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
@@ -51,9 +50,25 @@ import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
disable_telemetry: core.getBooleanInput("disable-telemetry"),
|
||||
disable_sudo: core.getBooleanInput("disable-sudo"),
|
||||
disable_file_monitoring: core.getBooleanInput("disable-file-monitoring"),
|
||||
private: context?.payload?.repository?.private || false,
|
||||
private: context.payload.repository.private,
|
||||
};
|
||||
|
||||
let policyName = core.getInput("policy");
|
||||
if (policyName !== "") {
|
||||
console.log(`Fetching policy from API with name: ${policyName}`);
|
||||
try {
|
||||
let idToken: string = await core.getIDToken()
|
||||
let result: PolicyResponse = await fetchPolicy(
|
||||
context.repo.owner,
|
||||
policyName,
|
||||
idToken
|
||||
);
|
||||
confg = mergeConfigs(confg, result);
|
||||
} catch (err) {
|
||||
core.info(`[!] ${err}`);
|
||||
core.setFailed(err);
|
||||
}
|
||||
}
|
||||
fs.appendFileSync(
|
||||
process.env.GITHUB_STATE,
|
||||
`disableSudo=${confg.disable_sudo}${EOL}`,
|
||||
@@ -77,28 +92,38 @@ import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
core.setFailed("disable-telemetry must be a boolean value");
|
||||
}
|
||||
|
||||
if (isValidEvent() && confg.egress_policy === "block") {
|
||||
let _http = new httpm.HttpClient();
|
||||
let statusCode;
|
||||
_http.requestOptions = { socketTimeout: 3 * 1000 };
|
||||
try {
|
||||
const resp: httpm.HttpClientResponse = await _http.get(
|
||||
`${api_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}/monitor`
|
||||
);
|
||||
statusCode = resp.message.statusCode; // adding error code to check whether agent is getting installed or not.
|
||||
fs.appendFileSync(
|
||||
process.env.GITHUB_STATE,
|
||||
`monitorStatusCode=${statusCode}${EOL}`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(`error in connecting to ${api_url}: ${e}`);
|
||||
}
|
||||
|
||||
console.log(`Step Security Job Correlation ID: ${correlation_id}`);
|
||||
|
||||
if (String(statusCode) === common.STATUS_HARDEN_RUNNER_UNAVAILABLE) {
|
||||
console.log(common.HARDEN_RUNNER_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isValidEvent()) {
|
||||
try {
|
||||
const cacheResult = await cache.saveCache(
|
||||
[path.join(__dirname, "cache.txt")],
|
||||
cacheKey
|
||||
);
|
||||
console.log(cacheResult);
|
||||
} 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,
|
||||
}
|
||||
);
|
||||
let compressionMethod:CompressionMethod = await utils.getCompressionMethod()
|
||||
const cacheEntry:ArtifactCacheEntry = await getCacheEntry([cacheKey], [cacheFile], {
|
||||
compressionMethod: compressionMethod,
|
||||
});
|
||||
const url = new URL(cacheEntry.archiveLocation);
|
||||
core.info(`Adding cacheHost: ${url.hostname}:443 to allowed-endpoints`);
|
||||
confg.allowed_endpoints += ` ${url.hostname}:443`;
|
||||
@@ -112,72 +137,6 @@ import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
}
|
||||
}
|
||||
|
||||
if (!confg.disable_telemetry || confg.egress_policy === "audit") {
|
||||
common.printInfo(web_url);
|
||||
}
|
||||
|
||||
if (isArcRunner()) {
|
||||
console.log(`[!] ${common.ARC_RUNNER_MESSAGE}`);
|
||||
if (confg.egress_policy === "block") {
|
||||
sendAllowedEndpoints(confg.allowed_endpoints);
|
||||
await sleep(10000);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const runnerName = process.env.RUNNER_NAME || "";
|
||||
core.info(`RUNNER_NAME: ${runnerName}`);
|
||||
if (!runnerName.startsWith("GitHub Actions")) {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
//return;
|
||||
|
||||
let statusCode;
|
||||
//_http.requestOptions = { socketTimeout: 3 * 1000 };
|
||||
try {
|
||||
const resp = await axios.get(
|
||||
`${api_url}/github/${process.env["GITHUB_REPOSITORY"]}/actions/runs/${process.env["GITHUB_RUN_ID"]}/monitor`,
|
||||
{ timeout: 3000 }
|
||||
);
|
||||
|
||||
statusCode = resp.status; // adding error code to check whether agent is getting installed or not.
|
||||
console.log(`statuscode: ${statusCode}`);
|
||||
fs.appendFileSync(
|
||||
process.env.GITHUB_STATE,
|
||||
`monitorStatusCode=${statusCode}${EOL}`,
|
||||
{
|
||||
encoding: "utf8",
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(`error in connecting to ${api_url}: ${e}`);
|
||||
}
|
||||
//return;
|
||||
console.log(`Step Security Job Correlation ID: ${correlation_id}`);
|
||||
if (String(statusCode) === common.STATUS_HARDEN_RUNNER_UNAVAILABLE) {
|
||||
console.log(common.HARDEN_RUNNER_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
//return;
|
||||
const confgStr = JSON.stringify(confg);
|
||||
cp.execSync("sudo mkdir -p /home/agent");
|
||||
cp.execSync("sudo chown -R $USER /home/agent");
|
||||
@@ -187,14 +146,18 @@ import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
let auth = `token ${token}`;
|
||||
|
||||
const downloadPath: string = await tc.downloadTool(
|
||||
"https://github.com/step-security/agent/releases/download/v0.13.5/agent_0.13.5_linux_amd64.tar.gz",
|
||||
"https://github.com/step-security/agent/releases/download/v0.12.2/agent_0.12.2_linux_amd64.tar.gz",
|
||||
undefined,
|
||||
auth
|
||||
);
|
||||
|
||||
verifyChecksum(downloadPath); // NOTE: verifying agent's checksum, before extracting
|
||||
const extractPath = await tc.extractTar(downloadPath);
|
||||
//return;
|
||||
|
||||
if (!confg.disable_telemetry || confg.egress_policy === "audit") {
|
||||
common.printInfo(web_url);
|
||||
}
|
||||
|
||||
let cmd = "cp",
|
||||
args = [path.join(extractPath, "agent"), "/home/agent/agent"];
|
||||
cp.execFileSync(cmd, args);
|
||||
@@ -216,7 +179,6 @@ import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
var statusFile = "/home/agent/agent.status";
|
||||
var logFile = "/home/agent/agent.log";
|
||||
var counter = 0;
|
||||
await sleep(5000);
|
||||
while (true) {
|
||||
if (!fs.existsSync(statusFile)) {
|
||||
counter++;
|
||||
@@ -228,7 +190,6 @@ import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
}
|
||||
break;
|
||||
}
|
||||
console.log("sleeping");
|
||||
await sleep(300);
|
||||
} // The file *does* exist
|
||||
else {
|
||||
@@ -241,11 +202,9 @@ import { isArcRunner, sendAllowedEndpoints } from "./arc-runner";
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
console.log("method done");
|
||||
return;
|
||||
})();
|
||||
|
||||
export function sleep(ms) {
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
"exclude": [
|
||||
"src/**/*.test.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||