From 0364da59d21da7598db17cfc2b012e0c63610ae4 Mon Sep 17 00:00:00 2001 From: smarcet Date: Tue, 24 Nov 2026 10:18:35 -0300 Subject: [PATCH 1/5] ci: install composer dependencies with the job token Dependabot and fork runs do not receive secrets.PAT, and Composer fails to authenticate with an empty token. Every locked package comes from a public GitHub repository, so the read-only job token is enough. --- .github/workflows/l5-swagger-generate.yml | 3 ++- .github/workflows/pull_request_unit_tests.yml | 3 ++- .github/workflows/push.yml | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/l5-swagger-generate.yml b/.github/workflows/l5-swagger-generate.yml index 8c7d7fa1..34f1b552 100644 --- a/.github/workflows/l5-swagger-generate.yml +++ b/.github/workflows/l5-swagger-generate.yml @@ -57,7 +57,8 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT }}"} }' + # Every locked package comes from a public repository, so the job token is enough. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' - name: Generate OpenAPI docs run: php artisan l5-swagger:generate diff --git a/.github/workflows/pull_request_unit_tests.yml b/.github/workflows/pull_request_unit_tests.yml index f150ee00..53d8fbd0 100644 --- a/.github/workflows/pull_request_unit_tests.yml +++ b/.github/workflows/pull_request_unit_tests.yml @@ -63,7 +63,8 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT }}"} }' + # Every locked package comes from a public repository, so the job token is enough. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' - name: 'Run Tests' env: TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 88d4189a..bf77f253 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -59,7 +59,8 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT }}"} }' + # Every locked package comes from a public repository, so the job token is enough. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' - name: 'Run Tests' env: TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }} From 3ad3716bf2ddbebd3d1371b171c7585b56da3763 Mon Sep 17 00:00:00 2001 From: smarcet Date: Tue, 24 Nov 2026 10:23:07 -0300 Subject: [PATCH 2/5] ci: keep secrets.PAT for composer when the run has it The job token has a lower API rate limit than the PAT. Runs that receive the secret keep using it, and the job token is the fallback for Dependabot and fork runs. --- .github/workflows/l5-swagger-generate.yml | 5 +++-- .github/workflows/pull_request_unit_tests.yml | 5 +++-- .github/workflows/push.yml | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/l5-swagger-generate.yml b/.github/workflows/l5-swagger-generate.yml index 34f1b552..4b7ce2fe 100644 --- a/.github/workflows/l5-swagger-generate.yml +++ b/.github/workflows/l5-swagger-generate.yml @@ -57,8 +57,9 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - # Every locked package comes from a public repository, so the job token is enough. - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' + # Dependabot and fork runs do not receive secrets.PAT. An empty token makes + # Composer fail to authenticate, so those runs use the read-only job token. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT || github.token }}"} }' - name: Generate OpenAPI docs run: php artisan l5-swagger:generate diff --git a/.github/workflows/pull_request_unit_tests.yml b/.github/workflows/pull_request_unit_tests.yml index 53d8fbd0..902524c0 100644 --- a/.github/workflows/pull_request_unit_tests.yml +++ b/.github/workflows/pull_request_unit_tests.yml @@ -63,8 +63,9 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - # Every locked package comes from a public repository, so the job token is enough. - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' + # Dependabot and fork runs do not receive secrets.PAT. An empty token makes + # Composer fail to authenticate, so those runs use the read-only job token. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT || github.token }}"} }' - name: 'Run Tests' env: TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index bf77f253..7a7ab81b 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -59,8 +59,9 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - # Every locked package comes from a public repository, so the job token is enough. - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' + # Dependabot runs do not receive secrets.PAT. An empty token makes Composer + # fail to authenticate, so those runs use the read-only job token. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT || github.token }}"} }' - name: 'Run Tests' env: TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }} From 830f74c32d2e36650b45aead8e98f6f02fde80e7 Mon Sep 17 00:00:00 2001 From: smarcet Date: Tue, 24 Nov 2026 11:28:10 -0300 Subject: [PATCH 3/5] ci: do not publish the Swagger preview for Dependabot or fork pull requests On a Dependabot pull request the permissions block of pages-preview raises the job token to write, so the preview published output generated while unreviewed dependency code ran. The job now runs only for pull requests opened by a person from a branch of this repository. --- .github/workflows/l5-swagger-generate.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/l5-swagger-generate.yml b/.github/workflows/l5-swagger-generate.yml index 4b7ce2fe..d17ec8a8 100644 --- a/.github/workflows/l5-swagger-generate.yml +++ b/.github/workflows/l5-swagger-generate.yml @@ -101,7 +101,13 @@ jobs: pages-preview: name: Publish Swagger UI to GitHub Pages needs: openapi-generate - if: github.event_name == 'pull_request' + # Only for pull requests that a person opened from a branch of this repository. + # On a Dependabot pull request the permissions below still raise the job token, so + # the preview would publish output generated while unreviewed dependency code ran. + if: >- + github.event_name == 'pull_request' && + github.event.pull_request.user.login != 'dependabot[bot]' && + github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-latest permissions: From a96216b6526845a3b39c24009648b5aabb614663 Mon Sep 17 00:00:00 2001 From: smarcet Date: Tue, 24 Nov 2026 11:34:38 -0300 Subject: [PATCH 4/5] ci: gate the Swagger preview on the author being a user account The condition excluded Dependabot by name, so any other bot account opening a pull request from a branch of this repository would still publish. Bot accounts have the type Bot. --- .github/workflows/l5-swagger-generate.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/l5-swagger-generate.yml b/.github/workflows/l5-swagger-generate.yml index d17ec8a8..46b2144b 100644 --- a/.github/workflows/l5-swagger-generate.yml +++ b/.github/workflows/l5-swagger-generate.yml @@ -104,9 +104,10 @@ jobs: # Only for pull requests that a person opened from a branch of this repository. # On a Dependabot pull request the permissions below still raise the job token, so # the preview would publish output generated while unreviewed dependency code ran. + # Bot accounts, Dependabot included, have the type "Bot". if: >- github.event_name == 'pull_request' && - github.event.pull_request.user.login != 'dependabot[bot]' && + github.event.pull_request.user.type == 'User' && github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-latest From 725c57d087e1ec5b3df833742bea5109f84ea25a Mon Sep 17 00:00:00 2001 From: smarcet Date: Tue, 24 Nov 2026 11:45:05 -0300 Subject: [PATCH 5/5] ci: stop using the PAT secret for composer The job token authenticates the downloads of every locked package: a run with the token alone and the cache disabled downloaded all 197 and passed the tests. The personal access token is no longer handed to code that runs during the install. The nightly workflow changes the same way. --- .github/workflows/l5-swagger-generate.yml | 6 +++--- .github/workflows/nightly_unit_tests.yml | 4 +++- .github/workflows/pull_request_unit_tests.yml | 6 +++--- .github/workflows/push.yml | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/l5-swagger-generate.yml b/.github/workflows/l5-swagger-generate.yml index 46b2144b..074c1658 100644 --- a/.github/workflows/l5-swagger-generate.yml +++ b/.github/workflows/l5-swagger-generate.yml @@ -57,9 +57,9 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - # Dependabot and fork runs do not receive secrets.PAT. An empty token makes - # Composer fail to authenticate, so those runs use the read-only job token. - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT || github.token }}"} }' + # Every locked package comes from a public repository, so the job token is enough + # to authenticate the downloads. Dependabot runs receive no repository secrets. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' - name: Generate OpenAPI docs run: php artisan l5-swagger:generate diff --git a/.github/workflows/nightly_unit_tests.yml b/.github/workflows/nightly_unit_tests.yml index c9b7d6d6..9f8fd50b 100644 --- a/.github/workflows/nightly_unit_tests.yml +++ b/.github/workflows/nightly_unit_tests.yml @@ -58,7 +58,9 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT }}"} }' + # Every locked package comes from a public repository, so the job token is enough + # to authenticate the downloads. Dependabot runs receive no repository secrets. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' - name: 'Run Tests' run: | ./update_doctrine.sh diff --git a/.github/workflows/pull_request_unit_tests.yml b/.github/workflows/pull_request_unit_tests.yml index 902524c0..706c58a1 100644 --- a/.github/workflows/pull_request_unit_tests.yml +++ b/.github/workflows/pull_request_unit_tests.yml @@ -63,9 +63,9 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - # Dependabot and fork runs do not receive secrets.PAT. An empty token makes - # Composer fail to authenticate, so those runs use the read-only job token. - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT || github.token }}"} }' + # Every locked package comes from a public repository, so the job token is enough + # to authenticate the downloads. Dependabot runs receive no repository secrets. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' - name: 'Run Tests' env: TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 7a7ab81b..34400038 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -59,9 +59,9 @@ jobs: - name: Install dependencies uses: "ramsey/composer-install@v3" env: - # Dependabot runs do not receive secrets.PAT. An empty token makes Composer - # fail to authenticate, so those runs use the read-only job token. - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.PAT || github.token }}"} }' + # Every locked package comes from a public repository, so the job token is enough + # to authenticate the downloads. Dependabot runs receive no repository secrets. + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }' - name: 'Run Tests' env: TEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }}