Skip to content

Commit c32754d

Browse files
authored
ci: avoid GITHUB_TOKEN for PR creation (#14207)
Using the workflow-native `GITHUB_TOKEN` for creation/approval of PRs requires an insecure workflow permissions setting: <img width="750" height="336" alt="image" src="https://github.com/user-attachments/assets/bba5c179-99c8-4e2c-925d-c553deddaffe" /> This creates a risk of branch protection bypass. Therefore, this PR migrates away from using the GITHUB_TOKEN for PR creation. It replaces the native GITHUB_TOKEN with a technical token generated via dd-octo-sts. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent 64a59e0 commit c32754d

6 files changed

+65
-6
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/dd-trace-py:pull_request
4+
5+
claim_pattern:
6+
event_name: pull_request_target
7+
ref: refs/heads/main
8+
ref_protected: "true"
9+
job_workflow_ref: DataDog/dd-trace-py/\.github/workflows/backport\.yml@refs/heads/main
10+
11+
permissions:
12+
contents: write
13+
pull_requests: write
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/dd-trace-py:ref:refs/heads/main
4+
5+
claim_pattern:
6+
event_name: (workflow_dispatch|schedule)
7+
ref: refs/heads/main
8+
ref_protected: "true"
9+
job_workflow_ref: DataDog/dd-trace-py/\.github/workflows/generate-package-versions\.yml@refs/heads/main
10+
11+
permissions:
12+
contents: write
13+
pull_requests: write
14+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/dd-trace-py:ref:refs/heads/main
4+
5+
claim_pattern:
6+
event_name: workflow_dispatch
7+
ref: refs/heads/main
8+
ref_protected: "true"
9+
job_workflow_ref: DataDog/dd-trace-py/\.github/workflows/generate-supported-versions\.yml@refs/heads/main
10+
11+
permissions:
12+
contents: write
13+
pull_requests: write

.github/workflows/backport.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
permissions:
1313
contents: write
14-
pull-requests: write
14+
id-token: write
1515
# Only react to merged PRs for security reasons.
1616
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
1717
if: >
@@ -24,9 +24,15 @@ jobs:
2424
)
2525
)
2626
steps:
27+
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
28+
id: octo-sts
29+
with:
30+
scope: DataDog/dd-trace-py
31+
policy: self.backport.create-pr
32+
2733
- uses: tibdex/backport@9565281eda0731b1d20c4025c43339fb0a23812e # v2.0.4
2834
with:
29-
github_token: ${{ secrets.GITHUB_TOKEN }}
35+
github_token: ${{ steps.octo-sts.outputs.token }}
3036
body_template: "Backport <%= mergeCommitSha %> from #<%= number %> to <%= base %>.\n\n<%= body %>"
3137
label_pattern: "^backport (?<base>([0-9]+\\.[0-9]+))$"
3238
# Include the original labels from the merged PR (minus any matching label_pattern)

.github/workflows/generate-package-versions.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
permissions:
1313
actions: read
1414
contents: write
15-
pull-requests: write
15+
id-token: write
1616

1717
steps:
1818
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -95,11 +95,17 @@ jobs:
9595
NEW_LATEST=$(python scripts/get_latest_version.py ${{ env.VENV_NAME }})
9696
echo "NEW_LATEST=$NEW_LATEST" >> $GITHUB_ENV
9797
98+
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
99+
id: octo-sts
100+
with:
101+
scope: DataDog/dd-trace-py
102+
policy: self.generate-package-versions.create-pr
103+
98104
- name: Create Pull Request
99105
id: pr
100106
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
101107
with:
102-
token: ${{ secrets.GITHUB_TOKEN }}
108+
token: ${{ steps.octo-sts.outputs.token }}
103109
branch: "upgrade-latest-${{ env.VENV_NAME }}-version"
104110
commit-message: "Update package version"
105111
delete-branch: true

.github/workflows/generate-supported-versions.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
permissions:
1111
actions: read
1212
contents: write
13-
pull-requests: write
13+
id-token: write
1414

1515
steps:
1616
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -77,11 +77,17 @@ jobs:
7777

7878
- run: git diff
7979

80+
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
81+
id: octo-sts
82+
with:
83+
scope: DataDog/dd-trace-py
84+
policy: self.generate-supported-versions.create-pr
85+
8086
- name: Create Pull Request
8187
id: pr
8288
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
8389
with:
84-
token: ${{ secrets.GITHUB_TOKEN }}
90+
token: ${{ steps.octo-sts.outputs.token }}
8591
branch: "update-supported-versions"
8692
commit-message: "Update supported versions table"
8793
delete-branch: true

0 commit comments

Comments
 (0)