-
Notifications
You must be signed in to change notification settings - Fork 13
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
Introduce OpenSSF Best Practices Badge rule #238
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
version: v1 | ||
type: data-source | ||
name: openssf_bestpractices | ||
context: {} | ||
rest: | ||
def: | ||
lookup: | ||
endpoint: 'https://www.bestpractices.dev/projects/{id}.json' | ||
parse: json | ||
input_schema: | ||
properties: | ||
id: | ||
type: string | ||
description: The project ID to lookup | ||
required: | ||
- id |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
version: v1 | ||
release_phase: alpha | ||
type: rule-type | ||
name: openssf_bestpractices | ||
display_name: Verifies the project has earned an OpenSSF Best Practices Badge | ||
short_failure_message: OpenSSF Best Practices Badge is missing | ||
severity: | ||
value: low | ||
context: | ||
provider: github | ||
description: | | ||
Verifies that a repository contains an OpenSSF Best Practices badge at | ||
the specified level. | ||
|
||
This rule type checks for the existence of a image declared in Markdown, | ||
referencing the project's badge on the Best Practices badge site. | ||
guidance: | | ||
The [OpenSSF Best Practices Badge](https://www.bestpractices.dev/en) | ||
program allows open source projects to show that they follow best | ||
security practices. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This guidance looks a little off. The intent is to tell people what to do if they fail this check. |
||
def: | ||
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: | ||
type: object | ||
properties: | ||
filename: | ||
type: string | ||
description: | | ||
The path to the README that links to the badge | ||
default: README.md | ||
level: | ||
type: string | ||
description: | | ||
The required achievement level. | ||
enum: | ||
- in_progress | ||
- passing | ||
- silver | ||
- gold | ||
default: passing | ||
# Defines the configuration for ingesting data relevant for the rule | ||
ingest: | ||
type: git | ||
git: {} | ||
eval: | ||
type: rego | ||
data_sources: | ||
- name: openssf_bestpractices | ||
rego: | ||
type: deny-by-default | ||
def: | | ||
package minder | ||
import rego.v1 | ||
|
||
default allow := false | ||
default message := "OpenSSF Best Practices Badge is missing" | ||
|
||
levels := { "in_progress": 1, "passing": 2, "silver": 3, "gold": 4 } | ||
|
||
allow if { | ||
file.exists(input.profile.filename) | ||
readme := file.read(input.profile.filename) | ||
|
||
badge := regex.find_all_string_submatch_n(`\[[^\]]+\]\(https:\/\/www\.bestpractices\.dev\/projects\/([\d]+)\/badge\)`, readme, 1) | ||
project_id := badge[0][1] | ||
|
||
badge_data := minder.datasource.openssf_bestpractices.lookup({"id": project_id }) | ||
|
||
levels[badge_data.body.badge_level] >= levels[input.profile.level] | ||
} | ||
# Defines the configuration for alerting on the rule | ||
alert: | ||
type: security_advisory | ||
security_advisory: {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Should we stop adding the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes but I think that it makes sense to burn it down so that the rules are consistent with each other, instead of having a few that are one way and a few that are another. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must match the file name.