-
Notifications
You must be signed in to change notification settings - Fork 0
chore(ci): supply-chain security workflow + harden ci.yml #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| name: security | ||
|
|
||
| # Supply-chain and license-policy gate for quantcli repos. | ||
| # Source of truth lives in quantcli/common; export-clis carry a copy of this file. | ||
| # When updating, propagate the change to every *-export-cli repo (see CONTRIBUTING.md). | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| # Default-deny at workflow level; each job re-grants only what it needs. | ||
| permissions: {} | ||
|
|
||
| jobs: | ||
| govulncheck: | ||
| name: govulncheck (Go vuln DB) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1 | ||
|
|
||
| - name: Detect Go module | ||
| id: detect | ||
| run: | | ||
| if [ -f go.mod ]; then | ||
| echo "has_go=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "has_go=false" >> "$GITHUB_OUTPUT" | ||
| echo "::notice::No go.mod present; skipping govulncheck." | ||
| fi | ||
|
|
||
| - name: Set up Go | ||
| if: steps.detect.outputs.has_go == 'true' | ||
| uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: true | ||
|
|
||
| - name: Install govulncheck | ||
| if: steps.detect.outputs.has_go == 'true' | ||
| run: go install golang.org/x/vuln/cmd/govulncheck@latest | ||
|
|
||
| - name: Run govulncheck | ||
| if: steps.detect.outputs.has_go == 'true' | ||
| run: govulncheck ./... | ||
|
|
||
| osv-scanner: | ||
| name: osv-scanner (transitive vulns) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1 | ||
|
|
||
| - name: Detect Go module | ||
| id: detect | ||
| run: | | ||
| # osv-scanner exits non-zero with "No package sources found" if there is | ||
| # nothing to scan. The quantcli org is Go-only today, so gate on go.mod. | ||
| # If a non-Go manifest (package.json, requirements.txt, Cargo.toml, …) is | ||
| # ever introduced, broaden this check. | ||
| if [ -f go.mod ]; then | ||
| echo "has_manifests=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "has_manifests=false" >> "$GITHUB_OUTPUT" | ||
| echo "::notice::No go.mod found; skipping osv-scanner." | ||
| fi | ||
|
|
||
| - name: Set up Go | ||
| if: steps.detect.outputs.has_manifests == 'true' | ||
| uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | ||
| with: | ||
| go-version: stable | ||
| cache: false | ||
|
|
||
| - name: Install osv-scanner | ||
| if: steps.detect.outputs.has_manifests == 'true' | ||
| run: go install github.com/google/osv-scanner/v2/cmd/osv-scanner@latest | ||
|
Terastar-Paperclip marked this conversation as resolved.
|
||
|
|
||
| - name: Run osv-scanner | ||
| if: steps.detect.outputs.has_manifests == 'true' | ||
| run: osv-scanner scan source --recursive . | ||
|
|
||
| license-policy: | ||
| name: license policy (allowlist) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| env: | ||
| # Policy: every direct + transitive Go dep must resolve to one of these SPDX ids. | ||
| # See SECURITY.md "Supply-chain policy" for the rationale. | ||
|
Terastar-Paperclip marked this conversation as resolved.
|
||
| ALLOWED_LICENSES: "Apache-2.0,MIT,BSD-2-Clause,BSD-3-Clause,MPL-2.0,ISC,Unlicense" | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1 | ||
|
|
||
| - name: Detect Go module | ||
| id: detect | ||
| run: | | ||
| if [ -f go.mod ]; then | ||
| echo "has_go=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "has_go=false" >> "$GITHUB_OUTPUT" | ||
| echo "::notice::No go.mod present; skipping license-policy check." | ||
| fi | ||
|
|
||
| - name: Set up Go | ||
| if: steps.detect.outputs.has_go == 'true' | ||
| uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: true | ||
|
|
||
| - name: Install go-licenses | ||
| if: steps.detect.outputs.has_go == 'true' | ||
| run: go install github.com/google/go-licenses@latest | ||
|
Terastar-Paperclip marked this conversation as resolved.
|
||
|
|
||
| - name: Check licenses against allowlist | ||
| if: steps.detect.outputs.has_go == 'true' | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| report=$(mktemp) | ||
| # go-licenses csv emits: module,license-url,license-id (one per line). | ||
| # Warnings (e.g. license-url not found) go to stderr and are non-fatal here. | ||
| go-licenses csv ./... > "$report" | ||
|
|
||
| IFS=',' read -ra ALLOWED <<< "$ALLOWED_LICENSES" | ||
| is_allowed() { | ||
| local needle="$1" | ||
| for a in "${ALLOWED[@]}"; do | ||
| if [ "$needle" = "$a" ]; then return 0; fi | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| bad=0 | ||
| while IFS=',' read -r module url license; do | ||
| [ -z "$module" ] && continue | ||
| if ! is_allowed "$license"; then | ||
| echo "::error::Disallowed license: module=$module license=$license" | ||
| bad=1 | ||
| fi | ||
| done < "$report" | ||
|
|
||
| if [ "$bad" -ne 0 ]; then | ||
| echo "::error::License policy violated. Allowlist: ${ALLOWED_LICENSES}" | ||
| echo "::error::See SECURITY.md for the policy and how to request an exception." | ||
|
Terastar-Paperclip marked this conversation as resolved.
|
||
| exit 1 | ||
| fi | ||
|
|
||
| echo "All dependency licenses are within policy." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.