-
Notifications
You must be signed in to change notification settings - Fork 12
ci: run all tests on pull_request_target event #365
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,62 @@ | ||
| # Inspired by https://github.com/osbuild/bootc-image-builder/blob/031df2b115743a87b6684d4894f3d1730afefc98/.github/workflows/testingfarm.yml | ||
| on: | ||
| issue_comment: | ||
| types: | ||
| - created | ||
| pull_request_target: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| # To use testing farm we need the TF_API_KEY secret available inside the | ||
| # forked repo which requires the pull_request_target trigger. To protect | ||
| # the secrets we need to make sure only people with repo write access | ||
| # can trigger this workflow. This means that outside contributors will | ||
| # get an initial failure when the workflow is run. But once someone from | ||
| # the team re-triggers it it will work. | ||
| # | ||
| # Note that "pull_request_target" events are always triggered even | ||
| # when the "Fork pull request workflows from outside collaborators" | ||
| # setting is restricted to "Require approval for all outside collaborators" | ||
| # (see https://docs.github.com/en/actions/managing-workflow-runs/approving-workflow-runs-from-public-forks) | ||
| # | ||
| # Note also that these precautions might be overkill because a fork | ||
| # cannot modify this workflow and all we do is run a branch inside | ||
| # testing farm. But a) the scope of workflow may expand over time | ||
| # b) it feels safer this way and is not a big burden in practice. | ||
| # | ||
| # This follows https://michaelheap.com/access-secrets-from-forks/ | ||
| jobs: | ||
| container-tests: | ||
| runs-on: ubuntu-latest | ||
| testingfarm: | ||
| name: "Smoke test for testing farm as a github action" | ||
| runs-on: ubuntu-latest | ||
|
|
||
| if: | | ||
| github.event.issue.pull_request | ||
| && contains(github.event.comment.body, '[test]') | ||
| && contains(fromJson('["OWNER", "MEMBER"]'), github.event.comment.author_association) | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| statuses: write | ||
|
|
||
| steps: | ||
| - name: Checkout repo | ||
| - name: Get User Permission | ||
| id: checkAccess | ||
| uses: actions-cool/check-user-permission@v2 | ||
| with: | ||
| require: write | ||
| username: ${{ github.triggering_actor }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Check User Permission | ||
| if: steps.checkAccess.outputs.require-result == 'false' | ||
| run: | | ||
| echo "${{ github.triggering_actor }} does not have permissions on this repo." | ||
| echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}" | ||
| echo "Job originally triggered by ${{ github.actor }}" | ||
| exit 1 | ||
|
|
||
| # This repo is the action under test, so we must check out the PR | ||
| # code to validate changes. The permission check above ensures only | ||
| # users with write access can reach this step. | ||
| - name: Check out code | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: "refs/pull/${{ github.event.issue.number }}/head" | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
|
Comment on lines
+55
to
+58
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 | 🔴 Critical | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
for f in \
.github/workflows/base-test.yml \
.github/workflows/secrets_test.yml \
.github/workflows/timeout-test.yml \
.github/workflows/variables_test.yml
do
echo "===== $f ====="
wc -l "$f"
sed -n '1,180p' "$f"
done
echo "===== workflow references and permissions ====="
rg -n -C 3 \
'pull_request_target|pull_request:|permissions:|GITHUB_TOKEN|TF_PUBLIC_API_KEY|actions-cool/check-user-permission|uses: \./|Testing Farm|github\.event\.pull_request\.head\.sha|github\.event\.pull_request\.base\.sha' \
.github/workflowsRepository: sclorg/testing-farm-as-github-action Length of output: 24007 🏁 Script executed: #!/bin/bash
set -eu
echo "===== repository files ====="
git ls-files | sed -n '1,160p'
echo "===== action metadata candidates ====="
fd -i 'action.yml|action.yaml|package.json|Dockerfile' .
for f in $(fd -i 'action.yml|action.yaml' .); do
echo "===== $f ====="
wc -l "$f"
cat -n "$f"
done
echo "===== local action entry points and workflow-facing APIs ====="
rg -n -C 4 \
'runs:|using:|main:|pre:|post:|GITHUB_TOKEN|TF_PUBLIC_API_KEY|api_key|pull_request|create_issue_comment|update_pull_request_status|octokit|github\.rest|process\.env|`@actions/`' \
--glob '!node_modules/**' \
--glob '!dist/**' \
--glob '!build/**' .Repository: sclorg/testing-farm-as-github-action Length of output: 50394 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
workflows = [
Path(".github/workflows/base-test.yml"),
Path(".github/workflows/secrets_test.yml"),
Path(".github/workflows/timeout-test.yml"),
Path(".github/workflows/variables_test.yml"),
]
checks = {
"pull_request_target trigger": r"^\s*pull_request_target:",
"head SHA checkout": r"ref:\s*\$\{\{\s*github\.event\.pull_request\.head\.sha\s*\}\}",
"local action execution": r"^\s*uses:\s*\./\s*$",
"Testing Farm API key": r"api_key:\s*\$\{\{\s*secrets\.TF_PUBLIC_API_KEY\s*\}\}",
"pull request write permission": r"^\s*pull-requests:\s*write\s*$",
"status write permission": r"^\s*statuses:\s*write\s*$",
}
for path in workflows:
text = path.read_text()
missing = [name for name, pattern in checks.items()
if not re.search(pattern, text, re.MULTILINE)]
print(f"{path}: {'PASS' if not missing else 'MISSING ' + ', '.join(missing)}")
action = Path("action.yml").read_text()
print("action.yml: local Node entry point:",
"PASS" if re.search(r"^\s*main:\s*dist/main\.js\s*$", action, re.MULTILINE)
else "MISSING")
PYRepository: sclorg/testing-farm-as-github-action Length of output: 378 Do not execute the pull request checkout in these privileged 🧰 Tools🪛 zizmor (1.29.0)[warning] 52-55: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false (artipacked) 📍 Affects 4 files
🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| allow-unsafe-pr-checkout: true | ||
|
|
||
| - name: Run the tests | ||
| uses: ./ | ||
|
|
||
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.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: sclorg/testing-farm-as-github-action
Length of output: 19062
🏁 Script executed:
Repository: sclorg/testing-farm-as-github-action
Length of output: 536
Pin
actions-cool/check-user-permissionto a reviewed full commit SHA in all four workflows.These
pull_request_targetjobs grant write permissions and exposeGITHUB_TOKENto the mutable@v2reference..github/workflows/base-test.yml#L37.github/workflows/secrets_test.yml#L18.github/workflows/timeout-test.yml#L18.github/workflows/variables_test.yml#L18📍 Affects 4 files
.github/workflows/base-test.yml#L35-L42(this comment).github/workflows/secrets_test.yml#L16-L23.github/workflows/timeout-test.yml#L16-L23.github/workflows/variables_test.yml#L16-L23🤖 Prompt for AI Agents