Skip to content

Commit 702f3b0

Browse files
committed
Harden GitHub Actions workflows per zizmor, poutine and octoscan
- Pass expressions to run scripts through env variables instead of expanding them into the script (template-injection) - Declare explicit least-privilege permissions on every workflow and document the non-obvious ones - Do not persist checkout credentials unless a later step pushes with them - Add concurrency groups where a newer run supersedes an older one - Name the remaining anonymous jobs after their IDs, keeping check names - Install actionlint from its digest-pinned image instead of piping a downloaded script into bash - Scan only externally triggerable workflows with octoscan, its default - Configure poutine's allowed GitHub-hosted arm runner and the reviewed third-party actions - Document by-design exceptions with inline zizmor ignores Amp-Thread-ID: https://ampcode.com/threads/T-01a197a7-c816-7129-bba7-bbd97e6de236
1 parent 4a6e0e9 commit 702f3b0

32 files changed

Lines changed: 325 additions & 69 deletions

‎.github/actions/downgrade-code/action.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ runs:
1818
- name: "Transform source code"
1919
if: inputs.php-version == '7.4' || inputs.php-version == '8.0' || inputs.php-version == '8.1'
2020
shell: bash
21+
env:
22+
TARGET_PHP_VERSION: ${{ inputs.php-version }}
2123
run: |
2224
composer install --no-interaction --no-progress --working-dir=compiler
23-
./compiler/vendor/bin/simple-downgrade downgrade -c build/downgrade.php ${{ inputs.php-version }}
25+
./compiler/vendor/bin/simple-downgrade downgrade -c build/downgrade.php "$TARGET_PHP_VERSION"
2426
composer dump
2527
2628
- name: "Re-store PHP version"

‎.github/poutine.yml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# https://github.com/boostsecurityio/poutine/blob/main/.poutine.sample.yml
2+
3+
rulesConfig:
4+
pr_runs_on_self_hosted:
5+
allowed_runners:
6+
# GitHub-hosted arm64 runner, not a self-hosted one
7+
- ubuntu-24.04-arm
8+
9+
skip:
10+
# Third-party actions in use, each pinned to a full commit SHA and reviewed
11+
# whenever the pin is bumped. A newly added action still gets reported.
12+
- rule: github_action_from_unverified_creator_used
13+
purl:
14+
- pkg:githubactions/astral-sh/setup-uv
15+
- pkg:githubactions/baptiste0928/cargo-install
16+
- pkg:githubactions/crate-ci/typos
17+
- pkg:githubactions/crazy-max/ghaction-import-gpg
18+
- pkg:githubactions/dorny/paths-filter
19+
- pkg:githubactions/ilammy/msvc-dev-cmd
20+
- pkg:githubactions/juliangruber/merge-pull-request-action
21+
- pkg:githubactions/morishiri/block-merge-commits-action
22+
- pkg:githubactions/peter-evans/create-or-update-comment
23+
- pkg:githubactions/peter-evans/create-pull-request
24+
- pkg:githubactions/peter-evans/repository-dispatch
25+
- pkg:githubactions/ramsey/composer-install
26+
- pkg:githubactions/rickstaa/action-create-tag
27+
- pkg:githubactions/scholliyt/broken-links-crawler-action
28+
- pkg:githubactions/shivammathur/setup-php
29+
- pkg:githubactions/stefanzweifel/git-auto-commit-action
30+
- pkg:githubactions/synacktiv/action-octoscan
31+
- pkg:githubactions/typeddevs/bashunit
32+
- pkg:githubactions/wyrihaximus/github-action-get-previous-tag
33+
- pkg:githubactions/wyrihaximus/github-action-next-semvers
34+
- pkg:githubactions/wyrihaximus/github-action-wait-for-status

‎.github/workflows/apiref-infra.yml‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ on:
1515
- '.github/workflows/apiref-infra.yml'
1616
- 'apigen/infra/**'
1717

18-
concurrency: apiref-infra
18+
# deploys queue up instead of cancelling one another, so a CDK deployment is never interrupted
19+
concurrency: apiref-infra # zizmor: ignore[concurrency-limits]
20+
21+
permissions:
22+
contents: read
1923

2024
jobs:
2125
test:
@@ -32,6 +36,8 @@ jobs:
3236

3337
- name: "Checkout"
3438
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
39+
with:
40+
persist-credentials: false
3541

3642
- name: "Install Node"
3743
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
@@ -62,7 +68,7 @@ jobs:
6268
needs: test
6369
if: "github.event_name == 'push' && github.ref == 'refs/heads/2.3.x'"
6470
permissions:
65-
id-token: write
71+
id-token: write # assumes the deploy role in AWS through OIDC
6672
contents: read
6773

6874
steps:
@@ -73,6 +79,8 @@ jobs:
7379

7480
- name: "Checkout"
7581
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
82+
with:
83+
persist-credentials: false
7684

