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

Scorecard workflow generation fixes #2110

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

justaugustus
Copy link

I noticed when using https://app.stepsecurity.io/securerepo (ref: uwu-tools/magex#8) it will generate a OpenSSF Scorecard workflow file with some minor nits:

  1. filename is pluralized
  2. harden runner is not included
  3. versions are not pinned to SHA
  4. versions are not up to date (which yield generated update PRs like Bump ossf/scorecard-action from 2.0.6 to 2.1.3 uwu-tools/magex#9)

This changeset does the following:

Signed-off-by: Stephen Augustus foo@auggie.dev

cc: @varunsh-coder

Scorecard is not pluralized.
ref: ossf/scorecard#2427

Signed-off-by: Stephen Augustus <foo@auggie.dev>
Signed-off-by: Stephen Augustus <foo@auggie.dev>
Copy link
Collaborator

@step-security-bot step-security-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please find code comments generated by StepSecurity AI CodeReviewer below. As we have used multiple ways to analyze the diff, our bot will create multiple comments with code feedback

Code Reviewer Model Name: json_output

Code Comments

README.md

[
{
"Severity": "Medium",
"Recommendation": "Update the GitHub Action file name to 'scorecards.yml'",
"Description": "As per the contribution guidelines set by GitHub, it is recommended to use the same file name scorecards.yml for consistency and completeness, instead of the old file name scorecard.yml."
}
]

remediation/workflow/addworkflow.go

[
{
"Severity": "Low",
"Recommendation": "Add a newline at the end of the file.",
"Description": "The code changes indicate that there is no newline at the end of the file. According to the Golang official style guide, each file should end with a newline character, so it is recommended to add it."
},
{
"Severity": "Low",
"Recommendation": "Rename the scorecard filename to be consistent with the existing filenames.",
"Description": "The changes show that the Scorecard filename was renamed from 'scorecards.yml' to 'scorecard.yml'. It is recommended that the filename be consistent with the other filenames in the same directory to follow the principle of consistency, as suggested by the Google style guide."
}
]

remediation/workflow/addworkflow_test.go

[
{
"Severity": "Medium",
"Recommendation": "Consider implementing regression tests.",
"Description": "Regression testing is a type of software testing that checks to make sure that changes do not negatively impact the already tested scenarios."
},
{
"Severity": "Low",
"Recommendation": "Consider using a linter to fix potential syntax errors and minor issues.",
"Description": "Linters are tools that analyze the source code to detect potential issues before the code is executed. They can help clean up common mistakes and optimize the code, and also enforce best practices and coding standards."
}
]

Both of the recommended actions are based on the following authoritative sources:

testfiles/addworkflow/expected-scorecard.yml

[
{
"Severity": "High",
"Recommendation": "Upgrade actions/checkout from v3.5.2 to v2",
"Description": "v3 releases of actions/checkout package have known issues that may cause security vulnerabilities. As the v3.5.2 version of the package is used, it's recommended to use the v2 version of the package (for example v2.4.2) in the workflow file instead (Source: https://github.com/actions/checkout#recommended-version)"
},
{
"Severity": "High",
"Recommendation": "Upgrade ossf/scorecard-action from v2.1.3 to v2.1.6",
"Description": "The ossf/scorecard-action package has known security vulnerabilities in versions prior to v2.1.6. As the v2.1.3 version of the package is used, it's recommended to upgrade to the latest available version of the package (for example v2.1.6) to resolve the security vulnerabilities (Source: https://github.com/ossf/scorecard-action/releases)"
},
{
"Severity": "Medium",
"Recommendation": "Upgrade actions/upload-artifact from v3.1.2 to v2.2.4",
"Description": "The actions/upload-artifact package has known security vulnerabilities in versions prior to v2.2.4. As the v3.1.2 version of the package is used, it's recommended to upgrade to the latest available version of the package (for example v2.2.4) to resolve the security vulnerabilities (Source: https://github.com/actions/upload-artifact/releases)"
},
{
"Severity": "Low",
"Recommendation": "Use GitHub-Recommended Upload Artifact Action",
"Description": "The GitHub-recommended upload artifact action 'actions/upload-artifact@v2.2.4' is available for use and provides the latest-supported functionality with the recommended security controls (Source: https://github.com/actions/upload-artifact#recommended-version)"
},
{
"Severity": "Low",
"Recommendation": "Upgrade github/codeql-action/upload-sarif to v2.3.3",
"Description": "The github/codeql-action/upload-sarif package has known security vulnerabilities in versions prior to v2.3.3. As the v2.3.2 version of the package is used, it's recommended to upgrade to the latest available version of the package (for example v2.3.3) to resolve the security vulnerabilities (Source: https://github.com/github/codeql-action/releases)"
}
]

workflow-templates/scorecard.yml

[
{
"Severity": "High",
"Recommendation": "Update dependencies to latest versions",
"Description": "The current used versions of "actions/checkout" and "actions/upload-artifact" are not up-to-date. It is recommended to update them to the latest stable versions to ensure that the project has the latest security patches, bug fixes, and performance improvements. This can help mitigate vulnerabilities that can be exploited by attackers."
},
{
"Severity": "High",
"Recommendation": "Enable persist-credentials option in 'Checkout code' step",
"Description": "The persist-credentials option in 'Checkout code' step is disabled. It is recommended to enable it to ensure that the Git credentials are stored on the runner machine. This can help to avoid repeated authentication errors from the git repository as well as ensure that the git repository is secure."
},
{
"Severity": "Low",
"Recommendation": "Specify version in dependencies at the minor or patch level",
"Description": "Dependency versions should be pinned down, and only the minor or patch level should be specified. This can ensure that the project is using the same dependencies across different environments and can prevent unexpected behavior due to dependency update problems. In the given code patch, the "ossf/scorecard-action" dependency should be updated to v2.1.x instead of v2.1.3. However, in general, it is best to specify dependencies at the minor or patch level, whenever possible."
}
]

Feedback

We appreciate your feedback in helping us enhance the service! To provide feedback, please use emojis on the comments generated by the bot. If you find the comments helpful, give them a 👍. If they aren't useful, kindly express that with a 👎. Thank you for your support!

Copy link
Collaborator

@step-security-bot step-security-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please find code comments generated by StepSecurity AI CodeReviewer below.

Code Reviewer Model Name: beta

Code Comments

testfiles/addworkflow/expected-scorecard.yml

  • Consider adding a comment explaining the purpose of the "Harden Runner" step.
  • Upgrade to the latest version of "actions/checkout" (v3.5.2).
  • Upgrade to the latest version of "ossf/scorecard-action" (v2.1.3).
  • Upgrade to the latest version of "actions/upload-artifact" (v3.1.2).
  • Upgrade to the latest version of "github/codeql-action/upload-sarif" (v2.3.2).
  • Consider adding error handling to the "Harden Runner" step in case the egress policy is not set correctly.

workflow-templates/scorecard.yml

  • Change the version of "harden-runner" in line 5 to the latest stable release.
  • Update the "actions/checkout" version in line 9 to the latest stable release.
  • Use the latest stable version of "ssf/scorecard-action" in line 14.
  • Update the "actions/upload-artifact" version in line 20 to the latest stable release.
  • Use the latest stable version of "github/codeql-action/upload-sarif" in line 26.
  • Avoid hardcoding versions, instead use a tag or branch name so that the dependencies can be updated easily.

README.md

  • Consider using a more descriptive name for the GitHub Actions workflow file, such as openSSF_scorecard.yml.
  • Provide some explanation regarding what the OpenSSF Scorecard workflow does and how it adds value to the project.
  • Consider adding comments to the workflow file to explain each step and increase readability.
  • Consider adding error handling to the workflow file to catch potential failures and notify developers.
  • Consider utilizing GitHub's pre-commit hooks to check for any security vulnerabilities in the code before it gets committed.

remediation/workflow/addworkflow.go

  • Change the constant ScorecardFileName from "scorecards.yml" to "scorecard.yml" to ensure consistency with the filename used in the repository.
  • Add a newline at the end of the file to ensure consistency with standard file formats.

remediation/workflow/addworkflow_test.go

  • Suggestion: Rename the file "expected-scorecard.yml" to be consistent with the naming convention used in the rest of the codebase.
  • Suggestion: Consider using a constant instead of hard-coding the file path "expected-scorecard.yml" to improve maintainability and avoid repetitive code.

Feedback

We appreciate your feedback in helping us enhance the service! To provide feedback, please use emojis on the comments generated by the bot. If you find the comments helpful, give them a 👍. If they aren't useful, kindly express that with a 👎. Thank you for your support!

@varunsh-coder
Copy link
Member

Hi @justaugustus, thanks for creating the PR!

I will review it soon and get back. We are also running our new AI-assisted code review Action on this repo, so that might add some comments as well :).

