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

Update workflow policy to scan all branches for dangerous workflows #569 #622

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

Conversation

serb-google
Copy link

This PR addresses #569 and introduces 2 changes:

  • Adds support for local git repos in scorecard.go, with additional functionality to switch between all branches. I opted to not replace the existing Github client as policies may want to interact directly with Github.
  • Updates workflow.go to scan all remote branches in the local git repo.

Tested locally using https://github.com/serb-google/allstar, with a branch insecure_test which contains a fake unsafe workflow rule. Verified this triggered the alert which included output Vulnerable Branch: refs/remotes/origin/insecure_test.

This is my first contribution to this repo, please review carefully :)

@serb-google serb-google requested a review from a team as a code owner January 6, 2025 01:59
Signed-off-by: Samuel Erb <[email protected]>
Signed-off-by: Samuel Erb <[email protected]>
jeffmendoza
jeffmendoza previously approved these changes Jan 17, 2025
Copy link
Member

@jeffmendoza jeffmendoza left a comment

Choose a reason for hiding this comment

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

LGTM

@jeffmendoza
Copy link
Member

@raghavkaul can you review as well? Thanks.

Copy link

@raghavkaul raghavkaul left a comment

Choose a reason for hiding this comment

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

Thanks for this push, looks good with minor feedback.

if err != nil {
return "", nil, err
}
return dir, repo, nil
}

// Function Close will close the scorecard clients. This cleans up the
// downloaded tarball.
func Close(fullRepo string) {

Choose a reason for hiding this comment

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

@jeffmendoza do we need to defer this func somewhere?

Copy link
Author

Choose a reason for hiding this comment

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

Nice catch! I went through and defer scorecard.Close... all uses of the Get function.

Msg(msg)
return &policydef.Result{
Enabled: enabled,
Pass: true,

Choose a reason for hiding this comment

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

Suggested change
Pass: true,
Pass: false,

Copy link
Author

Choose a reason for hiding this comment

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

fixed!

Msg(msg)
return &policydef.Result{
Enabled: enabled,
Pass: true,

Choose a reason for hiding this comment

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

Suggested change
Pass: true,
Pass: false,

Copy link
Author

Choose a reason for hiding this comment

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

fixed!

Msg(msg)
return &policydef.Result{
Enabled: enabled,
Pass: true,

Choose a reason for hiding this comment

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

Suggested change
Pass: true,
Pass: false,

Copy link
Author

Choose a reason for hiding this comment

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

fixed!

serb-google added a commit to serb-google/allstar that referenced this pull request Feb 28, 2025
@serb-google
Copy link
Author

Validated this still works as expected:

{"severity":"INFO","org":"serb-google","repo":"allstar","area":"Dangerous Workflow","result":false,"enabled":false,"notify":"Project is out of compliance with Dangerous Workflow policy: dangerous workflow patterns detected\n\n\t\t**Rule Description**\n\t\tDangerous workflows are GitHub Action workflows that exhibit dangerous patterns that could render them vulnerable to attack. A vulnerable workflow is susceptible to leaking repository secrets, or allowing an attacker write access using the GITHUB_TOKEN. For more information about the particular patterns that are detected, see the [OpenSSF Scorecard documentation](https://github.com/ossf/scorecard/blob/main/docs/checks.md#dangerous-workflow) on dangerous workflows. Any vulnerable branch can be exploited, so this rule will check all branches (vulnerable list below).\n\n\t\t**Remediation Steps**\n\t\tAvoid the dangerous workflow patterns. See this [post](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) for information on avoiding untrusted code checkouts. See this [document](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#understanding-the-risk-of-script-injections) for information on avoiding and mitigating the risk of script injections.\n\t\t**Dangerous Patterns Found**\n\n- [0]:\n\n**Additional Information**\n\tThis policy uses [OpenSSF Scorecard](https://github.com/ossf/scorecard/). You may wish to run a Scorecard scan directly on this repository for more details.\n\nVulnerable Branch: refs/remotes/origin/insecure_test","details":{"Findings":null},"time":"2025-02-28T21:36:22Z","message":"Policy run result."}

Signed-off-by: Samuel Erb <[email protected]>
@serb-google
Copy link
Author

Force-pushed to add Signed-off-by line which was missing in previous commit.

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