-
Notifications
You must be signed in to change notification settings - Fork 1
build(codeql): coordinate CodeQL Action 4.37.8 lifecycle #1026
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
4a3ff13
661afd3
9532f27
ffcc758
b8c1d1d
871ac35
d2b7097
9fc32ab
481766c
19484ed
2c8a453
717d48a
be5fd37
4b9050d
d50df53
e6ea024
046e221
06d93ae
0913edf
c1f8ccb
a3507bf
513f051
ef6f3b1
c0d4ebc
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 |
|---|---|---|
|
|
@@ -38,4 +38,4 @@ updates: | |
| open-pull-requests-limit: 10 | ||
| labels: | ||
| - "dependencies" | ||
| - "github-actions" | ||
| - "area: ci-cd" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,10 @@ on: | |
| branches: | ||
| - develop | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - develop | ||
| - main | ||
|
|
||
| permissions: read-all | ||
|
|
||
|
|
@@ -27,21 +31,21 @@ jobs: | |
| with: | ||
| persist-credentials: false | ||
| - uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3 | ||
| if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
| if: github.event_name == 'pull_request' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
| with: | ||
| results_file: results.sarif | ||
| results_format: sarif | ||
| publish_results: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} | ||
|
seonghobae marked this conversation as resolved.
|
||
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
| if: github.event_name == 'pull_request' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
| with: | ||
| name: ossf-scorecard-results | ||
| path: results.sarif | ||
| retention-days: 5 | ||
| scorecard-sarif-upload: | ||
| name: scorecard-sarif-upload | ||
| needs: analysis | ||
| if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
| if: github.event_name == 'pull_request' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch) | ||
|
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. 🟡 Forked pull requests fail Scorecard upload Fork pull requests run Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: read | ||
|
|
@@ -63,7 +67,7 @@ jobs: | |
| with: | ||
| persist-credentials: false | ||
| path: trusted-scorecard-scripts | ||
| ref: ${{ github.ref_name }} | ||
| ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.ref_name }} | ||
|
seonghobae marked this conversation as resolved.
|
||
| - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | ||
| with: | ||
| name: ossf-scorecard-results | ||
|
|
@@ -79,6 +83,6 @@ jobs: | |
| python3 trusted-scorecard-scripts/scripts/checks/normalize_scorecard_sarif.py | ||
| scorecard-sarif/results.sarif | ||
| normalized-scorecard-results.sarif | ||
| - uses: github/codeql-action/upload-sarif@99df26d4f13ea111d4ec1a7dddef6063f76b97e9 # v4.37.0 peeled commit; SHA pinning retained as supply-chain attack mitigation. | ||
| - uses: github/codeql-action/upload-sarif@db488ddef3bf6cb639b32c2e9a7c0a7ea8271d28 # v4.37.8 peeled commit; SHA pinning retained as supply-chain attack mitigation. | ||
| with: | ||
| sarif_file: normalized-scorecard-results.sarif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """Regression contract for coordinated CodeQL Action component upgrades.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| from pathlib import Path | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[3] | ||
| CODEQL_WORKFLOW = REPO_ROOT / ".github" / "workflows" / "codeql.yml" | ||
| CODEQL_ACTION_PATTERN = re.compile( | ||
| r"github/codeql-action/(?:init|autobuild|analyze)@([0-9a-f]{40})\s+#\s+(v[0-9.]+)" | ||
| ) | ||
|
|
||
|
|
||
| def test_codeql_job_uses_one_action_release() -> None: | ||
| """Require init, autobuild, and analyze to use one reviewed CodeQL release.""" | ||
| workflow = CODEQL_WORKFLOW.read_text(encoding="utf-8") | ||
| action_refs = CODEQL_ACTION_PATTERN.findall(workflow) | ||
|
|
||
| assert len(action_refs) == 3 | ||
| assert len({sha for sha, _version in action_refs}) == 1 | ||
| assert len({version for _sha, version in action_refs}) == 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """Regression contracts for CodeQL SARIF uploader provenance comments.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[3] | ||
| EXPECTED_SHA = "db488ddef3bf6cb639b32c2e9a7c0a7ea8271d28" | ||
| EXPECTED_VERSION = "v4.37.8" | ||
| UPLOAD_SARIF_REF = ( | ||
| f"github/codeql-action/upload-sarif@{EXPECTED_SHA} # {EXPECTED_VERSION} peeled commit;" | ||
| ) | ||
| WORKFLOWS = ( | ||
| REPO_ROOT / ".github" / "workflows" / "ossf-scorecard.yml", | ||
| REPO_ROOT / ".github" / "workflows" / "trivy.yml", | ||
| ) | ||
|
|
||
|
|
||
| def test_upload_sarif_sha_and_version_comment_move_together() -> None: | ||
| """Keep each immutable SARIF uploader pin paired with its reviewed release label.""" | ||
| for workflow in WORKFLOWS: | ||
| contents = workflow.read_text(encoding="utf-8") | ||
| assert contents.count(UPLOAD_SARIF_REF) == 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| """Regression contract for Dependabot's configured repository labels.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[3] | ||
| DEPENDABOT_CONFIG = REPO_ROOT / ".github" / "dependabot.yml" | ||
|
|
||
|
|
||
| def test_github_actions_updates_use_repository_ci_cd_taxonomy() -> None: | ||
| """Keep GitHub Actions updates on an existing CI/CD taxonomy label.""" | ||
| config = DEPENDABOT_CONFIG.read_text(encoding="utf-8") | ||
| github_actions = config.split('package-ecosystem: "github-actions"', maxsplit=1)[1] | ||
|
|
||
| assert '- "area: ci-cd"' in github_actions | ||
| assert '- "github-actions"' not in github_actions |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """Regression contract for OpenSSF Scorecard evidence on pull-request heads.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[3] | ||
| WORKFLOW = REPO_ROOT / ".github" / "workflows" / "ossf-scorecard.yml" | ||
| DEFAULT_BRANCH_GUARD = "github.ref == format('refs/heads/{0}', github.event.repository.default_branch)" | ||
| PR_OR_DEFAULT_BRANCH = f"github.event_name == 'pull_request' || {DEFAULT_BRANCH_GUARD}" | ||
|
Comment on lines
+9
to
+10
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. |
||
| PR_SAFE_TRUSTED_REF = ( | ||
| "ref: ${{ github.event_name == 'pull_request' && " | ||
| "github.event.pull_request.base.sha || github.ref_name }}" | ||
| ) | ||
|
|
||
|
|
||
| def test_scorecard_produces_pr_code_scanning_evidence_without_pr_publishing() -> None: | ||
| """Keep PR SARIF coverage while publishing only trusted default-branch runs.""" | ||
| contents = WORKFLOW.read_text(encoding="utf-8") | ||
|
|
||
| assert "pull_request_target:" not in contents | ||
| assert " pull_request:\n branches:\n - develop\n - main\n" in contents | ||
| assert contents.count(f"if: {PR_OR_DEFAULT_BRANCH}") == 3 | ||
| publish_lines = [ | ||
| line.strip() | ||
| for line in contents.splitlines() | ||
| if line.strip().startswith("publish_results:") | ||
| ] | ||
| assert publish_lines == [f"publish_results: ${{{{ {DEFAULT_BRANCH_GUARD} }}}}"] | ||
|
Comment on lines
+24
to
+29
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. |
||
| assert PR_SAFE_TRUSTED_REF in contents | ||
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.
🔍 Existing workflow contract test now fails
The existing push-only contract rejects
pull_request:in Scorecard and Trivy. These additions make the Python gate fail.Was this helpful? React with 👍 or 👎 to provide feedback.