@varunsh-coder
Copy link
Member

I noticed when using https://app.stepsecurity.io/securerepo (ref: uwu-tools/magex#8) it will generate a OpenSSF Scorecard workflow file with some minor nits:

  1. filename is pluralized
  2. harden runner is not included
  3. versions are not pinned to SHA
  4. versions are not up to date (which yield generated update PRs like Bump ossf/scorecard-action from 2.0.6 to 2.1.3 uwu-tools/magex#9)

This changeset does the following:

Signed-off-by: Stephen Augustus foo@auggie.dev

cc: @varunsh-coder

Hi @justaugustus, thanks again for creating the PR!

When using https://app.stepsecurity.io/securerepo to add Scorecard workflow, adding harden-runner and pinning Actions are options available in the UI (screenshot below). These options are checked by default. If you notice in the uwu-tools/magex#8 PR, harden-runner has been added, and the Actions have been pinned.

If a developer unchecks those options, then harden-runner is not added and Actions (other than Scorecard Action) are not pinned. We want to give developers this option, because some of them do not want to add harden-runner and/ or pin Actions. Moreover this way, the Actions are pinned to the latest commit SHA for the tag version.

So the template itself does not include these options, other than to pin the Scorecard Action.

So, can you please remove harden-runner and pinning of checkout , upload-artifact, and upload-sarif Actions from the workflow template in the PR?

I agree with the other changes:

  1. Scorecards plural should be changed to singular
  2. Scorecard version needs to be updated.

Please let me know if you have any questions.

Screen Shot 2023-05-08 at 6 22 40 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants