Skip to content

Commit 7e6eda6

Browse files
committed
Security changes to workflows to ensure only trusted builds run on self-hosted runner
1 parent a1235f0 commit 7e6eda6

5 files changed

Lines changed: 18 additions & 6 deletions

File tree

.github/workflows/allowlistchecker.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ permissions:
2727
contents: read
2828
jobs:
2929
asf-allowlist-check:
30-
runs-on: ubuntu-latest
30+
# Trusted sources on our own runner; fork PRs on the hosted runner.
31+
runs-on: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && 'self-hosted' || 'ubuntu-latest' }}
3132
steps:
3233
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3334
with:

.github/workflows/analyze.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ env:
1616

1717
jobs:
1818
analyze:
19-
runs-on: ubuntu-latest
19+
# Trusted sources on our own runner; fork PRs on the hosted runner.
20+
runs-on: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && 'self-hosted' || 'ubuntu-latest' }}
2021
strategy:
2122
fail-fast: false
2223
matrix:

.github/workflows/build.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [altera, arm, main, sbp, tertia]
66
pull_request:
7-
branches: [main]
7+
branches: [arm, main]
88
workflow_dispatch:
99

1010
permissions:
@@ -15,7 +15,15 @@ env:
1515

1616
jobs:
1717
test:
18-
runs-on: ubuntu-latest
18+
# Run on our own runner for trusted sources (push/dispatch, or a same-repo
19+
# PR); fork PRs fall back to the hosted runner so they never touch it.
20+
runs-on: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && 'self-hosted' || 'ubuntu-latest' }}
21+
# Skip same-repo PRs from branches push already built - no point building the
22+
# same commit twice.
23+
if: >-
24+
github.event_name != 'pull_request' ||
25+
github.event.pull_request.head.repo.full_name != github.repository ||
26+
!contains(fromJSON('["altera", "arm", "main", "sbp", "tertia"]'), github.event.pull_request.head.ref)
1927
strategy:
2028
fail-fast: false
2129
matrix:

.github/workflows/codeql.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ on:
1212
jobs:
1313
analyze:
1414
name: Analyze
15-
runs-on: ubuntu-latest
15+
# Trusted sources on our own runner; fork PRs on the hosted runner.
16+
runs-on: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && 'self-hosted' || 'ubuntu-latest' }}
1617

1718
permissions:
1819
actions: read

.github/workflows/generatesbom.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ permissions:
1111

1212
jobs:
1313
generate-sbom:
14-
runs-on: ubuntu-latest
14+
# Only runs on push to main / dispatch, so always trusted - use our runner.
15+
runs-on: self-hosted
1516
steps:
1617
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
1718
with:

0 commit comments

Comments
 (0)