Skip to content

Commit 0fdb9d1

Browse files
authored
chore(ci): use github app for tokens (#6534)
1 parent 03fc24d commit 0fdb9d1

5 files changed

+53
-58
lines changed

.github/workflows/authors-and-third-party-notices.yaml

+1-12
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@ jobs:
1616
HADRON_DISTRIBUTION: compass
1717
steps:
1818
- name: Create Github App Token
19-
uses: actions/create-github-app-token@v1
19+
uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
2020
id: app-token
2121
with:
2222
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
2323
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
2424

25-
- name: Get GitHub App User ID
26-
id: get-user-id
27-
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
28-
env:
29-
GH_TOKEN: ${{ steps.app-token.outputs.token }}
30-
3125
- uses: actions/checkout@v4
3226
with:
3327
# don't checkout a detatched HEAD
@@ -38,11 +32,6 @@ jobs:
3832
fetch-depth: "0"
3933
token: ${{ steps.app-token.outputs.token }}
4034

41-
- name: Set up Git
42-
run: |
43-
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
44-
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>'
45-
4635
- uses: actions/setup-node@v4
4736
with:
4837
node-version: 20.16.0

.github/workflows/bump-packages.yaml

+16-19
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,22 @@ jobs:
1010
name: Bump packages
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- name: Create Github App Token
14+
uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
15+
id: app-token
16+
with:
17+
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
18+
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
19+
20+
- uses: actions/checkout@v4
1421
with:
1522
# don't checkout a detatched HEAD
1623
ref: ${{ github.head_ref }}
1724

18-
# this is important so git log can pick up on
19-
# the whole history to generate the list of AUTHORS
20-
fetch-depth: '0'
21-
22-
- name: Setup git
23-
run: |
24-
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
25-
git config --local user.name "github-actions[bot]"
26-
27-
- uses: actions/setup-node@v3
25+
- uses: actions/setup-node@v4
2826
with:
2927
node-version: 20.16.0
30-
cache: 'npm'
28+
cache: "npm"
3129

3230
- name: Install [email protected]
3331
run: |
@@ -40,21 +38,20 @@ jobs:
4038
4139
- name: Bump packages
4240
env:
43-
LAST_BUMP_COMMIT_MESSAGE: 'chore(release): bump package versions'
44-
SKIP_BUMP_PACKAGES: 'mongodb-compass'
41+
LAST_BUMP_COMMIT_MESSAGE: "chore(release): bump package versions"
42+
SKIP_BUMP_PACKAGES: "mongodb-compass"
4543
run: |
4644
npm run bump-packages
4745
git add .
4846
git commit --no-allow-empty -m "$LAST_BUMP_COMMIT_MESSAGE" || true
4947
5048
- name: Create Pull Request
51-
id: cpr
52-
uses: peter-evans/create-pull-request@v6
49+
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5
5350
with:
54-
token: ${{ secrets.SVC_DEVTOOLSBOT_TOKEN }}
55-
commit-message: 'chore(release): bump package versions'
51+
token: ${{ steps.app-token.outputs.token }}
52+
commit-message: "chore(release): bump package versions"
5653
branch: ci/bump-packages
57-
title: 'chore(release): bump package versions'
54+
title: "chore(release): bump package versions"
5855
labels: no-title-validation
5956
body: |
6057
- Bump package versions

.github/workflows/merge-bump-packages-pr.yaml

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ on:
33
workflow_dispatch:
44
schedule:
55
# Each Tuesday at 5 AM UTC
6-
- cron: '0 5 * * 2'
6+
- cron: "0 5 * * 2"
77

88
jobs:
99
merge_bump_packages_pr:
1010
name: Merge bump packages PR
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- name: Create Github App Token
14+
uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
15+
id: app-token
16+
with:
17+
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
18+
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
1419

1520
- name: Merge PR
1621
env:
17-
GITHUB_TOKEN: ${{ secrets.SVC_DEVTOOLSBOT_TOKEN }}
22+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
1823
run: |
1924
set -e
2025
PR_NUMBER=$(gh pr list -s open --head=ci/bump-packages --limit=1 --json number | jq '.[0].number')

.github/workflows/update-electron.yaml

+19-23
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,40 @@ jobs:
1111
name: Update Electron
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- name: Create Github App Token
15+
uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
16+
id: app-token
17+
with:
18+
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
19+
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
20+
21+
- uses: actions/checkout@v4
1522
with:
1623
# don't checkout a detatched HEAD
1724
ref: ${{ github.head_ref }}
1825

19-
# this is important so git log can pick up on
20-
# the whole history to generate the list of AUTHORS
21-
fetch-depth: '0'
22-
23-
- name: Setup git
24-
run: |
25-
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
26-
git config --local user.name "github-actions[bot]"
27-
- uses: actions/setup-node@v3
26+
- uses: actions/setup-node@v4
2827
with:
2928
node-version: 20.16.0
30-
cache: 'npm'
29+
cache: "npm"
3130

3231
- name: Install [email protected]
3332
run: |
3433
npm install -g [email protected]
34+
3535
- name: Install Dependencies
36-
run: |
37-
npm -v
38-
npm ci
36+
run: npm ci
37+
3938
- name: Bump packages
40-
run: |
41-
node scripts/update-electron.js
42-
git add .
43-
git commit --no-allow-empty -m "chore(deps): update electron" || true
39+
run: node scripts/update-electron.js
40+
4441
- name: Create Pull Request
45-
id: cpr
46-
uses: peter-evans/create-pull-request@v6
42+
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5
4743
with:
48-
token: ${{ secrets.SVC_DEVTOOLSBOT_TOKEN }}
49-
commit-message: 'chore(deps): update electron'
44+
token: ${{ steps.app-token.outputs.token }}
45+
commit-message: "chore(deps): update electron"
5046
branch: ci/update-electron
51-
title: 'chore(deps): update electron'
47+
title: "chore(deps): update electron"
5248
labels: no-title-validation
5349
body: |
5450
- Update electron

CONTRIBUTING.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ In particular each change to the `main` branch is analyzed to calculate a new ve
9797

9898
Merging that PR will trigger another CI job that will publish to NPM any package which version is not yet present on the registry.
9999

100-
The version of packages is calculated following conventional bumps: See https://github.com/mongodb-js/devtools-shared/tree/main/packages/bump-monorepo-packages for details.
100+
The version of packages is calculated following conventional bumps: See https://github.com/mongodb-js/devtools-shared/tree/main/packages/monorepo-tools for details.
101101

102102
## Add / Update / Remove Dependencies in Packages
103103

@@ -115,6 +115,14 @@ npm run create-workspace [workspace name]
115115

116116
This will do all the initial workspace bootstrapping for you, ensuring that your package has all the standard configs set up and ready, and all the npm scripts aligned with other packages in the monorepo, which is important to get the most out of all the provided helpers in this repository (like `npm run check-changed` commands or to make sure that your tests will not immediately fail in CI because of the test timeout being too small)
117117

118+
## Using Github Actions
119+
120+
Github actions offers an easy way to create workflows that run various automated checks. While our main CI system is Evergreen, we have a number of auxiliary workflows configured to run using github actions. While adding new workflows or updating existing ones, it's important that we follow [the security hardening guidelines](https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions) by Github. Those can change over time, so be sure to periodically review them to make sure we're not using insecure workflows. Some notable highlights to pay special attention to are:
121+
1. Avoid using tag or branch refs for untrusted 3rd party actions. Those can easily be recreated by malicious actors and introduce supply chain attacks. As a rule of thumb, first party actions are considered actions by MongoDB, Github, Microsoft, or the primary maintainer of a particular ecosystem - e.g. Amazon for AWS. When using a 3rd party action, always use the full git commit sha as the ref to checkout.
122+
2. Be extra vigilant when using user-supplied data, such as branch name or PR title in scripts as that opens up the possibility of script injection attacks. Instead, prefer to use js actions to achieve the same result or sanitize the input before using it in a script.
123+
3. Never commit secrets in the workflow file directly - instead use github secrets to store them securely at the repo/org level.
124+
4. Avoid using repo-level secrets that grant access to deployment/publishing resources. Instead prefer to store these as environment secrets and ensure the correct environments protections are in place.
125+
118126
## Caveats
119127

120128
### `hdiutil: couldn't unmount "diskn" - Resource busy` or Similar `hdiutil` Errors

0 commit comments

Comments
 (0)