Skip to content

Commit f96b2da

Browse files
tym83claude
andcommitted
chore: replace cozystack-bot PAT with cozystack-ci GitHub App
Replace the cozystack-bot personal access token (GH_PAT) with a GitHub App (cozystack-ci) installation token across all CI/CD workflows. This improves security by using short-lived, scoped tokens instead of a long-lived PAT tied to a user account. Changes: - tags.yaml: use app token in all 3 jobs (prepare-release, generate-changelog, update-website-docs) - auto-release.yaml: use app token for daily patch releases - pull-requests-release.yaml: use app token for release finalization The cozystack-ci GitHub App (ID: 3297617) is installed org-wide with contents:write and pull-requests:write permissions. Secrets COZYSTACK_CI_APP_ID and COZYSTACK_CI_PRIVATE_KEY are set at org level. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 38624b7 commit f96b2da

3 files changed

Lines changed: 81 additions & 41 deletions

File tree

‎.github/workflows/auto-release.yaml‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ jobs:
2020
pull-requests: read
2121

2222
steps:
23+
- name: Generate GitHub App token
24+
id: app-token
25+
uses: actions/create-github-app-token@v1
26+
with:
27+
app-id: ${{ secrets.COZYSTACK_CI_APP_ID }}
28+
private-key: ${{ secrets.COZYSTACK_CI_PRIVATE_KEY }}
29+
owner: cozystack
30+
2331
- name: Checkout code
2432
uses: actions/checkout@v4
2533
with:
@@ -28,27 +36,27 @@ jobs:
2836

2937
- name: Configure git
3038
env:
31-
GH_PAT: ${{ secrets.GH_PAT }}
39+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
3240
run: |
33-
git config user.name "cozystack-bot"
34-
git config user.email "217169706[email protected]"
35-
git remote set-url origin https://cozystack-bot:${GH_PAT}@github.com/${GITHUB_REPOSITORY}
41+
git config user.name "cozystack-ci[bot]"
42+
git config user.email "3297617+cozystack-ci[bot]@users.noreply.github.com"
43+
git remote set-url origin https://x-access-token:${APP_TOKEN}@github.com/${GITHUB_REPOSITORY}
3644
git config --unset-all http.https://github.com/.extraheader || true
3745
3846
- name: Process release branches
3947
uses: actions/github-script@v7
4048
env:
41-
GH_PAT: ${{ secrets.GH_PAT }}
49+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
4250
with:
43-
github-token: ${{ secrets.GH_PAT }}
51+
github-token: ${{ steps.app-token.outputs.token }}
4452
script: |
4553
const { execSync } = require('child_process');
4654
47-
// Configure git to use PAT for authentication
48-
execSync('git config user.name "cozystack-bot"', { encoding: 'utf8' });
49-
execSync('git config user.email "217169706[email protected]"', { encoding: 'utf8' });
50-
execSync(`git remote set-url origin https://cozystack-bot:${process.env.GH_PAT}@github.com/${process.env.GITHUB_REPOSITORY}`, { encoding: 'utf8' });
51-
// Remove GITHUB_TOKEN extraheader to ensure PAT is used (needed to trigger other workflows)
55+
// Configure git to use GitHub App token for authentication
56+
execSync('git config user.name "cozystack-ci[bot]"', { encoding: 'utf8' });
57+
execSync('git config user.email "3297617+cozystack-ci[bot]@users.noreply.github.com"', { encoding: 'utf8' });
58+
execSync(`git remote set-url origin https://x-access-token:${process.env.APP_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}`, { encoding: 'utf8' });
59+
// Remove GITHUB_TOKEN extraheader to ensure App token is used (needed to trigger other workflows)
5260
execSync('git config --unset-all http.https://github.com/.extraheader || true', { encoding: 'utf8' });
5361
5462
// Get all release-X.Y branches

‎.github/workflows/pull-requests-release.yaml‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ jobs:
2323
contains(github.event.pull_request.labels.*.name, 'release')
2424
2525
steps:
26+
- name: Generate GitHub App token
27+
id: app-token
28+
uses: actions/create-github-app-token@v1
29+
with:
30+
app-id: ${{ secrets.COZYSTACK_CI_APP_ID }}
31+
private-key: ${{ secrets.COZYSTACK_CI_PRIVATE_KEY }}
32+
owner: cozystack
33+
2634
# Extract tag from branch name (branch = release-X.Y.Z*)
2735
- name: Extract tag from branch name
2836
id: get_tag
@@ -47,19 +55,19 @@ jobs:
4755

