Skip to content

Commit 23eee4f

Browse files
committed
Use environments to protect CI
1 parent 3a36643 commit 23eee4f

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
name: CI
2-
# SECURITY NOTE: This workflow uses pull_request_target which has access to secrets.
3-
# This is needed because tests require access to external services with credentials.
4-
# `pull_request_target` will always run without manual approval, even if "Require approval for all external contributors" is enabled in the repo settings.
5-
# Therefore we implement a "safe to test" label that must be manually added once we have checked that the diff is safe.
6-
# For PRs from forks, secrets are only provided when the "safe to test" label is present.
7-
# This allows maintainers to safely test external contributions while preventing
8-
# malicious actors from accessing secrets.
2+
# SECURITY: Uses environment protection for external PRs instead of unsafe "safe to test" labels.
3+
# Environment protection provides secure manual approval tied to specific commits,
4+
# eliminating race conditions and ensuring maintainer review before secrets access.
95
on:
106
push:
117
branches: [main]
128
paths-ignore:
139
- "**.md"
1410
- ".changeset/**"
1511
pull_request_target:
16-
types: [opened, synchronize, reopened, labeled]
12+
types: [opened, synchronize, reopened]
1713
paths-ignore:
1814
- "**.md"
1915
- ".changeset/**"
@@ -25,26 +21,29 @@ on:
2521
concurrency: ${{ github.workflow }}--${{ github.ref }}
2622

2723
permissions:
24+
contents: read
2825
pull-requests: write
2926

3027
jobs:
3128
main:
3229
name: Node.js 20
3330
runs-on: ubuntu-latest
34-
# Only run tests with secrets if:
35-
# 1. This is a push to main, OR
36-
# 2. PR is from the same repository (trusted), OR
37-
# 3. PR has the "safe to test" label (maintainer approved)
31+
# SECURITY: Use environment protection for external contributors
32+
environment: ${{ github.event.pull_request.head.repo.full_name != github.repository && 'external-testing' || '' }}
33+
# Run tests with secrets for:
34+
# 1. Push to main (trusted), OR
35+
# 2. PR from same repository (trusted)
36+
# For external PRs: environment protection requires manual approval
3837
if: |
39-
github.event_name == 'push' ||
40-
github.event.pull_request.head.repo.full_name == github.repository ||
41-
contains(github.event.pull_request.labels.*.name, 'safe to test')
38+
github.event_name == 'push' ||
39+
github.event.pull_request.head.repo.full_name == github.repository
4240
4341
steps:
4442
- name: Checkout sources
4543
uses: actions/checkout@v4
4644
with:
47-
ref: ${{ github.event.pull_request.head.sha || github.sha }}
45+
# SECURITY: For external PRs, only checkout trusted base branch
46+
ref: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.sha || github.sha }}
4847

4948
- name: Decrypt keyfile
5049
run: ./.github/scripts/decrypt_secret.sh

bb.test

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)