7785
- name: "Install Node"
7886
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0

‎.github/workflows/apiref.yml‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ concurrency:
2121
group: apigen-${{ github.ref }} # will be canceled on subsequent pushes in branch
2222
cancel-in-progress: true
2323

24+
permissions:
25+
contents: read
26+
2427
jobs:
2528
apigen:
2629
name: "Run ApiGen"
@@ -36,6 +39,8 @@ jobs:
3639

3740
- name: "Checkout"
3841
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
42+
with:
43+
persist-credentials: false
3944

4045
- name: "Install PHP"
4146
uses: "shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962" # 2.40.0
@@ -66,7 +71,7 @@ jobs:
6671
if: github.repository_owner == 'phpstan'
6772
runs-on: "ubuntu-latest"
6873
permissions:
69-
id-token: write
74+
id-token: write # assumes the deploy role in AWS through OIDC
7075
contents: read
7176
steps:
7277
- name: Harden the runner (Audit all outbound calls)
@@ -87,16 +92,20 @@ jobs:
8792
aws-region: us-east-1
8893

8994
- name: "Sync with S3"
95+
env:
96+
APIREF_BUCKET: ${{ vars.APIREF_BUCKET }}
9097
run: |
91-
aws s3 sync ./docs "s3://${{ vars.APIREF_BUCKET }}/${{ github.ref_name }}" \
98+
aws s3 sync ./docs "s3://${APIREF_BUCKET}/${GITHUB_REF_NAME}" \
9299
--exclude '.git*/*' \
93100
--follow-symlinks
94101
95102
- name: "Invalidate CloudFront"
103+
env:
104+
APIREF_DISTRIBUTION_ID: ${{ vars.APIREF_DISTRIBUTION_ID }}
96105
run: |
97106
aws cloudfront create-invalidation \
98-
--distribution-id "${{ vars.APIREF_DISTRIBUTION_ID }}" \
99-
--paths "/${{ github.ref_name }}/*"
107+
--distribution-id "${APIREF_DISTRIBUTION_ID}" \
108+
--paths "/${GITHUB_REF_NAME}/*"
100109
101110
- uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1
102111
with:

‎.github/workflows/backward-compatibility.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
- name: "Checkout"
3535
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3636
with:
37+
persist-credentials: false
3738
fetch-depth: 0
3839

3940
- name: "Install PHP"

‎.github/workflows/bench.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535

3636
- name: "Checkout base branch"
3737
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
38+
with:
39+
persist-credentials: false
3840

3941
- name: "Install PHP"
4042
uses: "shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962" # 2.40.0
@@ -73,6 +75,8 @@ jobs:
7375

7476
- name: "Checkout"
7577
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
78+
with:
79+
persist-credentials: false
7680

7781
- name: "Install PHP"
7882
uses: "shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962" # 2.40.0

‎.github/workflows/block-merge-commits.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ on: pull_request
22

33
name: Block merge commits
44

5+
concurrency:
6+
group: block-merge-commits-${{ github.event.pull_request.number }}
7+
cancel-in-progress: true
8+
9+
permissions:
10+
pull-requests: read # Block Merge Commits lists the pull request's commits
11+
512
jobs:
613
message-check:
714
name: Block Merge Commits

‎.github/workflows/build-issue-bot.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343

4444
- name: "Checkout"
4545
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
46+
with:
47+
persist-credentials: false
4648

4749
- name: "Install PHP"
4850
uses: "shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962" # 2.40.0
@@ -59,4 +61,6 @@ jobs:
5961

6062
- name: "Tests"
6163
working-directory: "issue-bot"
62-
run: ${{ matrix.script }}
64+
env:
65+
MATRIX_SCRIPT: ${{ matrix.script }}
66+
run: '"$MATRIX_SCRIPT"'

‎.github/workflows/changelog-generator.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636

3737
- name: "Checkout"
3838
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
39+
with:
40+
persist-credentials: false
3941

4042
- name: "Install PHP"
4143
uses: "shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962" # 2.40.0

‎.github/workflows/claude-react-on-review-dispatch.yml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
name: "Claude React On Review Dispatch"
22

3-
on:
4-
workflow_run:
3+
on: # zizmor: ignore[concurrency-limits] -- one run per submitted review, none supersedes another
4+
workflow_run: # zizmor: ignore[dangerous-triggers] -- runs no code from the pull request, only forwards the review's numeric IDs as quoted gh arguments
55
workflows: ["Claude React On Review"]
66
types: [completed]
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
dispatch:
13+
name: dispatch
1014
runs-on: ubuntu-latest
1115
if: github.event.workflow_run.conclusion == 'success'
1216
permissions:
13-
contents: read
14-
actions: write
17+
actions: read # downloads the review-context artifact of the triggering run
1518
steps:
1619
- name: Harden the runner (Audit all outbound calls)
1720
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3

0 commit comments

Comments
 (0)