4856
- name: Create tag on merge commit
4957
env:
50-
GH_PAT: ${{ secrets.GH_PAT }}
58+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
5159
run: |
52-
git config user.name "cozystack-bot"
53-
git config user.email "217169706[email protected]"
54-
git remote set-url origin https://cozystack-bot:${GH_PAT}@github.com/${GITHUB_REPOSITORY}
60+
git config user.name "cozystack-ci[bot]"
61+
git config user.email "3297617+cozystack-ci[bot]@users.noreply.github.com"
62+
git remote set-url origin https://x-access-token:${APP_TOKEN}@github.com/${GITHUB_REPOSITORY}
5563
git tag -f ${{ steps.get_tag.outputs.tag }} ${{ github.sha }}
5664
git push -f origin ${{ steps.get_tag.outputs.tag }}
5765
5866
# Ensure maintenance branch release-X.Y
5967
- name: Ensure maintenance branch release-X.Y
6068
uses: actions/github-script@v7
6169
with:
62-
github-token: ${{ secrets.GH_PAT }}
70+
github-token: ${{ steps.app-token.outputs.token }}
6371
script: |
6472
const tag = '${{ steps.get_tag.outputs.tag }}'; // e.g. v0.1.3 or v0.1.3-rc3
6573
const match = tag.match(/^v(\d+)\.(\d+)\.\d+(?:[-\w\.]+)?$/);

‎.github/workflows/tags.yaml‎

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ jobs:
2525
actions: write
2626

2727
steps:
28+
- name: Generate GitHub App token
29+
id: app-token
30+
uses: actions/create-github-app-token@v1
31+
with:
32+
app-id: ${{ secrets.COZYSTACK_CI_APP_ID }}
33+
private-key: ${{ secrets.COZYSTACK_CI_PRIVATE_KEY }}
34+
owner: cozystack
35+
2836
# Check if a non-draft release with this tag already exists
2937
- name: Check if release already exists
3038
id: check_release
@@ -115,11 +123,11 @@ jobs:
115123
- name: Commit release artifacts
116124
if: steps.check_release.outputs.skip == 'false'
117125
env:
118-
GH_PAT: ${{ secrets.GH_PAT }}
126+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
119127
run: |
120-
git config user.name "cozystack-bot"
121-
git config user.email "217169706[email protected]"
122-
git remote set-url origin https://cozystack-bot:${GH_PAT}@github.com/${GITHUB_REPOSITORY}
128+
git config user.name "cozystack-ci[bot]"
129+
git config user.email "3297617+cozystack-ci[bot]@users.noreply.github.com"
130+
git remote set-url origin https://x-access-token:${APP_TOKEN}@github.com/${GITHUB_REPOSITORY}
123131
git config --unset-all http.https://github.com/.extraheader || true
124132
git add .
125133
git commit -m "Prepare release ${GITHUB_REF#refs/tags/}" -s || echo "No changes to commit"
@@ -128,13 +136,13 @@ jobs:
128136
- name: Tag API submodule
129137
if: steps.check_release.outputs.skip == 'false'
130138
env:
131-
GH_PAT: ${{ secrets.GH_PAT }}
139+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
132140
run: |
133141
VTAG="${{ steps.tag.outputs.tag }}"
134142
SUBTAG="api/apps/v1alpha1/${VTAG}"
135-
git config user.name "cozystack-bot"
136-
git config user.email "217169706[email protected]"
137-
git remote set-url origin https://cozystack-bot:${GH_PAT}@github.com/${GITHUB_REPOSITORY}
143+
git config user.name "cozystack-ci[bot]"
144+
git config user.email "3297617+cozystack-ci[bot]@users.noreply.github.com"
145+
git remote set-url origin https://x-access-token:${APP_TOKEN}@github.com/${GITHUB_REPOSITORY}
138146
TARGET="$(git rev-parse "${VTAG}^{}")"
139147
git tag -f "${SUBTAG}" "$TARGET"
140148
git push -f origin "refs/tags/${SUBTAG}"
@@ -183,11 +191,11 @@ jobs:
183191
- name: Create release branch
184192
if: steps.check_release.outputs.skip == 'false'
185193
env:
186-
GH_PAT: ${{ secrets.GH_PAT }}
194+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
187195
run: |
188-
git config user.name "cozystack-bot"
189-
git config user.email "217169706[email protected]"
190-
git remote set-url origin https://cozystack-bot:${GH_PAT}@github.com/${GITHUB_REPOSITORY}
196+
git config user.name "cozystack-ci[bot]"
197+
git config user.email "3297617+cozystack-ci[bot]@users.noreply.github.com"
198+
git remote set-url origin https://x-access-token:${APP_TOKEN}@github.com/${GITHUB_REPOSITORY}
191199
BRANCH="release-${GITHUB_REF#refs/tags/v}"
192200
git branch -f "$BRANCH"
193201
git push -f origin "$BRANCH"
@@ -197,7 +205,7 @@ jobs:
197205
if: steps.check_release.outputs.skip == 'false'
198206
uses: actions/github-script@v7
199207
with:
200-
github-token: ${{ secrets.GH_PAT }}
208+
github-token: ${{ steps.app-token.outputs.token }}
201209
script: |
202210
const version = context.ref.replace('refs/tags/v', '');
203211
const base = '${{ steps.get_base.outputs.branch }}';
@@ -239,6 +247,14 @@ jobs:
239247
pull-requests: write
240248
if: needs.prepare-release.result == 'success'
241249
steps:
250+
- name: Generate GitHub App token
251+
id: app-token
252+
uses: actions/create-github-app-token@v1
253+
with:
254+
app-id: ${{ secrets.COZYSTACK_CI_APP_ID }}
255+
private-key: ${{ secrets.COZYSTACK_CI_PRIVATE_KEY }}
256+
owner: cozystack
257+
242258
- name: Parse tag
243259
id: tag
244260
uses: actions/github-script@v7
@@ -261,7 +277,7 @@ jobs:
261277
ref: main
262278
fetch-depth: 0
263279
fetch-tags: true
264-
token: ${{ secrets.GH_PAT }}
280+
token: ${{ steps.app-token.outputs.token }}
265281

