Skip to content

Commit cf4c3bb

Browse files
authored
[chore][ci]: restrict permissions to /rerun only to PR authors (#45078)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description As discussed on the [core side](open-telemetry/opentelemetry-collector#14314 (comment)), it is safer to allow only PR authors to use the `/rerun` command. This does not change the feature, only filters by who can execute it in each PR. Signed-off-by: Paulo Dias <[email protected]>
1 parent 74672e2 commit cf4c3bb

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.github/workflows/rerun-workflows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ jobs:
2121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2222
PR_NUMBER: ${{ github.event.issue.number }}
2323
COMMENT: ${{ github.event.comment.body }}
24+
SENDER: ${{ github.event.comment.user.login }}

.github/workflows/scripts/rerun-failed-workflows.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
set -euo pipefail
88

9-
if [[ -z "${PR_NUMBER:-}" || -z "${COMMENT:-}" ]]; then
10-
echo "PR_NUMBER or COMMENT not set"
9+
if [[ -z "${PR_NUMBER:-}" || -z "${COMMENT:-}" || -z "${SENDER:-}" ]]; then
10+
echo "PR_NUMBER, COMMENT, or SENDER not set"
1111
exit 0
1212
fi
1313

@@ -16,7 +16,14 @@ if [[ ${COMMENT:0:6} != "/rerun" ]]; then
1616
exit 0
1717
fi
1818

19-
HEAD_SHA=$(gh pr view "${PR_NUMBER}" --json headRefOid --jq .headRefOid)
19+
PR_DATA=$(gh pr view "${PR_NUMBER}" --json headRefOid,author)
20+
HEAD_SHA=$(echo "${PR_DATA}" | jq -r '.headRefOid')
21+
PR_AUTHOR=$(echo "${PR_DATA}" | jq -r '.author.login')
22+
23+
if [[ "${SENDER}" != "${PR_AUTHOR}" ]]; then
24+
echo "Only PR author can rerun workflows"
25+
exit 0
26+
fi
2027

2128
echo "Finding failed workflows for commit: ${HEAD_SHA}"
2229

0 commit comments

Comments
 (0)