Skip to content

Commit ef204f4

Browse files
committed
fix: scope id-token to publish, harden version handling, idempotent calver
- Drop workflow-level id-token: write; only the publish job (which needs OIDC for GCP auth) gets id-token: write. PR builds no longer receive a token they can exchange for cloud creds. - Validate kernel versions against [0-9]+(\.[0-9]+)+ in the matrix job and pass matrix.version to build.sh via env vars instead of inline YAML expression interpolation, so a malicious kernel_versions.txt entry can't shell-inject into the runner. - Calver tag picker now also checks local and remote git tags, not just GH releases, so retries after a partial publish no longer pick a tag that's already been pushed.
1 parent c167397 commit ef204f4

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ on:
55
pull_request:
66

77
permissions:
8-
contents: write
9-
id-token: write
8+
contents: read
109

1110
jobs:
1211
matrix:
1312
runs-on: ubuntu-24.04
13+
permissions:
14+
contents: read
1415
outputs:
1516
build_matrix: ${{ steps.gen.outputs.matrix }}
1617
steps:
@@ -19,11 +20,17 @@ jobs:
1920
run: |
2021
python3 - >> "$GITHUB_OUTPUT" <<'PY'
2122
import json
23+
import re
24+
import sys
25+
VERSION_RE = re.compile(r"^[0-9]+(?:\.[0-9]+)+$")
2226
versions = []
2327
for line in open("kernel_versions.txt").read().splitlines():
2428
v = line.split("#", 1)[0].strip()
25-
if v:
26-
versions.append(v)
29+
if not v:
30+
continue
31+
if not VERSION_RE.match(v):
32+
sys.exit(f"::error::invalid kernel version in kernel_versions.txt: {v!r}")
33+
versions.append(v)
2734
include = []
2835
for v in versions:
2936
include.append({"version": v, "arch": "amd64", "target_arch": "x86_64", "runner": "ubuntu-24.04"})
@@ -38,11 +45,16 @@ jobs:
3845
fail-fast: false
3946
matrix: ${{ fromJson(needs.matrix.outputs.build_matrix) }}
4047
runs-on: ${{ matrix.runner }}
48+
permissions:
49+
contents: read
4150
steps:
4251
- uses: actions/checkout@v4
4352

4453
- name: Build kernel
45-
run: sudo ./build.sh "${{ matrix.version }}" "${{ matrix.target_arch }}"
54+
env:
55+
KERNEL_VERSION: ${{ matrix.version }}
56+
KERNEL_TARGET_ARCH: ${{ matrix.target_arch }}
57+
run: sudo ./build.sh "$KERNEL_VERSION" "$KERNEL_TARGET_ARCH"
4658

4759
- uses: actions/upload-artifact@v4
4860
with:
@@ -54,6 +66,9 @@ jobs:
5466
needs: build
5567
if: github.event_name == 'workflow_dispatch'
5668
runs-on: ubuntu-24.04
69+
permissions:
70+
contents: write
71+
id-token: write
5772
steps:
5873
- uses: actions/checkout@v4
5974
with:
@@ -86,7 +101,9 @@ jobs:
86101
base="$(date -u +%Y.%m.%d)"
87102
tag="$base"
88103
n=0
89-
while gh release view "$tag" >/dev/null 2>&1; do
104+
while gh release view "$tag" >/dev/null 2>&1 \
105+
|| git rev-parse "refs/tags/$tag" >/dev/null 2>&1 \
106+
|| git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null 2>&1; do
90107
n=$((n + 1))
91108
tag="${base}.${n}"
92109
done

0 commit comments

Comments
 (0)