Skip to content

Commit 8224cd1

Browse files
committed
ci: Fix zizmor security findings in GitHub Actions
Signed-off-by: Shubham Bhardwaj <shubbhar@redhat.com>
1 parent 0c827bc commit 8224cd1

7 files changed

Lines changed: 85 additions & 16 deletions

File tree

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "weekly"
7+
cooldown:
8+
default-days: 7
79
labels:
810
- "ok-to-test"
911
- "dependencies"
@@ -22,6 +24,8 @@ updates:
2224
directory: "/"
2325
schedule:
2426
interval: "weekly"
27+
cooldown:
28+
default-days: 7
2529
labels:
2630
- "ok-to-test"
2731
- "dependencies"

.github/workflows/ci.yaml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ defaults:
1212

1313
permissions:
1414
contents: read
15-
checks: write # Used to annotate code in the PR
1615

1716
jobs:
1817
changes:
@@ -24,16 +23,23 @@ jobs:
2423
steps:
2524
- name: Get base depth
2625
id: base-depth
27-
run: echo "base-depth=$(expr ${{ github.event.pull_request.commits }} + 1)" >> $GITHUB_OUTPUT
26+
env:
27+
PR_COMMITS: ${{ github.event.pull_request.commits }}
28+
run: echo "base-depth=$(expr "${PR_COMMITS}" + 1)" >> $GITHUB_OUTPUT
2829
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2930
with:
3031
ref: ${{ github.event.pull_request.head.sha }}
3132
fetch-depth: ${{ steps.base-depth.outputs.base-depth }}
33+
persist-credentials: false
3234
- name: detect
3335
id: detect
36+
env:
37+
GITHUB_BASE_REF_NAME: ${{ github.base_ref }}
38+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
39+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
3440
run: |
35-
git fetch origin ${{ github.base_ref }}
36-
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} | tr ' ' '\n')
41+
git fetch origin "${GITHUB_BASE_REF_NAME}"
42+
CHANGED_FILES=$(git diff --name-only "${BASE_SHA}...${HEAD_SHA}" | tr ' ' '\n')
3743
3844
echo -e "Changed files:\n${CHANGED_FILES}"
3945
@@ -66,6 +72,8 @@ jobs:
6672
if: ${{ needs.changes.outputs.non-docs == 'true' }}
6773
steps:
6874
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
75+
with:
76+
persist-credentials: false
6977
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
7078
with:
7179
go-version-file: "go.mod"
@@ -76,10 +84,14 @@ jobs:
7684
name: lint
7785
runs-on: ubuntu-latest
7886
needs: [changes]
87+
permissions:
88+
contents: read
89+
checks: write # Used by golangci-lint-action to annotate code in the PR
7990
steps:
8091
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
8192
with:
8293
fetch-depth: 0
94+
persist-credentials: false
8395
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
8496
with:
8597
go-version-file: "go.mod"
@@ -113,6 +125,8 @@ jobs:
113125
runs-on: ubuntu-latest
114126
steps:
115127
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
128+
with:
129+
persist-credentials: false
116130
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
117131
with:
118132
go-version-file: "go.mod"
@@ -125,6 +139,8 @@ jobs:
125139
runs-on: ubuntu-latest
126140
steps:
127141
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
142+
with:
143+
persist-credentials: false
128144
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
129145
with:
130146
go-version-file: "go.mod"
@@ -139,6 +155,8 @@ jobs:
139155
KOCACHE: /tmp/ko-cache
140156
steps:
141157
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
158+
with:
159+
persist-credentials: false
142160
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
143161
with:
144162
go-version-file: "go.mod"
@@ -165,14 +183,21 @@ jobs:
165183
if: always()
166184
steps:
167185
- name: Check CI results
186+
env:
187+
BUILD: ${{ needs.build.result }}
188+
LINTING: ${{ needs.linting.result }}
189+
TESTS: ${{ needs.tests.result }}
190+
GENERATED: ${{ needs.generated.result }}
191+
MULTI_ARCH_BUILD: ${{ needs.multi-arch-build.result }}
192+
E2E_TESTS: ${{ needs.e2e-tests.result }}
168193
run: |
169194
results=(
170-
"build=${{ needs.build.result }}"
171-
"linting=${{ needs.linting.result }}"
172-
"tests=${{ needs.tests.result }}"
173-
"generated=${{ needs.generated.result }}"
174-
"multi-arch-build=${{ needs.multi-arch-build.result }}"
175-
"e2e-tests=${{ needs.e2e-tests.result }}"
195+
"build=${BUILD}"
196+
"linting=${LINTING}"
197+
"tests=${TESTS}"
198+
"generated=${GENERATED}"
199+
"multi-arch-build=${MULTI_ARCH_BUILD}"
200+
"e2e-tests=${E2E_TESTS}"
176201
)
177202
failed=0
178203
for r in "${results[@]}"; do

