-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement issue #842 — SonarCloud: GitHub Actions / dependency hardening #843
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
Changes from all commits
fca210e
abfb370
283f30f
e441bdf
0461e89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,34 @@ workflow_command_lines() { | |
| [ "$fail" -eq 0 ] | ||
| } | ||
|
|
||
| @test "every 'go install' in a workflow is version-pinned and S8545-exempted" { | ||
| # S8545 flags `go install` as non-lockfile-enforcing. Go has no --locked / | ||
| # --require-hashes equivalent: a pinned `@vX.Y.Z` is the reproducible install | ||
| # (verified via the Go checksum DB, sum.golang.org), so the finding is a confirmed | ||
| # false positive suppressed with an inline `# NOSONAR(githubactions:S8545)` | ||
| # marker. This guard fails loud if a new `go install` is added unpinned | ||
| # (@latest/@main) or without the marker. | ||
| local fail=0 file cmd | ||
| while IFS=$'\t' read -r file cmd || [ -n "$file" ]; do | ||
| case "$cmd" in | ||
| *"go install"*) | ||
| case "$cmd" in | ||
| *[a-zA-Z0-9_-]go\ install*) : ;; | ||
| *) | ||
| case "$cmd" in *"@v"[0-9]*) : ;; *) | ||
| echo "UNPINNED go install (needs @vX.Y.Z): ${file##*/}: $cmd"; fail=1 ;; | ||
| esac | ||
| case "$cmd" in *"NOSONAR(githubactions:S8545)"*) : ;; *) | ||
| echo "MISSING # NOSONAR(githubactions:S8545): ${file##*/}: $cmd"; fail=1 ;; | ||
| esac | ||
|
Comment on lines
+74
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win Validate command tokens, not arbitrary line text. The checks search the complete raw line, so an unpinned command such as Proposed validation shape- case "$cmd" in *"`@v`"[0-9]*) : ;; *)
+ cmd_without_comment=${cmd%%#*}
+ if [[ "$cmd_without_comment" =~ (^|[[:space:]])go[[:space:]]+install[[:space:]]+[^[:space:]]+@v[0-9]+(\.[0-9]+){2}([[:space:]]|$) ]]; then
+ :
+ else
echo "UNPINNED go install (needs `@vX.Y.Z`): ${file##*/}: $cmd"; fail=1 ;;
- esac
+ fi🤖 Prompt for AI Agents |
||
| ;; | ||
| esac | ||
| ;; | ||
| esac | ||
|
don-petry marked this conversation as resolved.
|
||
| done < <(workflow_command_lines) | ||
| [ "$fail" -eq 0 ] | ||
| } | ||
|
|
||
| @test "each hash-locked requirements file referenced by a workflow exists" { | ||
| local fail=0 file cmd path | ||
| while IFS=$'\t' read -r file cmd || [ -n "$file" ]; do | ||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Cover
.yamlworkflows too.workflow_command_linesonly enumerates.ymlfiles, so this “every workflow” guard will miss unpinnedgo installcommands in.yamlworkflows. Extend the helper to scan both extensions.As per coding guidelines, workflow checks must cover both
.ymland.yamlfiles.Proposed fix
🤖 Prompt for AI Agents
Source: Coding guidelines