Skip to content

Commit 205cddc

Browse files
authored
Security: remove possibility of token leak (#462)
* security: do not archive git directory * security: restrict token permissions * security: delete old artifacts that start with build-artifact * security: open action permission only on remove artifact job
1 parent b73d7e8 commit 205cddc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: CI
22

33
on: [push, pull_request]
44

5+
permissions:
6+
contents: read
7+
actions: read
8+
id-token: none
9+
510
jobs:
611
composer:
712
runs-on: ubuntu-latest
@@ -24,7 +29,7 @@ jobs:
2429
php_version: ${{ matrix.php }}
2530

2631
- name: Archive build
27-
run: mkdir /tmp/github-actions/ && tar -cvf /tmp/github-actions/build.tar ./
32+
run: mkdir /tmp/github-actions/ && tar --exclude=".git" -cvf /tmp/github-actions/build.tar ./
2833

2934
- name: Upload build archive for test runners
3035
uses: actions/upload-artifact@v4
@@ -161,12 +166,15 @@ jobs:
161166
remove_old_artifacts:
162167
runs-on: ubuntu-latest
163168

169+
permissions:
170+
actions: write
171+
164172
steps:
165173
- name: Remove old artifacts for prior workflow runs on this repository
166174
env:
167175
GH_TOKEN: ${{ github.token }}
168176
run: |
169-
gh api "/repos/${{ github.repository }}/actions/artifacts?name=build-artifact" | jq ".artifacts[] | select(.name | startswith(\"build-artifact\")) | .id" > artifact-id-list.txt
177+
gh api "/repos/${{ github.repository }}/actions/artifacts" | jq ".artifacts[] | select(.name | startswith(\"build-artifact\")) | .id" > artifact-id-list.txt
170178
while read id
171179
do
172180
echo -n "Deleting artifact ID $id ... "

0 commit comments

Comments
 (0)