Skip to content

Commit 5d9f443

Browse files
committed
fix(OVH): add minimum approval logic to prevent abuse
1 parent 6705cfd commit 5d9f443

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

.github/workflows/deploy.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,37 @@ on:
99
workflow_dispatch:
1010

1111
jobs:
12+
check-approval:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
approved: ${{ steps.check.outputs.approved }}
16+
steps:
17+
- id: check
18+
env:
19+
IS_PUSH_OR_DISPATCH: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) }}
20+
AUTHOR_TRUSTED: ${{ contains(fromJSON('["MEMBER","OWNER","COLLABORATOR","CONTRIBUTOR"]'), github.event.pull_request.author_association) }}
21+
HAS_APPROVAL_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'preview-approved') }}
22+
run: |
23+
if [ "$IS_PUSH_OR_DISPATCH" = "true" ] || [ "$AUTHOR_TRUSTED" = "true" ] || [ "$HAS_APPROVAL_LABEL" = "true" ]; then
24+
echo "approved=true" >> "$GITHUB_OUTPUT"
25+
else
26+
echo "approved=false" >> "$GITHUB_OUTPUT"
27+
fi
28+
1229
deploy:
13-
if: github.event_name == 'push' || (github.event.action != 'closed' && github.event.action != 'labeled')
30+
needs: [check-approval]
31+
if: |
32+
github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (
33+
github.event.action != 'closed' &&
34+
(github.event.action != 'labeled' || github.event.label.name == 'preview-approved')
35+
)
1436
uses: ./.github/workflows/ovh.yaml
1537
with:
1638
environment_name: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && 'production' || format('pull/{0}', github.event.pull_request.number) }}
1739
url: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && format('https://{0}', vars.MAIN_WEBSITE) || format('https://{0}/pr/{1}', vars.PREVIEW_WEBSITE, github.event.pull_request.number) }}
1840
target: ${{ contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && 'www' || format('pulls/pr/{0}', github.event.pull_request.number) }}
41+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
42+
approval_required: ${{ needs.check-approval.outputs.approved == 'false' }}
1943
action: deploy
2044
secrets: inherit
2145

.github/workflows/ovh.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ on:
1717
required: false
1818
type: string
1919
default: 'deploy' # Or 'teardown'
20+
ref:
21+
required: false
22+
type: string
23+
approval_required:
24+
required: false
25+
type: boolean
26+
default: false
2027
secrets:
2128
OVH_USERNAME:
2229
required: true
@@ -34,6 +41,11 @@ jobs:
3441
name: ${{ inputs.environment_name }}
3542
url: ${{ inputs.url }}
3643
steps:
44+
- name: Require maintainer approval
45+
if: ${{ inputs.action != 'teardown' && inputs.approval_required }}
46+
run: |
47+
echo "::error::Preview deploy requires a maintainer to add the 'preview-approved' label on this pull request."
48+
exit 1
3749
- name: Forbid tearing down production
3850
if: ${{ inputs.target == 'www' && inputs.action == 'teardown' }}
3951
run: |
@@ -44,6 +56,7 @@ jobs:
4456
uses: actions/checkout@v4.2.2
4557
with:
4658
fetch-depth: 0
59+
ref: ${{ inputs.ref }}
4760
- name: Set up Python
4861
if: ${{ inputs.action != 'teardown' }}
4962
uses: actions/setup-python@v6

0 commit comments

Comments
 (0)