Skip to content

Commit c3001e0

Browse files
authored
chore(ci): improve action security (#4404)
Adding checks for injections with zimzor (not supported by CodeQL ((yet))). <img width="798" alt="image" src="https://github.com/user-attachments/assets/57f1d00e-e949-47f6-9eec-ee7a1e0da5f5" />
1 parent 62de76a commit c3001e0

9 files changed

+103
-12
lines changed

.github/workflows/actions.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Lint GitHub Actions
2+
3+
on:
4+
push:
5+
paths:
6+
- '.github/workflows/*.ya?ml'
7+
branches:
8+
- main
9+
pull_request:
10+
paths:
11+
- '.github/workflows/*.ya?ml'
12+
13+
concurrency:
14+
group: "actionlint-${{ github.ref }}"
15+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
16+
17+
permissions: {}
18+
19+
jobs:
20+
lint:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
steps:
25+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
with:
27+
persist-credentials: false
28+
29+
- name: lint wit zizmor
30+
run: |
31+
pipx install zizmor
32+
zizmor --gh-token ${{ secrets.GITHUB_TOKEN }} --format sarif . > results.sarif || true
33+
34+
- name: Upload SARIF file
35+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
36+
with:
37+
name: results.sarif
38+
path: results.sarif
39+
40+
upload:
41+
needs: lint
42+
runs-on: ubuntu-latest
43+
permissions:
44+
contents: read
45+
security-events: write
46+
steps:
47+
- name: Download SARIF file
48+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
49+
with:
50+
name: results.sarif
51+
path: results.sarif
52+
53+
- name: Upload SARIF file
54+
uses: github/codeql-action/upload-sarif@f6091c0113d1dcf9b98e269ee48e8a7e51b7bdd4 # v3.28.5
55+
with:
56+
sarif_file: results.sarif
57+
category: actions-zizmor

.github/workflows/codeql.yml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
steps:
2727
- name: Checkout repository
2828
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
with:
30+
persist-credentials: false
2931

3032
# Initializes the CodeQL tools for scanning.
3133
- name: Initialize CodeQL

.github/workflows/lambda.yml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525

2626
steps:
2727
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
persist-credentials: false
2830
- name: Install dependencies
2931
run: yarn install --frozen-lockfile
3032
- name: Run prettier

.github/workflows/packer-build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
steps:
3131
- name: "Checkout"
3232
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33+
with:
34+
persist-credentials: false
3335
- name: packer init
3436
run: packer init .
3537
- name: check packer formatting

.github/workflows/release.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
with:
2121
node-version: 22
2222
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
with:
24+
persist-credentials: false
2325
- name: Build dist
2426
working-directory: lambdas
2527
run: yarn install --frozen-lockfile && yarn run test && yarn dist
@@ -50,17 +52,25 @@ jobs:
5052
if: ${{ steps.release.outputs.releases_created == 'true' }}
5153
env:
5254
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
VERSION: ${{ github.event.inputs.version }}
56+
TAG_NAME: ${{ steps.release.outputs.tag_name }}
57+
ATTESTATION_URL: ${{ steps.attest.outputs.attestation-url }}
5358
run: |
54-
gh release view ${{ github.event.inputs.version }} --json body -q '.body' > new-release-notes.md
59+
version="${VERSION}"
60+
tag_name="${TAG_NAME}"
61+
attestation_url="${ATTESTATION_URL}"
62+
gh release view $version --json body -q '.body' > new-release-notes.md
5563
echo "## Attestation" >> new-release-notes.md
56-
echo "Attestation url: ${{ steps.attest.outputs.attestation-url }}" >> new-release-notes.md
64+
echo "Attestation url: $attestation_url" >> new-release-notes.md
5765
echo "Verify the artifacts by running \`gh attest verify <name_of_artifact> --repo ${{ github.repository }}\`" >> new-release-notes.md
58-
gh release edit ${{ steps.release.outputs.tag_name }} -F new-release-notes.md -t ${{ steps.release.outputs.tag_name }}
66+
gh release edit $tag_name -F new-release-notes.md -t $tag_name
5967
- name: Upload release assets
6068
if: ${{ steps.release.outputs.releases_created == 'true' }}
6169
env:
6270
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
TAG_NAME: ${{ steps.release.outputs.tag_name }}
6372
run: |
73+
tag_name="${TAG_NAME}"
6474
for f in $(find . -name '*.zip'); do
65-
gh release upload ${{ steps.release.outputs.tag_name }} $f
75+
gh release upload $tag_name $f
6676
done

.github/workflows/semantic-check.yml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
with:
18+
persist-credentials: false
1719
- uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 # v5.5.3
1820
name: Check PR for Semantic Commit Message
1921
env:

.github/workflows/terraform.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88

99
permissions:
1010
contents: read
11-
pull-requests: write
1211

1312
env:
1413
AWS_REGION: eu-west-1
@@ -24,6 +23,8 @@ jobs:
2423
steps:
2524
- name: "Checkout"
2625
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
with:
27+
persist-credentials: false
2728
- name: "Fake zip files" # Validate will fail if it cannot find the zip files
2829
run: |
2930
touch lambdas/functions/webhook/webhook.zip
@@ -47,7 +48,7 @@ jobs:
4748
run: apk add --no-cache tar
4849
continue-on-error: true
4950
- if: contains(matrix.terraform, '1.5.')
50-
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
51+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
5152
name: Cache TFLint plugin dir
5253
with:
5354
path: ~/.tflint.d/plugins
@@ -90,6 +91,8 @@ jobs:
9091
image: hashicorp/terraform:${{ matrix.terraform }}
9192
steps:
9293
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
94+
with:
95+
persist-credentials: false
9396
- name: terraform init
9497
run: terraform init -get -backend=false -input=false
9598
- if: contains(matrix.terraform, '1.3.')
@@ -106,7 +109,7 @@ jobs:
106109
run: apk add --no-cache tar
107110
continue-on-error: true
108111
- if: contains(matrix.terraform, '1.3.')
109-
uses: actions/cache@v4
112+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
110113
name: Cache TFLint plugin dir
111114
with:
112115
path: ~/.tflint.d/plugins
@@ -145,6 +148,8 @@ jobs:
145148
image: hashicorp/terraform:${{ matrix.terraform }}
146149
steps:
147150
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
151+
with:
152+
persist-credentials: false
148153
- name: terraform init
149154
run: terraform init -get -backend=false -input=false
150155
- if: contains(matrix.terraform, '1.5.')
@@ -161,7 +166,7 @@ jobs:
161166
run: apk add --no-cache tar
162167
continue-on-error: true
163168
- if: contains(matrix.terraform, '1.5.')
164-
uses: actions/cache@v4
169+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
165170
name: Cache TFLint plugin dir
166171
with:
167172
path: ~/.tflint.d/plugins

.github/workflows/update-docs.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ on:
66
- "**/*.md"
77
- ".github/workflows/update-docs.yml"
88

9-
permissions:
10-
contents: write
11-
pull-requests: write
12-
139
jobs:
1410
docs:
1511
name: Auto update terraform docs
1612
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
1716
steps:
1817
- name: Checkout with GITHUB Action token
1918
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2019
with:
2120
token: ${{ secrets.GITHUB_TOKEN }}
21+
persist-credentials: true
2222

2323
# use an app to ensure CI is triggered
2424
- name: Generate TF docs
@@ -55,6 +55,8 @@ jobs:
5555
deploy-pages:
5656
needs: [docs]
5757
runs-on: ubuntu-latest
58+
permissions:
59+
contents: write
5860
steps:
5961
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6062
- name: Configure Git Credentials

.github/zizmor.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rules:
2+
artipacked:
3+
ignore:
4+
# update docs requires token to be persisted
5+
- update-docs.yml:61:9
6+
dangerous-triggers:
7+
ignore:
8+
# semantic check with only a read only token
9+
- semantic-check.yml:2:1

0 commit comments

Comments
 (0)