Skip to content

Commit 00f8c96

Browse files
committed
fix: safeguard from deploy on external PRs
1 parent 1531e62 commit 00f8c96

1 file changed

Lines changed: 35 additions & 14 deletions

File tree

.github/workflows/deploy-preview.yaml

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,51 @@
11
name: Deploy Preview Environment
22

33
on:
4-
pull_request_target: # zizmor: ignore[dangerous-triggers] # We have a check disabling external forks.
4+
pull_request_target: # zizmor: ignore[dangerous-triggers] - Mitigated with label-based approval
5+
types: [labeled, synchronize, opened, reopened]
56
branches:
67
- main
78
paths: ['examples/homepage/**', 'packages/vechain-kit/**', 'yarn.lock']
89

910
permissions:
1011
contents: read
11-
id-token: write
12-
pull-requests: write
1312

1413
jobs:
14+
# Job 1: Post instruction comment for external PRs
15+
comment-external-pr:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
pull-requests: write
19+
if: |
20+
github.event.pull_request.head.repo.full_name != github.repository &&
21+
github.event.action == 'opened'
22+
steps:
23+
- name: Comment on external PR
24+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
25+
with:
26+
issue-number: ${{ github.event.pull_request.number }}
27+
body: |
28+
## 👋 Thanks for your contribution!
29+
30+
Since this PR comes from a forked repository, preview deployment requires approval from a maintainer for security reasons.
31+
32+
**Next steps:**
33+
1. A maintainer will review your code
34+
2. If approved, they'll add the `safe-to-deploy` label to trigger deployment
35+
3. **After each new commit**, the maintainer will need to remove and re-add the label for security
36+
37+
This ensures every version of the code is explicitly reviewed before deployment. Thank you for your patience! 🙏
38+
39+
# Job 2: Deploy (runs for internal PRs OR when external PR gets labeled)
1540
deploy:
1641
runs-on: ubuntu-latest
42+
permissions:
43+
id-token: write
44+
pull-requests: write
45+
# Security gate: Only run when 'safe-to-deploy' label is ADDED OR from internal branch
46+
if: |
47+
(github.event.label.name == 'safe-to-deploy') ||
48+
(github.event.pull_request.head.repo.full_name == github.repository)
1749
env:
1850
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID }}
1951
NEXT_PUBLIC_PRIVY_APP_ID: ${{ secrets.NEXT_PUBLIC_PRIVY_APP_ID }}
@@ -24,16 +56,6 @@ jobs:
2456
AWS_REGION: eu-west-1
2557
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
2658
steps:
27-
- name: Security - Block external forks
28-
run: |
29-
if [ "$REPO_FULL_NAME" != "${{ github.repository }}" ]; then
30-
echo "::error::Security Policy: PRs from forked repositories cannot run this workflow due to secret access requirements."
31-
echo "::error::VeChain Team Members: Please create branches in the main repository instead of forking."
32-
exit 1
33-
fi
34-
env:
35-
REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
36-
3759
- name: Checkout
3860
uses: actions/checkout@v4
3961
with:
@@ -76,7 +98,6 @@ jobs:
7698
AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_PREVIEW_CLOUDFRONT_DISTRIBUTION_ID }} --paths '/' '/*'
7799
78100
- name: Create Deployment Comment
79-
if: github.event.action == 'opened' || github.event.action == 'reopened'
80101
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
81102
with:
82103
issue-number: ${{ github.event.pull_request.number }}

0 commit comments

Comments
 (0)