|
1 | 1 | name: Manifest |
| 2 | +# Uses pull_request_target but with careful security controls |
2 | 3 | on: |
3 | | - pull_request: |
| 4 | + pull_request_target: |
| 5 | + paths: |
| 6 | + - 'west.yml' |
4 | 7 |
|
5 | 8 | permissions: |
6 | 9 | contents: read |
7 | 10 |
|
8 | 11 | jobs: |
9 | | - contribs: |
| 12 | + manifest-validation: |
10 | 13 | runs-on: ubuntu-22.04 |
| 14 | + name: Validate Manifest |
11 | 15 | permissions: |
12 | 16 | pull-requests: write # to create/update pull request comments |
13 | | - issues: write |
14 | | - name: Manifest |
| 17 | + contents: read |
15 | 18 | steps: |
16 | | - - name: Checkout the code |
| 19 | + # SECURITY CRITICAL: First checkout the base repo code WITHOUT using untrusted code |
| 20 | + - name: Checkout base repository |
17 | 21 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
18 | 22 | with: |
19 | | - path: zephyrproject/zephyr |
20 | | - #ref: ${{ github.event.pull_request.head.sha }} |
| 23 | + ref: ${{ github.base_ref }} |
| 24 | + path: base-repo |
21 | 25 | fetch-depth: 0 |
22 | 26 | persist-credentials: false |
23 | 27 |
|
24 | | - - name: west setup |
25 | | - env: |
26 | | - BASE_REF: ${{ github.base_ref }} |
27 | | - working-directory: zephyrproject/zephyr |
| 28 | + # SECURITY: Then fetch PR data - only checking out the specific manifest file |
| 29 | + - name: Fetch PR Manifest |
28 | 30 | run: | |
29 | | - git checkout ${{ github.event.pull_request.head.sha }} |
30 | | - pip install west |
31 | | - git config --global user.email "[email protected]" |
32 | | - git config --global user.name "Your Name" |
| 31 | + # Safely get the PR's west.yml file without executing any PR code |
| 32 | + PR_SHA="${{ github.event.pull_request.head.sha }}" |
| 33 | + PR_REPO="${{ github.event.pull_request.head.repo.full_name }}" |
| 34 | + PR_BRANCH="${{ github.event.pull_request.head.ref }}" |
| 35 | +
|
| 36 | + echo "Fetching west.yml from PR $PR_SHA from $PR_REPO branch $PR_BRANCH" |
| 37 | + mkdir -p pr-repo |
| 38 | + curl -s -L "https://raw.githubusercontent.com/$PR_REPO/$PR_SHA/west.yml" > pr-repo/west.yml |
| 39 | +
|
| 40 | + # Validate the file was downloaded successfully |
| 41 | + if [ ! -s "pr-repo/west.yml" ]; then |
| 42 | + echo "Failed to fetch west.yml from PR" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Validate manifest changes |
| 47 | + run: | |
| 48 | + # Basic manifest file validation |
| 49 | + echo "Validating west.yml format..." |
| 50 | + python -c "import yaml; yaml.safe_load(open('pr-repo/west.yml'))" || { |
| 51 | + echo "Invalid YAML format in west.yml" |
| 52 | + exit 1 |
| 53 | + } |
| 54 | +
|
| 55 | + # Compare manifest files to show changes |
| 56 | + echo "Comparing manifest changes..." |
| 57 | + diff -u base-repo/west.yml pr-repo/west.yml || true |
| 58 | +
|
| 59 | + - name: Create minimal repo structure for west |
| 60 | + run: | |
| 61 | + # Create a minimal structure required by west without executing PR code |
| 62 | + mkdir -p pr-repo/.git |
| 63 | + cp -r base-repo/.git/* pr-repo/.git/ |
| 64 | +
|
| 65 | + - name: West setup |
| 66 | + run: | |
| 67 | + pip install --user west |
| 68 | + git config --global user.email "[email protected]" |
| 69 | + git config --global user.name "GitHub Actions" |
| 70 | +
|
| 71 | + # Initialize west with the manifest file we explicitly downloaded |
| 72 | + cd pr-repo |
33 | 73 | west init -l . || true |
34 | 74 |
|
35 | | - - name: Manifest |
| 75 | + # After creating necessary environment above, run the action |
| 76 | + - name: Run manifest action with restricted token |
36 | 77 | uses: zephyrproject-rtos/action-manifest@cb8f6fba6f20b5f8649bd573e80a7583a239894c # v1.7.0 |
37 | 78 | with: |
38 | 79 | github-token: ${{ secrets.GITHUB_TOKEN }} |
39 | 80 | manifest-path: 'west.yml' |
40 | | - checkout-path: 'zephyrproject/zephyr' |
| 81 | + checkout-path: 'pr-repo' |
41 | 82 | use-tree-checkout: 'true' |
42 | 83 | check-impostor-commits: 'true' |
43 | 84 | label-prefix: 'manifest-' |
44 | 85 | verbosity-level: '1' |
45 | 86 | labels: 'manifest' |
46 | 87 | dnm-labels: 'DNM (manifest)' |
| 88 | + |
| 89 | + # Optional: Clean up sensitive data after running |
| 90 | + - name: Clean up |
| 91 | + if: always() |
| 92 | + run: | |
| 93 | + rm -rf pr-repo base-repo |
0 commit comments