-
Notifications
You must be signed in to change notification settings - Fork 0
ci: codeql-guard to keep CodeQL out of evalops/* #29
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
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| name: codeql-guard | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - ".github/workflows/**" | ||
| - ".github/workflow-templates/**" | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - ".github/workflows/**" | ||
| - ".github/workflow-templates/**" | ||
| schedule: | ||
| # Daily org-wide drift sweep. | ||
| - cron: "17 9 * * *" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| guard-self: | ||
| name: Forbid CodeQL in evalops/.github | ||
| if: ${{ github.event_name != 'schedule' }} | ||
| runs-on: blacksmith-4vcpu-ubuntu-2404 | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 | ||
|
|
||
| - name: Forbid github/codeql-action references | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| shopt -s globstar nullglob | ||
| targets=(.github/workflows .github/workflow-templates) | ||
| existing=() | ||
| for d in "${targets[@]}"; do | ||
| [ -d "$d" ] && existing+=("$d") | ||
| done | ||
| if [ "${#existing[@]}" -eq 0 ]; then | ||
| echo "no workflow directories present" | ||
| exit 0 | ||
| fi | ||
| if grep -RIn --include='*.yml' --include='*.yaml' --exclude='codeql-guard.yml' \ | ||
| 'github/codeql-action' "${existing[@]}" 2>/dev/null; then | ||
| echo "::error::EvalOps policy forbids github/codeql-action. See SECURITY.md (Code Scanning)." | ||
| exit 1 | ||
| fi | ||
| echo "ok: no codeql-action references in evalops/.github" | ||
|
|
||
| guard-org: | ||
| name: Sweep evalops/* for CodeQL workflow drift | ||
| if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} | ||
| runs-on: blacksmith-4vcpu-ubuntu-2404 | ||
| timeout-minutes: 15 | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| ORG_CODE_SEARCH_TOKEN: ${{ secrets.EVALOPS_ORG_READ_TOKEN }} | ||
| steps: | ||
| - name: Search org for github/codeql-action references | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| if [ -z "${ORG_CODE_SEARCH_TOKEN}" ]; then | ||
| echo "::error::Set secrets.EVALOPS_ORG_READ_TOKEN to a token with org-wide code search access." | ||
| exit 1 | ||
| fi | ||
| response="$( | ||
| GH_TOKEN="${ORG_CODE_SEARCH_TOKEN}" gh api -X GET search/code \ | ||
| -f q='org:evalops "github/codeql-action" path:.github/workflows' \ | ||
| --jq '.items[] | "\(.repository.full_name)\t\(.path)"' \ | ||
| )" | ||
| if [ -z "${response}" ]; then | ||
| echo "ok: no CodeQL workflow files found in any evalops repo" | ||
| exit 0 | ||
| fi | ||
| mapfile -t hits <<< "${response}" | ||
| { | ||
| echo "## codeql-guard tripped" | ||
| echo | ||
| echo "EvalOps does not run GitHub CodeQL (see \`SECURITY.md\` and the Blacksmith" | ||
| echo "code security configuration). The following workflow files reference" | ||
| echo "\`github/codeql-action\` and need to be removed or the policy amended:" | ||
| echo | ||
| for h in "${hits[@]}"; do | ||
| repo="${h%%$'\t'*}" | ||
| path="${h##*$'\t'}" | ||
| echo "- \`${repo}\` — \`${path}\`" | ||
| done | ||
| } > /tmp/body.md | ||
| title="codeql-guard: CodeQL workflow drift detected" | ||
| if issue_number="$(gh issue list --repo evalops/.github --state open --search "\"${title}\" in:title" --limit 1 --json number --jq '.[0].number // empty')" && [ -n "${issue_number}" ]; then | ||
| echo "open tracking issue already exists: #${issue_number}" | ||
| else | ||
| gh issue create \ | ||
| --repo evalops/.github \ | ||
| --title "${title}" \ | ||
| --body-file /tmp/body.md | ||
| fi | ||
| exit 1 | ||
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.