Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github: Add rule type that verifies that harden runner is the first step #141

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions rule-types/github/step_security_harden_runner_enabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
version: v1
type: rule-type
name: step_security_harden_runner_enabled
severity:
value: medium
context:
provider: github
description: Verifies that Step Security's harden-runner action is enabled
guidance: |
Step Security's harden-runner is not enabled in all pipelines!

harden-runner detects providers network egress filtering which is critical
for malicious pipeline detection in gitHub

Set it up by adding the following as the first step of each job:

```yaml
- uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
with:
egress-policy: audit
```

For more information, see https://github.com/step-security/harden-runner
def:
# Defines the section of the pipeline the rule will appear in.
# This will affect the template used to render multiple parts
# of the rule.
in_entity: repository
# Defines the schema for writing a rule with this rule being checked
# In this case there are no settings that need to be configured
rule_schema: {}
# Defines the configuration for ingesting data relevant for the rule
ingest:
type: git
git:
branch: main
# Defines the configuration for evaluating data ingested against the given profile
eval:
type: rego
rego:
type: deny-by-default
def: |
package minder

default allow := false

allow {
# List all workflows
workflows := file.ls("./.github/workflows")

# Read all workflows
some w
workflowstr := file.read(workflows[w])

workflow := yaml.unmarshal(workflowstr)

# Iterate jobs
job := workflow.jobs[_]

# Iterate steps
first_step := job.steps[0]

# Check if the step is harden-runner
startswith(first_step.uses, "step-security/harden-runner@")
}
# Defines the configuration for alerting on the rule
alert:
type: security_advisory
security_advisory: {}
Loading