Skip to content

Commit 5ab8374

Browse files
authored
chore(ci): harden ci + harden default workflow templates + pin actions on hash (#11676)
* lower permissions packages codeql * scope permissions, test.yml and test-isolate.yml * set default permissions * restrict permissions: nix.yml * bump deps * pin deps: test.yml * avoid any caching for releases, improve string handling * avoid writing to GITHUB_ENV * harden nix.yml * pin deps nextest, harden * pin deps * restore matrix.flags * add dependabot * pin dep * harden default workflow template * unpin setup-node, nit * rescope to minimal permissions * fix workflow * grant docker-publish workflow the permissions it requires * do not cache in docker-publish * use printf in docker-publish, revert shell defaulting in release.yml
1 parent 33df467 commit 5ab8374

File tree

14 files changed

+263
-118
lines changed

14 files changed

+263
-118
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/benchmarks.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Foundry Benchmarks
22

3+
permissions: {}
4+
35
on:
46
workflow_dispatch:
57
inputs:
@@ -18,10 +20,6 @@ on:
1820
type: string
1921
default: "ithacaxyz/account:v0.3.2,Vectorized/solady:v0.1.22"
2022

21-
permissions:
22-
contents: write
23-
pull-requests: write
24-
2523
env:
2624
ITHACAXYZ_ACCOUNT: "ithacaxyz/account:v0.3.2"
2725
VECTORIZED_SOLADY: "Vectorized/solady:v0.1.22"
@@ -31,36 +29,43 @@ jobs:
3129
run-benchmarks:
3230
name: Run All Benchmarks
3331
runs-on: foundry-runner
32+
permissions:
33+
contents: write
3434
steps:
3535
- name: Checkout repository
3636
uses: actions/checkout@v5
37+
with:
38+
persist-credentials: false
3739

3840
- name: Install build dependencies
3941
run: |
4042
sudo apt-get update
4143
sudo apt-get install -y build-essential pkg-config
4244
4345
- name: Setup Rust toolchain
44-
uses: dtolnay/rust-toolchain@stable
46+
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # master
47+
with:
48+
toolchain: stable
4549

4650
- name: Cache Rust dependencies
47-
uses: Swatinem/rust-cache@v2
51+
uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2
4852
with:
4953
workspaces: |
5054
./
5155
5256
- name: Setup Foundry
5357
env:
5458
FOUNDRY_DIR: ${{ github.workspace }}/.foundry
59+
GITHUB_WORKSPACE: ${{ github.workspace }}
5560
run: |
5661
./.github/scripts/setup-foundryup.sh
57-
echo "${{ github.workspace }}/.foundry/bin" >> $GITHUB_PATH
62+
printf '%s\n' "$GITHUB_WORKSPACE/.foundry/bin" >> "$GITHUB_PATH"
5863
5964
- name: Build benchmark binary
6065
run: cargo build --release --bin foundry-bench
6166

6267
- name: Setup Node.js
63-
uses: actions/setup-node@v4
68+
uses: actions/setup-node@v5
6469
with:
6570
node-version: "24"
6671

@@ -151,9 +156,14 @@ jobs:
151156
name: Publish Results
152157
needs: run-benchmarks
153158
runs-on: foundry-runner
159+
permissions:
160+
contents: write
161+
pull-requests: write
154162
steps:
155163
- name: Checkout repository
156164
uses: actions/checkout@v5
165+
with:
166+
persist-credentials: false
157167

158168
- name: Download benchmark results
159169
uses: actions/download-artifact@v4

.github/workflows/bump-forge-std.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@
22

33
name: bump-forge-std
44

5+
permissions: {}
6+
57
on:
68
schedule:
7-
- cron: "0 0 * * *"
8-
workflow_dispatch:
9+
- cron: "0 0 * * *" # Run daily at midnight UTC
10+
workflow_dispatch: # Needed so we can run it manually
911

1012
jobs:
1113
update-tag:
1214
name: update forge-std tag
1315
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
pull-requests: write
1419
steps:
1520
- uses: actions/checkout@v5
21+
with:
22+
persist-credentials: false
1623
- name: Fetch and update forge-std tag
1724
run: curl 'https://api.github.com/repos/foundry-rs/forge-std/tags' | jq '.[0].commit.sha' -jr > testdata/forge-std-rev
1825
- name: Create pull request
19-
uses: peter-evans/create-pull-request@v5
26+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7
2027
with:
2128
commit-message: "chore: bump forge-std version used for tests"
2229
title: "chore(tests): bump forge-std version"

.github/workflows/codeql.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: CodeQL
22

3+
permissions: {}
4+
35
on:
46
push:
57
branches: ["master"]
@@ -18,10 +20,9 @@ jobs:
1820
name: Analyze (${{ matrix.language }})
1921
runs-on: ubuntu-latest
2022
permissions:
23+
contents: read
2124
security-events: write
22-
packages: read
2325
actions: read
24-
contents: read
2526

2627
strategy:
2728
fail-fast: false
@@ -33,6 +34,8 @@ jobs:
3334
steps:
3435
- name: Checkout repository
3536
uses: actions/checkout@v5
37+
with:
38+
persist-credentials: false
3639

3740
- name: Initialize CodeQL
3841
uses: github/codeql-action/init@v3

.github/workflows/dependencies.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22

33
name: dependencies
44

5+
permissions: {}
6+
57
on:
68
schedule:
7-
# Run weekly
8-
- cron: "0 0 * * SUN"
9-
workflow_dispatch:
10-
# Needed so we can run it manually
11-
12-
permissions:
13-
contents: write
14-
pull-requests: write
9+
- cron: "0 0 * * SUN" # Run weekly on Sundays at midnight UTC
10+
workflow_dispatch: # Needed so we can run it manually
1511

1612
jobs:
1713
update:
18-
uses: ithacaxyz/ci/.github/workflows/cargo-update-pr.yml@main
14+
uses: ithacaxyz/ci/.github/workflows/cargo-update-pr.yml@9c8d0dc20e7ad02455d3fdab2378a05f29907630 # main
15+
permissions:
16+
contents: write
17+
pull-requests: write
1918
secrets:
2019
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/docker-publish.yml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: docker
22

3+
permissions: {}
4+
35
on:
46
# Trigger without any parameters a proactive rebuild
57
workflow_dispatch: {}
@@ -19,16 +21,17 @@ jobs:
1921
name: build and push
2022
runs-on: Linux-22.04
2123
permissions:
24+
contents: read
2225
id-token: write
2326
packages: write
24-
contents: read
2527
timeout-minutes: 120
2628
steps:
2729
- uses: actions/checkout@v5
28-
- uses: dtolnay/rust-toolchain@stable
29-
- uses: Swatinem/rust-cache@v2
3030
with:
31-
cache-on-failure: true
31+
persist-credentials: false
32+
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # master
33+
with:
34+
toolchain: stable
3235
- name: Install gcc aarch64
3336
id: aarch_64_setup
3437
run: |
@@ -38,7 +41,7 @@ jobs:
3841
- name: Login into registry ${{ env.REGISTRY }}
3942
# Ensure this doesn't trigger on PR's
4043
if: github.event_name != 'pull_request'
41-
uses: docker/login-action@v2
44+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3
4245
with:
4346
registry: ${{ env.REGISTRY }}
4447
username: ${{ github.actor }}
@@ -48,7 +51,7 @@ jobs:
4851
# https://github.com/docker/metadata-action
4952
- name: Extract Docker metadata
5053
id: meta
51-
uses: docker/metadata-action@v4
54+
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # v5
5255
with:
5356
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5457

@@ -59,22 +62,22 @@ jobs:
5962
- name: Finalize Docker Metadata
6063
id: docker_tagging
6164
run: |
62-
if [[ "${{ github.event_name }}" == 'schedule' ]]; then
63-
echo "cron trigger, assigning nightly tag"
64-
echo "docker_tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly-${GITHUB_SHA}" >> $GITHUB_OUTPUT
65-
elif [[ "${GITHUB_REF##*/}" == "main" ]] || [[ ${GITHUB_REF##*/} == "master" ]]; then
66-
echo "manual trigger from master/main branch, assigning latest tag"
67-
echo "docker_tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT
65+
if [[ "${{ github.event_name }}" == "schedule" ]]; then
66+
printf "cron trigger, assigning nightly tag\n"
67+
printf "docker_tags=%s/%s:nightly,%s/%s:nightly-%s\n" "${{ env.REGISTRY }}" "${{ env.IMAGE_NAME }}" "${{ env.REGISTRY }}" "${{ env.IMAGE_NAME }}" "$GITHUB_SHA" >> "$GITHUB_OUTPUT"
68+
elif [[ "${GITHUB_REF##*/}" == "main" ]] || [[ "${GITHUB_REF##*/}" == "master" ]]; then
69+
printf "manual trigger from master/main branch, assigning latest tag\n"
70+
printf "docker_tags=%s/%s:%s,%s/%s:latest\n" "${{ env.REGISTRY }}" "${{ env.IMAGE_NAME }}" "${GITHUB_REF##*/}" "${{ env.REGISTRY }}" "${{ env.IMAGE_NAME }}" >> "$GITHUB_OUTPUT"
6871
else
69-
echo "Neither scheduled nor manual release from main branch. Just tagging as branch name"
70-
echo "docker_tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
72+
printf "Neither scheduled nor manual release from main branch. Just tagging as branch name\n"
73+
printf "docker_tags=%s/%s:%s\n" "${{ env.REGISTRY }}" "${{ env.IMAGE_NAME }}" "${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT"
7174
fi
7275
7376
# Log docker metadata to explicitly know what is being pushed
7477
- name: Inspect Docker Metadata
7578
run: |
76-
echo "TAGS -> ${{ steps.docker_tagging.outputs.docker_tags }}"
77-
echo "LABELS -> ${{ steps.meta.outputs.labels }}"
79+
printf "TAGS -> %s\n" "${{ steps.docker_tagging.outputs.docker_tags }}"
80+
printf "LABELS -> %s\n" "${{ steps.meta.outputs.labels }}"
7881
7982
- name: Build and push foundry image
8083
run: make DOCKER_IMAGE_NAME=${{ steps.docker_tagging.outputs.docker_tags }} CARGO_TAG_NAME=${{ inputs.tag_name }} PROFILE=maxperf docker-build-push

.github/workflows/nextest.yml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
name: nextest
44

5+
permissions: {}
6+
57
on:
68
workflow_call:
79
inputs:
@@ -21,27 +23,34 @@ jobs:
2123
matrices:
2224
name: build matrices
2325
runs-on: ubuntu-latest
26+
permissions:
27+
contents: read
2428
outputs:
2529
test-matrix: ${{ steps.gen.outputs.test-matrix }}
2630
steps:
2731
- uses: actions/checkout@v5
28-
- uses: actions/setup-python@v4
32+
with:
33+
persist-credentials: false
34+
- uses: actions/setup-python@v6
2935
with:
3036
python-version: "3.11"
3137
- name: Generate matrices
3238
id: gen
3339
env:
3440
EVENT_NAME: ${{ github.event_name }}
3541
PROFILE: ${{ inputs.profile }}
42+
shell: bash
3643
run: |
3744
output=$(python3 .github/scripts/matrices.py)
38-
echo "::debug::test-matrix=$output"
39-
echo "test-matrix=$output" >> $GITHUB_OUTPUT
45+
printf '::debug::test-matrix=%s\n' "$output"
46+
printf 'test-matrix=%s\n' "$output" >> "$GITHUB_OUTPUT"
4047
4148
test:
4249
name: test ${{ matrix.name }}
4350
runs-on: ${{ matrix.runner_label }}
4451
timeout-minutes: 60
52+
permissions:
53+
contents: read
4554
needs: matrices
4655
strategy:
4756
fail-fast: false
@@ -50,24 +59,29 @@ jobs:
5059
CARGO_PROFILE_DEV_DEBUG: 0
5160
steps:
5261
- uses: actions/checkout@v5
53-
- uses: dtolnay/rust-toolchain@stable
5462
with:
63+
persist-credentials: false
64+
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # master
65+
with:
66+
toolchain: stable
5567
target: ${{ matrix.target }}
56-
- uses: taiki-e/install-action@nextest
68+
- uses: taiki-e/install-action@e5f8d33e7166e0491b2ab4ff0567cc6cd6772737 # v2
69+
with:
70+
tool: nextest
5771

5872
# External tests dependencies
5973
- name: Setup Node.js
6074
if: contains(matrix.name, 'external')
61-
uses: actions/setup-node@v4
75+
uses: actions/setup-node@v5
6276
with:
6377
node-version: 24
6478
- name: Install Bun
6579
if: contains(matrix.name, 'external') && !contains(matrix.runner_label, 'windows')
66-
uses: oven-sh/setup-bun@v1
80+
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2
6781
with:
6882
bun-version: latest
6983
- name: Setup Python
70-
uses: actions/setup-python@v5
84+
uses: actions/setup-python@v6
7185
with:
7286
python-version: 3.11
7387
- name: Install Vyper
@@ -81,7 +95,7 @@ jobs:
8195
~/.foundry/cache
8296
~/.config/.foundry/cache
8397
key: rpc-cache-${{ hashFiles('crates/forge/tests/rpc-cache-keyfile') }}
84-
- uses: Swatinem/rust-cache@v2
98+
- uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2
8599
with:
86100
cache-on-failure: true
87101
- name: Setup Git config

.github/workflows/nix.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: nix
22

3+
permissions: {}
4+
35
on:
46
schedule:
5-
# Run weekly
6-
- cron: "0 0 * * SUN"
7-
workflow_dispatch:
8-
# Needed so we can run it manually
7+
- cron: "0 0 * * SUN" # Run weekly on Sundays at midnight UTC
8+
workflow_dispatch: # Needed so we can run it manually
99

1010
concurrency:
1111
group: ${{ github.workflow }}-${{ github.ref }}
@@ -15,10 +15,15 @@ jobs:
1515
# Opens a PR with an updated flake.lock file
1616
update:
1717
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
pull-requests: write
1821
steps:
19-
- uses: DeterminateSystems/determinate-nix-action@v3
22+
- uses: DeterminateSystems/determinate-nix-action@dbda91f6efef3ee627f56175120aa9543687d830 # v3
2023
- uses: actions/checkout@v5
21-
- uses: DeterminateSystems/update-flake-lock@main
24+
with:
25+
persist-credentials: false
26+
- uses: DeterminateSystems/update-flake-lock@4d443398067153ddd6191a9d9c89533f9a100c26 # main
2227
with:
2328
pr-title: "Update flake.lock"
2429
pr-labels: |
@@ -30,9 +35,13 @@ jobs:
3035
matrix:
3136
runs-on: [ubuntu-latest, macos-latest]
3237
runs-on: ${{ matrix.runs-on }}
38+
permissions:
39+
contents: read
3340
steps:
34-
- uses: DeterminateSystems/determinate-nix-action@v3
41+
- uses: DeterminateSystems/determinate-nix-action@dbda91f6efef3ee627f56175120aa9543687d830 # v3
3542
- uses: actions/checkout@v5
43+
with:
44+
persist-credentials: false
3645

3746
- name: Update flake.lock
3847
run: nix flake update

0 commit comments

Comments
 (0)