-
Notifications
You must be signed in to change notification settings - Fork 14
Add check for OSPS-DO-03: repo contains end-user documentation #232
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dade4e1
Add check for OSPS-DO-03: repo contains end-user documentation
evankanderson 8607374
Adjust documentation and guidance
evankanderson 4d45f69
Update rule-types/github/osps-do-03.yaml
evankanderson d842379
Merge remote-tracking branch 'upstream/main' into osps-do-03
evankanderson 46f7864
Relocate osps-do-03
evankanderson 1ca62b9
Merge remote-tracking branch 'upstream/main' into osps-do-03
evankanderson d0196f3
Update rule with feedback from Ria
evankanderson 1ec3315
Remove DO-05 for a separate PR
evankanderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--- | ||
version: v1 | ||
release_phase: alpha | ||
type: rule-type | ||
name: osps-do-03 | ||
display_name: OSPS-DO-03 The project documentation MUST provide user guides for all basic functionality | ||
short_failure_message: No user guides or project documentation found | ||
severity: | ||
value: low | ||
context: | ||
provider: github | ||
description: | | ||
Verifies that the project documentation provides a user guide. | ||
|
||
This rule attempts to locate user guides from several project documentation sources. | ||
|
||
Currently, this rule checks the following: | ||
|
||
* The GitHub repository's public link | ||
* A `docs` directory in the default branch of the repository with .md, .rst, .html or .txt files | ||
* A `documentation` entry in SECURITY-INSIGHTS.yaml | ||
* A `README.md` file containing preformatted text (triple-backtick) or the headings | ||
"usage" or "getting started" | ||
|
||
For more information, see [OpenSSF Security Baseline](https://baseline.openssf.org/#osps-do-03). | ||
guidance: | | ||
Publish documentation in one of the following well-known locations: | ||
|
||
* Set the repository homepage to a documentation URL. | ||
* Add a SECURITY-INSIGHTS.yaml file with a `documentation` entry | ||
* Create a `docs` directory in the default branch of the repository | ||
* Add a "usage" or "getting started" section to `README.md` | ||
def: | ||
in_entity: repository | ||
rule_schema: {} | ||
ingest: | ||
type: git | ||
eval: | ||
type: rego | ||
data_sources: | ||
- name: ghapi | ||
rego: | ||
type: deny-by-default | ||
def: | | ||
package minder | ||
|
||
import rego.v1 | ||
|
||
default allow := false | ||
|
||
repo := sprintf("%s/%s", []) | ||
|
||
allow if { | ||
# Check the SECURITY-INSIGHTS.yaml file | ||
file.exists("SECURITY-INSIGHTS.yaml") | ||
si_data := yaml.unmarshal(file.read("SECURITY-INSIGHTS.yaml")) | ||
count(si_data.documentation) > 0 | ||
} | ||
|
||
# TODO: these should trigger a remediation to put them in | ||
# SECURITY-INSIGHTS.yaml, but also still pass the check(?) | ||
|
||
allow if { | ||
# Check the GitHub homepage link | ||
out = minder.datasource.ghapi.repo_config({ | ||
"owner": input.properties["github/repo_owner"], | ||
"repo": input.properties["github/repo_name"] | ||
}) | ||
out.body.homepage != "" | ||
} | ||
|
||
allow if { | ||
# Check the docs directory | ||
mdDocs := file.ls_glob("docs/*.md") | ||
rstDocs := file.ls_glob("docs/*.rst") | ||
htmlDocs := file.ls_glob("docs/*.html") | ||
txtDocs := file.ls_glob("docs/*.txt") | ||
count(mdDocs) + count(rstDocs) + count(htmlDocs) + count(txtDocs) > 0 | ||
} | ||
|
||
readme := file.read("README.md") | ||
allow if { | ||
# Check the README.md file for preformatted text after the first line | ||
regex.match("\n *```", readme) | ||
} | ||
allow if { | ||
regex.match("\n#+ (?i:Usage|Getting Started)", readme) | ||
} | ||
|
||
# Remediation is a work in progress -- ideally, we could read which location(s) | ||
# contained the documentation, and automatically update SECURITY-INSIGHTS.yaml | ||
# with any missing documentation locations. | ||
# remediate: | ||
# type: pull_request | ||
# pull_request: | ||
# title: "Add documentation to security-insights.yaml" | ||
# body: | | ||
# This is a Minder automated pull request. | ||
|
||
# This pull request links the discovered documentation in the security-insights.yaml file. | ||
# method: minder.yq.evaluate | ||
# params: | ||
# # TODO: need to be able to feed output from eval into remediate | ||
# expression: | | ||
# .documentation = [ "./README.md" ] | ||
# patterns: | ||
# # TODO: need to be able to create files as well as match existing files | ||
# - pattern: "SECURITY-INSIGHTS.yaml" | ||
# type: glob |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.