266282
- name: Check if changelog already exists
267283
id: check_changelog
@@ -289,19 +305,19 @@ jobs:
289305
if: steps.check_changelog.outputs.exists == 'false'
290306
env:
291307
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
292-
GH_TOKEN: ${{ secrets.GH_PAT }}
308+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
293309
run: |
294310
copilot --prompt "prepare changelog file for tagged release v${{ steps.tag.outputs.version }}, use @docs/agents/changelog.md for it. Create the changelog file at docs/changelogs/v${{ steps.tag.outputs.version }}.md" \
295311
--allow-all-tools --allow-all-paths < /dev/null
296312
297313
- name: Create changelog branch and commit
298314
if: steps.check_changelog.outputs.exists == 'false'
299315
env:
300-
GH_PAT: ${{ secrets.GH_PAT }}
316+
APP_TOKEN: ${{ steps.app-token.outputs.token }}
301317
run: |
302-
git config user.name "cozystack-bot"
303-
git config user.email "217169706[email protected]"
304-
git remote set-url origin https://cozystack-bot:${GH_PAT}@github.com/${GITHUB_REPOSITORY}
318+
git config user.name "cozystack-ci[bot]"
319+
git config user.email "3297617+cozystack-ci[bot]@users.noreply.github.com"
320+
git remote set-url origin https://x-access-token:${APP_TOKEN}@github.com/${GITHUB_REPOSITORY}
305321
306322
CHANGELOG_FILE="docs/changelogs/v${{ steps.tag.outputs.version }}.md"
307323
CHANGELOG_BRANCH="changelog-v${{ steps.tag.outputs.version }}"
@@ -336,7 +352,7 @@ jobs:
336352
if: steps.check_changelog.outputs.exists == 'false'
337353
uses: actions/github-script@v7
338354
with:
339-
github-token: ${{ secrets.GH_PAT }}
355+
github-token: ${{ steps.app-token.outputs.token }}
340356
script: |
341357
const version = '${{ steps.tag.outputs.version }}';
342358
const changelogBranch = `changelog-v${version}`;
@@ -395,6 +411,14 @@ jobs:
395411
permissions:
396412
contents: read
397413
steps:
414+
- name: Generate GitHub App token
415+
id: app-token
416+
uses: actions/create-github-app-token@v1
417+
with:
418+
app-id: ${{ secrets.COZYSTACK_CI_APP_ID }}
419+
private-key: ${{ secrets.COZYSTACK_CI_PRIVATE_KEY }}
420+
owner: cozystack
421+
398422
- name: Parse tag
399423
id: tag
400424
uses: actions/github-script@v7
@@ -414,19 +438,19 @@ jobs:
414438
uses: actions/checkout@v4
415439
with:
416440
repository: cozystack/website
417-
token: ${{ secrets.GH_PAT }}
441+
token: ${{ steps.app-token.outputs.token }}
418442
ref: main
419443

420444
- name: Update docs from release branch
421445
env:
422-
GH_TOKEN: ${{ secrets.GH_PAT }}
446+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
423447
run: make update-all BRANCH=release-${{ steps.tag.outputs.version }} RELEASE_TAG=${{ steps.tag.outputs.tag }}
424448

425449
- name: Commit and push
426450
id: commit
427451
run: |
428-
git config user.name "cozystack-bot"
429-
git config user.email "217169706[email protected]"
452+
git config user.name "cozystack-ci[bot]"
453+
git config user.email "3297617+cozystack-ci[bot]@users.noreply.github.com"
430454
git add content
431455
if git diff --cached --quiet; then
432456
echo "No changes to commit"
@@ -443,7 +467,7 @@ jobs:
443467
- name: Open pull request
444468
if: steps.commit.outputs.changed == 'true'
445469
env:
446-
GH_TOKEN: ${{ secrets.GH_PAT }}
470+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
447471
run: |
448472
BRANCH="update-docs-v${{ steps.tag.outputs.version }}"
449473
pr_state=$(gh pr view "$BRANCH" --repo cozystack/website --json state --jq .state 2>/dev/null || echo "")

0 commit comments

Comments
 (0)