-
Notifications
You must be signed in to change notification settings - Fork 127
Update workflow policy to scan all branches for dangerous workflows #569 #622
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
Conversation
all branches. Signed-off-by: Samuel Erb <[email protected]>
Signed-off-by: Samuel Erb <[email protected]>
Signed-off-by: Samuel Erb <[email protected]>
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.
LGTM
@raghavkaul can you review as well? Thanks. |
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.
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) { |
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.
@jeffmendoza do we need to defer
this func somewhere?
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.
Nice catch! I went through and defer scorecard.Close...
all uses of the Get function.
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.
We have the Close here:
allstar/pkg/enforce/enforce.go
Line 342 in 5ef0769
defer scorecard.Close(fmt.Sprintf("%s/%s", owner, repo)) |
Just one per repo run, so that each policy can get the clients, the first one will download the tarball, but the subsequent policies that use scorecard will not have to download the tarball again.
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.
Yup, you're right. I was able to validate this running ./main -once=true
with inotifywait -m -e modify,create,delete /tmp
also running. Only one folder named allstar<random number>
is created and then deleted per-run after removing the unnecessary closes.
pkg/policies/workflow/workflow.go
Outdated
Msg(msg) | ||
return &policydef.Result{ | ||
Enabled: enabled, | ||
Pass: true, |
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.
Pass: true, | |
Pass: false, |
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.
fixed!
pkg/policies/workflow/workflow.go
Outdated
Msg(msg) | ||
return &policydef.Result{ | ||
Enabled: enabled, | ||
Pass: true, |
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.
Pass: true, | |
Pass: false, |
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.
fixed!
pkg/policies/workflow/workflow.go
Outdated
Msg(msg) | ||
return &policydef.Result{ | ||
Enabled: enabled, | ||
Pass: true, |
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.
Pass: true, | |
Pass: false, |
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.
fixed!
Validated this still works as expected:
|
Signed-off-by: Samuel Erb <[email protected]>
ac9b28f
to
56c269f
Compare
Force-pushed to add |
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.
New changes LGTM.
Signed-off-by: Samuel Erb <[email protected]>
Signed-off-by: Samuel Erb <[email protected]>
Signed-off-by: Samuel Erb <[email protected]>
Thanks! |
@jeffmendoza @serb-google This PR is breaking the dangerous workflows scan for private repositories. It fails with an authentication failure on:
which can only work for public repos as it's not re-using the http config. The logs I see are:
|
Hi @coheigea, I believe serb-google@57aa84f should address this, but I need to find a way to test this before sending it out for a PR. |
@serb-google Hi, I get a different error message with the patch. Before:
After:
|
@serb-google I've found our scans running way slower than before on big repos with many branches after this change. What do you think about adding a boolean config whether to restrict to the default branch or not? |
This PR addresses #569 and introduces 2 changes:
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 outputVulnerable Branch: refs/remotes/origin/insecure_test
.This is my first contribution to this repo, please review carefully :)