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

🌱 Add lifecycle field to probes #4147

Merged
merged 7 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
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
94 changes: 94 additions & 0 deletions docs/probes.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/probes/internal/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func printField(w io.Writer, name string, value any) {
func printProbe(w io.Writer, p *pyaml.Probe) {
// short, motivation, implementation, outcome, remediation, ecosystem
fmt.Fprint(w, "\n"+"## "+p.ID+"\n\n")
printField(w, "Lifecycle", p.Lifecycle)
printField(w, "Description", p.Short)
printField(w, "Motivation", p.Motivation)
printField(w, "Implementation", p.Implementation)
Expand Down
19 changes: 19 additions & 0 deletions finding/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
// RemediationEffort indicates the estimated effort necessary to remediate a finding.
type RemediationEffort int

// lifecycle indicates the probe's stability.
type lifecycle string

const (
// RemediationEffortNone indicates a no remediation effort.
RemediationEffortNone RemediationEffort = iota
Expand All @@ -37,6 +40,10 @@ const (
RemediationEffortMedium
// RemediationEffortHigh indicates a high remediation effort.
RemediationEffortHigh

lifecycleExperimental lifecycle = "experimental"
lifecycleStable lifecycle = "stable"
lifecycleDeprecated lifecycle = "deprecated"
)

// Remediation represents the remediation for a finding.
Expand Down Expand Up @@ -109,6 +116,9 @@ func validate(r *pyaml.Probe, probeID string) error {
if err := validateEcosystem(r.Ecosystem); err != nil {
return err
}
if err := validateLifecycle(lifecycle(r.Lifecycle)); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -178,6 +188,15 @@ func validateSupportedClients(r pyaml.Ecosystem) error {
return nil
}

func validateLifecycle(l lifecycle) error {
switch l {
case lifecycleExperimental, lifecycleStable, lifecycleDeprecated:
return nil
default:
return fmt.Errorf("%w: %v", errInvalid, fmt.Sprintf("lifecycle '%v'", l))
}
}

func parseFromYAML(content []byte) (*pyaml.Probe, error) {
r := pyaml.Probe{}

Expand Down
12 changes: 12 additions & 0 deletions finding/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ func Test_probeFromBytes(t *testing.T) {
path: "testdata/invalid-client.yml",
err: errInvalid,
},
{
name: "invalid lifecycle is an error",
id: "invalid-lifecycle",
path: "testdata/invalid-lifecycle.yml",
err: errInvalid,
},
{
name: "missing lifecycle is an error",
id: "missing-lifecycle",
path: "testdata/missing-lifecycle.yml",
err: errInvalid,
},
}
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
Expand Down
1 change: 1 addition & 0 deletions finding/testdata/all-fields.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
id: all-fields
lifecycle: stable
short: short description
motivation: >
mot1
Expand Down
1 change: 1 addition & 0 deletions finding/testdata/effort-high.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
id: effort-high
lifecycle: stable
short: short description
motivation: >
line1
Expand Down
1 change: 1 addition & 0 deletions finding/testdata/effort-low.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
id: effort-low
lifecycle: stable
short: short description
motivation: >
line1
Expand Down
1 change: 1 addition & 0 deletions finding/testdata/invalid-client.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
id: invalid-client
lifecycle: stable
short: short description
motivation: >
mot1
Expand Down
1 change: 1 addition & 0 deletions finding/testdata/invalid-effort.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
id: invalid-effort
lifecycle: stable
short: short description
motivation: >
line1
Expand Down
1 change: 1 addition & 0 deletions finding/testdata/invalid-language.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
id: invalid-language
lifecycle: stable
short: short description
motivation: >
mot1
Expand Down
26 changes: 26 additions & 0 deletions finding/testdata/invalid-lifecycle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
id: all-fields
lifecycle: foo
short: short description
motivation: >
mot1
mot2
implementation: >
impl1
impl2
remediation:
onOutcome: False
effort: Low
text:
- step1
- step2 https://www.google.com/something
markdown:
- step1
- step2 [google.com](https://www.google.com/something)
ecosystem:
languages:
- c
- c++
clients:
- github
- gitlab
- localdir
1 change: 1 addition & 0 deletions finding/testdata/metadata-variables.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
id: metadata-variables
lifecycle: stable
short: short description
motivation: >
line1
Expand Down
1 change: 1 addition & 0 deletions finding/testdata/missing-id.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lifecycle: stable
short: short description
motivation: >
line1
Expand Down
25 changes: 25 additions & 0 deletions finding/testdata/missing-lifecycle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
id: all-fields
short: short description
motivation: >
mot1
mot2
implementation: >
impl1
impl2
remediation:
onOutcome: False
effort: Low
text:
- step1
- step2 https://www.google.com/something
markdown:
- step1
- step2 [google.com](https://www.google.com/something)
ecosystem:
languages:
- c
- c++
clients:
- github
- gitlab
- localdir
1 change: 1 addition & 0 deletions internal/probes/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Probe struct {
ID string `yaml:"id"`
Short string `yaml:"short"`
Motivation string `yaml:"motivation"`
Lifecycle string `yaml:"lifecycle"`
Implementation string `yaml:"implementation"`
Ecosystem Ecosystem `yaml:"ecosystem"`
Outcomes []string `yaml:"outcome"`
Expand Down
7 changes: 7 additions & 0 deletions probes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ A probe consists of three files:
- `impl.go`: The actual implementation of the probe.
- `impl_test.go`: The probe's test.

## Lifecycle

Probes can exist in several different lifecycle states:
* `Experimental`: The semantics of the probe may change, and there are no stability guarantees.
* `Stable`: The probe behavior and semantics will not change. There may be bug fixes as needed.
* `Deprecated`: The probe is no longer supported and callers should not expect it to be maintained.

## Reusing code in probes

When multiple probes use the same code, the reused code can be placed in a package under `probes/internal/`
Expand Down
1 change: 1 addition & 0 deletions probes/archived/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: archived
lifecycle: stable
short: Check that the project is archived
motivation: >
An archived project will not received security patches, and is not actively tested or used.
Expand Down
1 change: 1 addition & 0 deletions probes/blocksDeleteOnBranches/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: blocksDeleteOnBranches
lifecycle: stable
short: Check that the project blocks non-admins from deleting branches.
motivation: >
Allowing non-admins to delete project branches has a similar effect to performing force pushes.
Expand Down
1 change: 1 addition & 0 deletions probes/blocksForcePushOnBranches/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: blocksForcePushOnBranches
lifecycle: stable
short: Check that the project blocks force push on its branches.
motivation: >
Allowing force pushes to branches could allow those with write access to make insecure changes to the behavior of the project.
Expand Down
1 change: 1 addition & 0 deletions probes/branchProtectionAppliesToAdmins/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: branchProtectionAppliesToAdmins
lifecycle: stable
short: Check that the project's branch protection rules apply to project admins.
motivation: >
Admins may be able to bypass branch protection settings which could defeat the purpose of having them.
Expand Down
1 change: 1 addition & 0 deletions probes/branchesAreProtected/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: branchesAreProtected
lifecycle: stable
short: Check that the project uses protected branches.
motivation: >
Unprotected branches may allow actions that could compromise the project's security.
Expand Down
1 change: 1 addition & 0 deletions probes/codeApproved/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


id: codeApproved
lifecycle: stable
short: Check that all recent changesets have been approved by someone who is not the author of the changeset.
motivation: >
To ensure that the review process works, the proposed changes
Expand Down
1 change: 1 addition & 0 deletions probes/codeReviewOneReviewers/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: codeReviewOneReviewers
lifecycle: experimental
short: Check that at least one reviewers review a change before merging.
motivation: >
To ensure that the review process works, the proposed changes
Expand Down
1 change: 1 addition & 0 deletions probes/contributorsFromOrgOrCompany/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: contributorsFromOrgOrCompany
lifecycle: experimental
short: Checks whether a project has a contributions from users associated with a company or organization.
motivation: >
This probe tries to determine if the project has recent contributors from multiple organizations.
Expand Down
1 change: 1 addition & 0 deletions probes/createdRecently/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: createdRecently
lifecycle: stable
short: Checks if the project was created in the last 90 days.
motivation: >
Recently created repositories have been used for malicious forks / typosquatting attacks in the past.
Expand Down
1 change: 1 addition & 0 deletions probes/dependencyUpdateToolConfigured/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: dependencyUpdateToolConfigured
lifecycle: stable
short: Check that a dependency update tool config is present.
motivation: >
Out-of-date dependencies make a project vulnerable to known flaws and prone to attacks.
Expand Down
1 change: 1 addition & 0 deletions probes/dismissesStaleReviews/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: dismissesStaleReviews
lifecycle: stable
short: Check that the project dismisses stale reviews when new commits are pushed.
motivation: >
When a project does not dismiss stale reviews, contributors can bring their pull requests to an approved state and then make unreviewed commits.
Expand Down
1 change: 1 addition & 0 deletions probes/fuzzed/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: fuzzed
lifecycle: stable
short: Check that the project is fuzzed
motivation: >
Fuzzing, or fuzz testing, is the practice of feeding unexpected or random data into a program to expose bugs.
Expand Down
1 change: 1 addition & 0 deletions probes/hasBinaryArtifacts/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasBinaryArtifacts
lifecycle: stable
short: Checks if the project has any binary files in its source tree.
motivation: >
Binary files are not human readable so users and reviewers can't easily see what they do.
Expand Down
1 change: 1 addition & 0 deletions probes/hasDangerousWorkflowScriptInjection/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasDangerousWorkflowScriptInjection
lifecycle: stable
short: Check whether the project has GitHub Actions workflows that enable script injection.
motivation: >
Script injections allow attackers to use untrusted input to access privileged resources (code execution, secret exfiltration, etc.)
Expand Down
1 change: 1 addition & 0 deletions probes/hasDangerousWorkflowUntrustedCheckout/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasDangerousWorkflowUntrustedCheckout
lifecycle: stable
short: Check whether the project has GitHub Actions workflows that does untrusted checkouts.
motivation: >
GitHub workflows triggered with pull_request_target or workflow_run have write permission to the target repository and access to target repository secrets.
Expand Down
1 change: 1 addition & 0 deletions probes/hasFSFOrOSIApprovedLicense/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasFSFOrOSIApprovedLicense
lifecycle: stable
short: Check that the project has an FSF or OSI approved license.
motivation: >
A license can give users information about how the source code may or may not be used.
Expand Down
1 change: 1 addition & 0 deletions probes/hasLicenseFile/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasLicenseFile
lifecycle: stable
short: Check that the project has a license file
motivation: >
A license can give users information about how the source code may or may not be used.
Expand Down
1 change: 1 addition & 0 deletions probes/hasNoGitHubWorkflowPermissionUnknown/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasNoGitHubWorkflowPermissionUnknown
lifecycle: experimental
short: Checks that GitHub workflows have workflows with unknown permissions
motivation: >
Unknown permissions may be a result of a bug or another error from fetching the permission levels.
Expand Down
1 change: 1 addition & 0 deletions probes/hasOSVVulnerabilities/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasOSVVulnerabilities
lifecycle: stable
short: Check whether the project has known vulnerabilities
motivation: >
This check determines whether the project has open, unfixed vulnerabilities in its own codebase or its dependencies using the OSV (Open Source Vulnerabilities) service.
Expand Down
1 change: 1 addition & 0 deletions probes/hasOpenSSFBadge/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasOpenSSFBadge
lifecycle: stable
short: This check determines whether the project has an OpenSSF (formerly CII) Best Practices Badge.
motivation: >
The OpenSSF Best Practices badge indicates whether or not the project uses a set of security-focused best development practices for open source software.
Expand Down
1 change: 1 addition & 0 deletions probes/hasPermissiveLicense/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasPermissiveLicense
lifecycle: stable
short: Check that the project has an permissive license.
motivation: >
A permissive license allows users to use the analyzed component to be used in derivative works. Non-permissive licenses (as copyleft licenses) might be a legal risk for potential users.
Expand Down
1 change: 1 addition & 0 deletions probes/hasRecentCommits/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasRecentCommits
lifecycle: stable
short: Check whether the project has at least one commit per week over the last 90 days.
motivation: >
A project which is not active might not be patched, have its dependencies patched, or be actively tested and used.
Expand Down
1 change: 1 addition & 0 deletions probes/hasReleaseSBOM/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasReleaseSBOM
lifecycle: experimental
short: Check that the project publishes an SBOM as part of its release artifacts.
motivation: >
An SBOM can give users information about how the source code components and dependencies. They help facilitate sotware supplychain security and aid in identifying upstream vulnerabilities in a codebase.
Expand Down
1 change: 1 addition & 0 deletions probes/hasSBOM/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasSBOM
lifecycle: experimental
short: Check that the project has an SBOM file
motivation: >
An SBOM can give users information about how the source code components and dependencies. They help facilitate sotware supplychain security and aid in identifying upstream vulnerabilities in a codebase.
Expand Down
1 change: 1 addition & 0 deletions probes/hasUnverifiedBinaryArtifacts/def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

id: hasUnverifiedBinaryArtifacts
lifecycle: stable
short: Checks if the project has binary files in its source tree. The probe skips verified binary files which currently are gradle-wrappers.
motivation: >
Binary files are not human readable so users and reviewers can't easily see what they do.
Expand Down
Loading
Loading