.github/workflows/codeql-analysis.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ on:
2020
schedule:
2121
- cron: '30 20 * * 2'
2222

23+
permissions: {}
24+
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
27+
cancel-in-progress: true
28+
2329
jobs:
2430
analyze:
2531
name: Analyze
2632
runs-on: ubuntu-latest
2733
permissions:
28-
actions: read
34+
actions: read # Required by CodeQL to read workflow information
2935
contents: read
30-
security-events: write
36+
security-events: write # Required to upload CodeQL SARIF results
3137

3238
strategy:
3339
fail-fast: false
@@ -39,6 +45,8 @@ jobs:
3945
steps:
4046
- name: Checkout repository
4147
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
48+
with:
49+
persist-credentials: false
4250

4351
# Initializes the CodeQL tools for scanning.
4452
- name: Initialize CodeQL

.github/workflows/e2e-matrix.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424

2525
steps:
2626
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
27+
with:
28+
persist-credentials: false
2729
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
2830
with:
2931
go-version-file: "go.mod"
@@ -55,7 +57,7 @@ jobs:
5557
run: |
5658
./test/setup-kind.sh \
5759
--registry-url $(echo ${KO_DOCKER_REPO} | cut -d'/' -f 1) \
58-
--cluster-suffix c${{ github.run_id }}.local \
60+
--cluster-suffix "${CLUSTER_DOMAIN}" \
5961
--nodes 3 \
6062
--k8s-version v1.29.x \
6163
--e2e-script ./test/gh-e2e-tests.sh \

.github/workflows/go-coverage.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
name: Go coverage
2727
runs-on: ubuntu-24.04
2828
permissions:
29-
pull-requests: write
29+
pull-requests: write # Required by go-coverage-report to comment on PRs
3030

3131
steps:
3232
- name: Harden runner
@@ -38,6 +38,7 @@ jobs:
3838
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3939
with:
4040
path: ${{ github.workspace }}/src/github.com/tektoncd/triggers
41+
persist-credentials: false
4142

4243
- name: Set up Go
4344
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0

.github/workflows/microshift.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: Integration Tests on microshift
22

33
permissions:
44
contents: read
5-
packages: write
65

76
on:
87
push:
@@ -42,10 +41,12 @@ jobs:
4241
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4342
with:
4443
path: ${{ github.workspace }}/src/github.com/tektoncd/triggers
44+
persist-credentials: false
4545

4646
- name: Set up Go
4747
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
4848
with:
49+
cache: false
4950
cache-dependency-path: "${{ github.workspace }}/src/github.com/tektoncd/triggers/go.sum"
5051
go-version-file: "${{ github.workspace }}/src/github.com/tektoncd/triggers/go.mod"
5152

@@ -88,7 +89,7 @@ jobs:
8889
curl https://infra.tekton.dev/tekton-releases/pipeline/latest/release.yaml | yq 'del(.spec.template.spec.containers[]?.securityContext.runAsUser, .spec.template.spec.containers[]?.securityContext.runAsGroup)' > release
8990
export RELEASE_YAML=$(realpath release)
9091
91-
${{ github.workspace }}/src/github.com/tektoncd/triggers/test/gh-e2e-tests.sh
92+
"${GOPATH}/src/github.com/tektoncd/triggers/test/gh-e2e-tests.sh"
9293
9394
- name: Upload test results
9495
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1

.github/workflows/zizmor.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: GitHub Actions Security Analysis with zizmor
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
permissions: {}
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
zizmor:
17+
name: zizmor
18+
runs-on: ubuntu-latest
19+
permissions:
20+
security-events: write # Required to upload SARIF results
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24+
with:
25+
persist-credentials: false
26+
27+
- name: Run zizmor
28+
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2

0 commit comments

Comments
 (0)