Skip to content

Commit 2877227

Browse files
lloekisarahchen6
andauthored
Replace secrets.GITHUB_TOKEN with dd-octo-sts in CI workflows (#11347)
Add dd-octo-sts chainguard policy files Add 5 policy files under .github/chainguard/ declaring the issuer, subject, event, and permission constraints for every workflow that will be migrated from secrets.GITHUB_TOKEN to DataDog/dd-octo-sts-action. These policies must be on the default branch before the corresponding workflow changes can use them. Replace secrets.GITHUB_TOKEN with dd-octo-sts Migrate all 5 GitHub Actions workflows from secrets.GITHUB_TOKEN to OIDC tokens minted by DataDog/dd-octo-sts-action. The token exchange is auditable and governed by chainguard policy files that explicitly declare which workflow, event, and ref pattern may request which permissions. All affected workflows pass the token to actions/github-script via the github-token parameter. Merge branch 'master' into lloeki/dd-octo-sts Co-authored-by: sarahchen6 <sarah.chen@datadoghq.com>
1 parent 3bca1f0 commit 2877227

5 files changed

Lines changed: 48 additions & 13 deletions

File tree

.github/workflows/check-pull-request-labels.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ jobs:
1111
check_pr_labels:
1212
name: Check pull request labels
1313
permissions:
14+
id-token: write # Required for OIDC token federation
1415
issues: write
1516
pull-requests: write
1617
runs-on: ubuntu-latest
1718
steps:
19+
- name: Get GitHub Token via dd-octo-sts
20+
id: generate-token
21+
uses: DataDog/dd-octo-sts-action@96a25462dbcb10ebf0bfd6e2ccc917d2ab235b9a # v1.0.4
22+
with:
23+
scope: DataDog/dd-trace-java
24+
policy: self.check-pull-request-labels
1825
- name: Flag AI-generated pull requests
1926
id: flag_ai_generated
2027
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # 9.0.0
2128
with:
22-
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
github-token: ${{ steps.generate-token.outputs.token }}
2330
script: |
2431
// Skip draft pull requests
2532
if (context.payload.pull_request.draft) {
@@ -124,7 +131,7 @@ jobs:
124131
env:
125132
LABELS_STALE: ${{ steps.flag_ai_generated.outputs.labels_stale }}
126133
with:
127-
github-token: ${{ secrets.GITHUB_TOKEN }}
134+
github-token: ${{ steps.generate-token.outputs.token }}
128135
script: |
129136
// Skip draft pull requests
130137
if (context.payload.pull_request.draft) {

.github/workflows/check-pull-requests.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,30 @@ on:
33
pull_request:
44
types: [opened, edited, ready_for_review, labeled, unlabeled, synchronize]
55
branches:
6-
- master
7-
- release/v*
6+
- master
7+
- release/v*
88
concurrency:
99
group: ${{ github.workflow }}-${{ github.ref }}
1010
cancel-in-progress: true
1111
jobs:
1212
check_pull_requests:
1313
name: Check pull requests
1414
permissions:
15+
id-token: write # Required for OIDC token federation
1516
issues: write # Required to create a comment on the pull request
1617
pull-requests: write # Required to create a comment on the pull request
1718
runs-on: ubuntu-latest
1819
steps:
20+
- name: Get GitHub Token via dd-octo-sts
21+
id: generate-token
22+
uses: DataDog/dd-octo-sts-action@96a25462dbcb10ebf0bfd6e2ccc917d2ab235b9a # v1.0.4
23+
with:
24+
scope: DataDog/dd-trace-java
25+
policy: self.check-pull-requests
1926
- name: Check pull requests
2027
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # 9.0.0
2128
with:
22-
github-token: ${{secrets.GITHUB_TOKEN}}
29+
github-token: ${{ steps.generate-token.outputs.token }}
2330
script: |
2431
// Skip draft pull requests
2532
if (context.payload.pull_request.draft) {
@@ -41,7 +48,7 @@ jobs:
4148
if (titleCheckFailed) {
4249
core.setFailed('Please remove the tag from the pull request title.')
4350
}
44-
// Check body does
51+
// Check body does
4552
const linkingKeywords = ['closes', 'closed', 'fix', 'fixes', 'fixed', 'resolve', 'resolves', 'resolved']
4653
const body = context.payload.pull_request.body
4754
const bodyCheckFailed = linkingKeywords.some(keyword => body.search(new RegExp(`${keyword}\\s\\d+`, "im")) !== -1)

.github/workflows/comment-on-submodule-update.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,30 @@ name: Comment on Submodule Update
33
on:
44
pull_request:
55
branches:
6-
- 'master'
7-
- 'release/**'
6+
- "master"
7+
- "release/**"
88
paths:
9-
- 'dd-java-agent/agent-jmxfetch/integrations-core'
9+
- "dd-java-agent/agent-jmxfetch/integrations-core"
1010

1111
jobs:
1212
comment_on_submodule_update:
1313
permissions:
14+
id-token: write # Required for OIDC token federation
1415
issues: write # Required to create a comment on the pull request
1516
pull-requests: write # Required to create a comment on the pull request
1617
runs-on: ubuntu-latest
1718

1819
steps:
20+
- name: Get GitHub Token via dd-octo-sts
21+
id: generate-token
22+
uses: DataDog/dd-octo-sts-action@96a25462dbcb10ebf0bfd6e2ccc917d2ab235b9a # v1.0.4
23+
with:
24+
scope: DataDog/dd-trace-java
25+
policy: self.comment-on-submodule-update
1926
- name: Post comment on submodule update
2027
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # 9.0.0
2128
with:
22-
github-token: ${{secrets.GITHUB_TOKEN}}
29+
github-token: ${{ steps.generate-token.outputs.token }}
2330
script: |
2431
github.rest.issues.createComment({
2532
issue_number: context.issue.number,

.github/workflows/enforce-groovy-migration.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
types: [opened, edited, ready_for_review, labeled, unlabeled, synchronize]
55
branches:
66
- master
7-
- 'release/v*'
7+
- "release/v*"
88

99
concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
@@ -14,14 +14,21 @@ jobs:
1414
enforce_groovy_migration:
1515
name: Enforce Groovy migration
1616
permissions:
17+
id-token: write # Required for OIDC token federation
1718
issues: write # Required to create a comment on the pull request
1819
pull-requests: write # Required to create a comment on the pull request
1920
runs-on: ubuntu-latest
2021
steps:
22+
- name: Get GitHub Token via dd-octo-sts
23+
id: generate-token
24+
uses: DataDog/dd-octo-sts-action@96a25462dbcb10ebf0bfd6e2ccc917d2ab235b9a # v1.0.4
25+
with:
26+
scope: DataDog/dd-trace-java
27+
policy: self.enforce-groovy-migration
2128
- name: Check for new Groovy files
2229
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # 9.0.0
2330
with:
24-
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
github-token: ${{ steps.generate-token.outputs.token }}
2532
script: |
2633
const managedMarker = '<!-- dd-trace-java-groovy-enforcement -->'
2734

.github/workflows/update-issues-on-release.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@ on:
1111
jobs:
1212
update_issues:
1313
permissions:
14+
id-token: write # Required for OIDC token federation
1415
issues: write # Required to update issues
1516
runs-on: ubuntu-latest
1617
steps:
18+
- name: Get GitHub Token via dd-octo-sts
19+
id: generate-token
20+
uses: DataDog/dd-octo-sts-action@96a25462dbcb10ebf0bfd6e2ccc917d2ab235b9a # v1.0.4
21+
with:
22+
scope: DataDog/dd-trace-java
23+
policy: self.update-issues-on-release
1724
- name: Get milestone for release
1825
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # 9.0.0
1926
with:
20-
github-token: ${{secrets.GITHUB_TOKEN}}
27+
github-token: ${{ steps.generate-token.outputs.token }}
2128
script: |
2229
// Get release milestone name
2330
const milestoneName = "${{github.event_name}}" == "workflow_dispatch" ?

0 commit comments

Comments
 (0)