mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-05 19:47:53 +00:00
ci: gha: Remove ok-to-test label on every push
This removes the ok-to-test label on every push, except if the PR author has write access to the repo (ie. permission to modify labels). This protects against attackers who would initially open a genuine PR, then push malicious code after the initial review. Signed-off-by: Aurélien Bombo <abombo@microsoft.com>
This commit is contained in:
parent
17b2daf0a7
commit
2ee3470627
30
.github/workflows/validate-ok-to-test.yml
vendored
Normal file
30
.github/workflows/validate-ok-to-test.yml
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
name: Validate ok-to-test label
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [synchronize]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
remove-label-if-needed:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
permissions:
|
||||||
|
# SAFETY: Only enough to modify labels.
|
||||||
|
issues: write
|
||||||
|
steps:
|
||||||
|
- name: Remove ok-to-test label on push
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
|
AUTHOR: ${{ github.event.pull_request.user.login }}
|
||||||
|
OWNER: ${{ github.repository.owner.login }}
|
||||||
|
REPO: ${{ github.event.repository.name }}
|
||||||
|
run: |
|
||||||
|
permission="$(gh api "repos/${OWNER}/${REPO}/collaborators/${AUTHOR}/permission" --jq '.permission')"
|
||||||
|
echo "User ${AUTHOR} has permission '${permission}'"
|
||||||
|
|
||||||
|
if [[ "${permission}" != "write" && "${permission}" != "admin" ]]; then
|
||||||
|
echo "Removing 'ok-to-test' label"
|
||||||
|
gh pr edit "${PR_NUMBER}" --repo "${OWNER}/${REPO}" --remove-label "ok-to-test"
|
||||||
|
else
|
||||||
|
echo "User has label permission - skipping removal"
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user