Skip to content

Commit 301bb75

Browse files
authored
Harden CI workflows with Zizmor and SHA version pinning (#230)
* ci: Pin action versions to commit SHAs * ci: Use runner-provided `rustup` over external action * ci: Configure granular workflow permissions * ci: Add zizmor workflow * ci: Format workflows * ci: Correct go version in `tests.yaml` * ci: Remove explicit permissions since repo is public
1 parent a22761c commit 301bb75

3 files changed

Lines changed: 93 additions & 60 deletions

File tree

.github/workflows/single_sdk_tests.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
# in the input. It runs single SDK only tests (e.g all JS clients _or_ all Rust clients, not a mixture).
55
name: "Complement Crypto"
66
run-name: "Running Complement-Crypto"
7-
permissions: read-all
7+
8+
permissions: {}
9+
810
on:
911
workflow_call:
1012
inputs:
@@ -32,7 +34,9 @@ jobs:
3234
# At this stage we don't know which repo we have just checked out. We will reference this repo
3335
# if the workflow uses '.'
3436
- name: Checkout repo
35-
uses: actions/checkout@v3
37+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
38+
with:
39+
persist-credentials: false
3640
- name: Resolve branches
3741
shell: bash
3842
# these env vars will be modified and used in subsequent steps
@@ -104,18 +108,18 @@ jobs:
104108
docker pull mitmproxy/mitmproxy:10.1.5
105109
docker tag ghcr.io/matrix-org/synapse-service:v1.117.0 homeserver:latest
106110
- name: Setup | Go
107-
uses: actions/setup-go@v6
111+
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
108112
with:
109113
go-version: "1.25"
110114
- name: "Install Complement Dependencies"
111115
shell: bash
112116
run: |
113-
go install -v github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
117+
go install -v github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@4c97682ab858d6bbd26fc020e255cb339c9c8119 # v2.5.0
114118
115119
# JS SDK only steps
116120
- name: Setup | Node.js LTS
117121
if: ${{ inputs.use_js_sdk != '' }}
118-
uses: actions/setup-node@v3
122+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
119123
with:
120124
node-version: "lts/*"
121125
- name: "Install JS SDK"
@@ -128,9 +132,9 @@ jobs:
128132
# which we then pass to rebuild_rust_sdk.sh
129133
- name: Setup | Rust
130134
if: ${{ inputs.use_rust_sdk != '' }}
131-
uses: dtolnay/rust-toolchain@stable
132-
with:
133-
toolchain: stable
135+
run: |
136+
rustup toolchain install stable
137+
rustup default stable
134138
- name: "Download Rust SDK" # no need to download rust SDK if we are using the local checkout.
135139
if: ${{ inputs.use_rust_sdk != '' && inputs.use_rust_sdk != '.'}}
136140
run: |
@@ -182,7 +186,7 @@ jobs:
182186
RUST_SDK_LIB_RELATIVE: ${{ inputs.use_rust_sdk == '.' && '/target/debug' || '/complement-crypto/rust-sdk/target/debug'}}
183187

184188
- name: Upload logs
185-
uses: actions/upload-artifact@v4
189+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
186190
if: ${{ failure() }}
187191
with:
188192
name: Logs - ${{ inputs.use_js_sdk != '' && 'jssdk' || 'rust'}}

.github/workflows/tests.yaml

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,68 @@
11
name: Tests
22

3+
permissions: {}
4+
35
on:
46
push:
5-
branches: [ 'main' ]
7+
branches: ["main"]
68
pull_request:
79
workflow_dispatch:
810

911
jobs:
1012
check-signoff:
1113
if: "github.event_name == 'pull_request'"
12-
uses: "matrix-org/backend-meta/.github/workflows/sign-off.yml@v2"
14+
uses: matrix-org/backend-meta/.github/workflows/sign-off.yml@18beaf3c8e536108bd04d18e6c3dc40ba3931e28 # v2
1315

1416
js-latest-main:
1517
name: Tests (JS only, latest)
1618
uses: ./.github/workflows/single_sdk_tests.yml
1719
with:
18-
use_js_sdk: 'MATCHING_BRANCH'
19-
use_complement_crypto: '.'
20+
use_js_sdk: "MATCHING_BRANCH"
21+
use_complement_crypto: "."
2022

2123
rust-latest-main:
2224
name: Tests (Rust only, latest)
2325
uses: ./.github/workflows/single_sdk_tests.yml
2426
with:
25-
use_rust_sdk: 'MATCHING_BRANCH'
26-
use_complement_crypto: '.'
27+
use_rust_sdk: "MATCHING_BRANCH"
28+
use_complement_crypto: "."
2729

2830
complement:
2931
name: Tests
3032
runs-on: ubuntu-22.04
3133
steps:
32-
- uses: actions/checkout@v3 # Checkout crypto tests
34+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
35+
with:
36+
persist-credentials: false
3337

3438
# Install Node, Go and Rust, along with gotestfmt
3539
- name: Setup | Node.js LTS
36-
uses: actions/setup-node@v3
40+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
3741
with:
3842
node-version: "lts/*"
39-
cache: 'yarn'
43+
cache: "yarn"
4044
cache-dependency-path: "internal/api/js/js-sdk/yarn.lock"
4145
- name: Setup | Go
42-
uses: actions/setup-go@v4
46+
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
4347
with:
44-
go-version: '1.21'
48+
go-version: "1.25"
4549
- name: Setup | Rust
46-
uses: dtolnay/rust-toolchain@stable
47-
with:
48-
toolchain: stable
50+
run: |
51+
rustup toolchain install stable
52+
rustup default stable
4953
- name: Checkout matrix-rust-sdk
5054
run: |
5155
BRANCH=$(./.github/workflows/resolve_branch.sh matrix-org/matrix-rust-sdk)
5256
mkdir rust-sdk
5357
wget -O archive.tar.gz "https://github.com/matrix-org/matrix-rust-sdk/archive/$BRANCH.tar.gz"
5458
zcat < archive.tar.gz | git get-tar-commit-id # useful for debugging
5559
tar -xz --strip-components=1 -C rust-sdk < archive.tar.gz
56-
- uses: Swatinem/rust-cache@v2
60+
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
5761
with:
5862
workspaces: "rust-sdk"
5963
- name: "Install Complement Dependencies"
6064
run: |
61-
go install -v github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
65+
go install -v github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@4c97682ab858d6bbd26fc020e255cb339c9c8119 # v2.5.0
6266
6367
# Install whatever version of the JS SDK is in package.json
6468
- name: Build JS SDK
@@ -81,38 +85,38 @@ jobs:
8185
docker tag ghcr.io/matrix-org/synapse-service:v1.117.0 homeserver:latest
8286
8387
# Build homeserver image, honouring branch names
84-
#- name: "Checkout corresponding Synapse branch"
85-
#shell: bash
86-
#run: |
87-
#mkdir -p homeserver
88-
#
89-
## Attempt to use the version of the homeserver which best matches the
90-
## current build.
91-
##
92-
## 1. If we are not on complement's default branch, check if there's a
93-
## similarly named branch (GITHUB_HEAD_REF for pull requests,
94-
## otherwise GITHUB_REF).
95-
## 2. otherwise, use the default homeserver branch ("HEAD")
96-
#
97-
#for BRANCH_NAME in "$GITHUB_HEAD_REF" "${GITHUB_REF#refs/heads/}" "HEAD"; do
98-
## Skip empty branch names, merge commits, and our default branch.
99-
## (If we are on complement's default branch, we want to fall through to the HS's default branch
100-
## rather than using the HS's 'master'/'main').
101-
#case "$BRANCH_NAME" in
102-
#"" | refs/pull/* | main | master)
103-
#continue
104-
#;;
105-
#esac
106-
#(wget -O - "https://github.com/matrix-org/synapse/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C homeserver) && break
107-
#done
108-
## Build the base Synapse dockerfile and then build a Complement-specific image from that base.
109-
#- run: |
110-
#docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile .
111-
#docker build -t matrixdotorg/synapse-workers:latest -f docker/Dockerfile-workers .
112-
#docker build -t homeserver -f docker/complement/Dockerfile docker/complement
113-
#working-directory: homeserver
114-
#env:
115-
#DOCKER_BUILDKIT: 1
88+
#- name: "Checkout corresponding Synapse branch"
89+
#shell: bash
90+
#run: |
91+
#mkdir -p homeserver
92+
#
93+
## Attempt to use the version of the homeserver which best matches the
94+
## current build.
95+
##
96+
## 1. If we are not on complement's default branch, check if there's a
97+
## similarly named branch (GITHUB_HEAD_REF for pull requests,
98+
## otherwise GITHUB_REF).
99+
## 2. otherwise, use the default homeserver branch ("HEAD")
100+
#
101+
#for BRANCH_NAME in "$GITHUB_HEAD_REF" "${GITHUB_REF#refs/heads/}" "HEAD"; do
102+
## Skip empty branch names, merge commits, and our default branch.
103+
## (If we are on complement's default branch, we want to fall through to the HS's default branch
104+
## rather than using the HS's 'master'/'main').
105+
#case "$BRANCH_NAME" in
106+
#"" | refs/pull/* | main | master)
107+
#continue
108+
#;;
109+
#esac
110+
#(wget -O - "https://github.com/matrix-org/synapse/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C homeserver) && break
111+
#done
112+
## Build the base Synapse dockerfile and then build a Complement-specific image from that base.
113+
#- run: |
114+
#docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile .
115+
#docker build -t matrixdotorg/synapse-workers:latest -f docker/Dockerfile-workers .
116+
#docker build -t homeserver -f docker/complement/Dockerfile docker/complement
117+
#working-directory: homeserver
118+
#env:
119+
#DOCKER_BUILDKIT: 1
116120
- name: "Run Complement-Crypto unit tests"
117121
env:
118122
COMPLEMENT_BASE_IMAGE: homeserver
@@ -161,10 +165,10 @@ jobs:
161165
DOCKER_BUILDKIT: 1
162166
163167
- name: Upload logs
164-
uses: actions/upload-artifact@v4
168+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
165169
if: ${{ always() }} # do this even if the tests fail
166170
with:
167171
name: Logs - ${{ job.status }}
168172
path: |
169-
./**/logs/*
170-
./**/mitm.dump
173+
./**/logs/*
174+
./**/mitm.dump

.github/workflows/zizmor.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Analyse workflows with zizmor
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
permissions: {}
10+
11+
jobs:
12+
zizmor:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
security-events: write
16+
contents: read
17+
actions: read
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
with:
22+
persist-credentials: false
23+
24+
- name: Run zizmor
25+
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2

0 commit comments

Comments
 (0)