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

🐛 Fix remediation message #2486

Merged
merged 1 commit into from
Nov 28, 2022
Merged
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
15 changes: 10 additions & 5 deletions checks/evaluation/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckReq
hm := make(map[string]permissions)
dl := c.Dlogger
//nolint:errcheck
remediaitonMetadata, _ := remediation.New(c)
remediationMetadata, _ := remediation.New(c)

for _, r := range results.TokenPermissions {
var msg checker.LogMessage

var rem *checker.Remediation
if r.File != nil {
msg.Path = r.File.Path
msg.Offset = r.File.Offset
msg.Type = r.File.Type
msg.Snippet = r.File.Snippet

if msg.Path != "" {
msg.Remediation = remediaitonMetadata.CreateWorkflowPermissionRemediation(r.File.Path)
rem = remediationMetadata.CreateWorkflowPermissionRemediation(r.File.Path)
}
}

Expand All @@ -92,7 +92,7 @@ func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckReq

// We warn only for top-level.
if *r.LocationType == checker.PermissionLocationTop {
dl.Warn(&msg)
warnWithRemediation(dl, &msg, rem)
} else {
dl.Debug(&msg)
}
Expand All @@ -103,7 +103,7 @@ func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckReq
}

case checker.PermissionLevelWrite:
dl.Warn(&msg)
warnWithRemediation(dl, &msg, rem)

// Group results by workflow name for score computation.
if err := updateWorkflowHashMap(hm, r); err != nil {
Expand All @@ -115,6 +115,11 @@ func applyScorePolicy(results *checker.TokenPermissionsData, c *checker.CheckReq
return calculateScore(hm), nil
}

func warnWithRemediation(logger checker.DetailLogger, msg *checker.LogMessage, rem *checker.Remediation) {
msg.Remediation = rem
logger.Warn(msg)
}

func recordPermissionWrite(hm map[string]permissions, path string,
locType checker.PermissionLocation, permName *string,
) {
Expand Down