Repository navigation
Add advisory PR commit signature verification #12703
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 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9012105
Add PR commit signature verification
brooke-hamilton 194aa11
Refactor signature comment orchestration
brooke-hamilton a3bee1f
Enable manual signature verification
brooke-hamilton fcbf3e3
Report commit verification results
brooke-hamilton 4dbb978
Retain commit signature guidance comments
brooke-hamilton d185c64
Avoid workflow command injection
brooke-hamilton 561ebd3
Potential fix for pull request finding
brooke-hamilton 622b615
Validate signature verifier output
brooke-hamilton 9b23913
Merge branch 'main' into brooke-hamilton-commit-signoff-check
brooke-hamilton 6833783
Use github-script for signature verification
brooke-hamilton af8be6a
Decompose signature verification script
brooke-hamilton 65adad0
Extract signature verification script
brooke-hamilton c978ccf
Merge origin/main into commit signature verification
brooke-hamilton 925fbf6
Address signature verifier review feedback
brooke-hamilton c8d6a5c
Apply repository JavaScript formatting
brooke-hamilton ca94950
Serialize pnpm-based lint checks
brooke-hamilton 0d734a8
Revert "Serialize pnpm-based lint checks"
brooke-hamilton 5b4bab3
Merge branch 'main' into brooke-hamilton-commit-signoff-check
brooke-hamilton 8cb4e64
Merge branch 'main' into brooke-hamilton-commit-signoff-check
brooke-hamilton 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| #!/bin/bash | ||
|
|
||
| # ------------------------------------------------------------ | ||
| # Copyright 2026 The Radius Authors. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ------------------------------------------------------------ | ||
|
|
||
| # Lists pull request commits that do not have a GitHub Verified signature. | ||
| # Requires the GitHub CLI and jq. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # shellcheck disable=SC2016 # GraphQL variables must remain literal. | ||
| readonly GRAPHQL_QUERY=' | ||
| query( | ||
| $endCursor: String | ||
| $number: Int! | ||
| $owner: String! | ||
| $repo: String! | ||
| ) { | ||
| repository(owner: $owner, name: $repo) { | ||
| pullRequest(number: $number) { | ||
| commits(first: 100, after: $endCursor) { | ||
| nodes { | ||
| commit { | ||
| oid | ||
| signature { | ||
| isValid | ||
| state | ||
| } | ||
| } | ||
| } | ||
| pageInfo { | ||
| hasNextPage | ||
| endCursor | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }' | ||
|
|
||
| require_environment() { | ||
| local name | ||
| for name in GH_TOKEN GITHUB_REPOSITORY PR_NUMBER; do | ||
| if [[ -z "${!name:-}" ]]; then | ||
| echo "Error: ${name} is required" >&2 | ||
| return 1 | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| require_commands() { | ||
| local command | ||
| for command in gh jq; do | ||
| if ! command -v "${command}" > /dev/null; then | ||
| echo "Error: ${command} is required" >&2 | ||
| return 1 | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| main() { | ||
| require_environment | ||
| require_commands | ||
|
|
||
| local owner | ||
| local repo | ||
| IFS="/" read -r owner repo <<< "${GITHUB_REPOSITORY}" | ||
| if [[ -z "${owner}" || -z "${repo}" ]]; then | ||
| echo "Error: GITHUB_REPOSITORY must use owner/repo format" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| local response | ||
| response="$( | ||
| gh api graphql --paginate --slurp \ | ||
| -f query="${GRAPHQL_QUERY}" \ | ||
| -F owner="${owner}" \ | ||
| -F repo="${repo}" \ | ||
| -F number="${PR_NUMBER}" | ||
| )" | ||
|
|
||
| if ! jq -e \ | ||
| 'all(.[]; .data.repository.pullRequest != null)' \ | ||
| <<< "${response}" > /dev/null; then | ||
| echo "Error: pull request ${PR_NUMBER} was not found" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| jq -c ' | ||
| [ | ||
| .[] | | ||
| .data.repository.pullRequest.commits.nodes[] | | ||
| select( | ||
| .commit.signature == null or | ||
| .commit.signature.isValid != true or | ||
| .commit.signature.state != "VALID" | ||
| ) | | ||
| .commit.oid | ||
| ] | ||
| ' <<< "${response}" | ||
| } | ||
|
|
||
| main "$@" | ||
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,101 @@ | ||
| # yaml-language-server: $schema=https://www.schemastore.org/github-workflow.json | ||
| --- | ||
| name: Verify Commit Signatures | ||
|
Copilot marked this conversation as resolved.
Outdated
|
||
|
|
||
| on: | ||
| # This workflow uses the trusted base commit and never executes PR-head code. | ||
| pull_request_target: | ||
| types: [opened, reopened, synchronize] | ||
| workflow_dispatch: | ||
| inputs: | ||
| pr_number: | ||
| description: Pull request number to verify | ||
| required: true | ||
| type: number | ||
|
|
||
| concurrency: | ||
| group: verify-commit-signatures-${{ github.event.pull_request.number || inputs.pr_number }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| verify-commit-signatures: | ||
| name: Verify Commit Signatures | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 5 | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }} | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| steps: | ||
| - name: Checkout signature verifier | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.sha || github.sha }} | ||
| sparse-checkout: | | ||
| .github/scripts/verify-commit-signatures.sh | ||
| sparse-checkout-cone-mode: false | ||
| persist-credentials: false | ||
|
|
||
| - name: Verify commit signatures | ||
|
brooke-hamilton marked this conversation as resolved.
|
||
| id: verify | ||
| run: | | ||
| unverified_commits="$(./.github/scripts/verify-commit-signatures.sh)" | ||
| count="$(jq 'length' <<< "${unverified_commits}")" | ||
|
|
||
| if [[ "${count}" == "0" ]]; then | ||
| echo "All pull request commits have Verified signatures." | ||
| else | ||
| printf 'Found %s commit(s) without Verified signatures:\n' "${count}" | ||
| jq -r '.[] | "- \(.[0:7])"' <<< "${unverified_commits}" | ||
| fi | ||
|
|
||
| printf 'unverified_commits=%s\n' "${unverified_commits}" >> "${GITHUB_OUTPUT}" | ||
| printf 'count=%s\n' "${count}" >> "${GITHUB_OUTPUT}" | ||
|
|
||
| - name: Prepare signature guidance | ||
| if: steps.verify.outputs.count != '0' | ||
| env: | ||
| UNVERIFIED_COMMITS: ${{ steps.verify.outputs.unverified_commits }} | ||
| run: | | ||
| pr_author="$( | ||
| gh api "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" \ | ||
| --jq '.user.login' | ||
| )" | ||
|
brooke-hamilton marked this conversation as resolved.
Outdated
|
||
| guide_path="docs/contributing/contributing-code" | ||
| guide_path+="/contributing-code-first-commit" | ||
| guide_path+="/first-commit-06-creating-a-pr/index.md" | ||
| guide_url="${GITHUB_SERVER_URL}/radius-project/radius/blob/main" | ||
| guide_url+="/${guide_path}#signing-your-commits" | ||
|
|
||
| { | ||
| printf 'Hi @%s, thank you for contributing to Radius.\n\n' "${pr_author}" | ||
| echo "The following commits do not currently show a GitHub **Verified** signature:" | ||
| echo | ||
| jq -r \ | ||
| --arg origin "${GITHUB_SERVER_URL}" \ | ||
| --arg repo "${GITHUB_REPOSITORY}" \ | ||
| '.[] | "- [`\(.[:7])`](\($origin)/\($repo)/commit/\(.))"' \ | ||
| <<< "${UNVERIFIED_COMMITS}" | ||
| echo | ||
| printf '%s%s%s\n' \ | ||
| "Please follow our [commit-signing guide](${guide_url}) to " \ | ||
| "configure GPG, SSH, or S/MIME signing. Then re-sign the affected " \ | ||
| "commits and force-push the rewritten branch with \`--force-with-lease\`." | ||
|
brooke-hamilton marked this conversation as resolved.
Outdated
|
||
| echo | ||
| printf '%s%s\n' \ | ||
| "Cryptographic commit signing is separate from the DCO " \ | ||
| "\`Signed-off-by\` line; both are required." | ||
| } > commit-signature-guidance.md | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| - name: Post signature guidance | ||
| if: steps.verify.outputs.count != '0' | ||
| uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5 | ||
| with: | ||
| header: commit-signature-verification | ||
| number_force: ${{ github.event.pull_request.number || inputs.pr_number }} | ||
| path: commit-signature-guidance.md | ||
| skip_unchanged: true | ||
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
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.