Skip to content

Commit 679c72a

Browse files
authored
Harden CI workflows (#139)
* Use dynamic github token Signed-off-by: Tamal Saha <tamal@appscode.com> * Harden GitHub Actions workflows - Pin every action ref to a full-length commit SHA with a trailing version comment, so floating tags like @v4 can't be re-pointed at malicious code. - Bump outdated actions/checkout@v1 to @v4.3.1 (where present). - Tag-triggered workflows now check out with fetch-depth: 1 and fetch-tags: true so the tag ref is available downstream. - release-tracker.yml grants contents: write at the job level so the default GITHUB_TOKEN can push commits/tags back to the repo. Signed-off-by: Tamal Saha <tamal@appscode.com> * Migrate firebase-tools auth to service account Signed-off-by: Tamal Saha <tamal@appscode.com> * Grant preview-website job the permissions Firebase deploy needs Signed-off-by: Tamal Saha <tamal@appscode.com> * Use GitHub App token for release tracker comments Signed-off-by: Tamal Saha <tamal@appscode.com> * Apply kubedb/installer#2281: harden CI workflows Signed-off-by: Tamal Saha <tamal@appscode.com> * Remove Prepare git step from release-tracker.yml Signed-off-by: Tamal Saha <tamal@appscode.com> * Rename LGTM App token step id to lgtm-app-token Signed-off-by: Tamal Saha <tamal@appscode.com> * release-tracker.yml: gate at job level with merged == true Signed-off-by: Tamal Saha <tamal@appscode.com> * release-tracker.yml: drop permissions block Signed-off-by: Tamal Saha <tamal@appscode.com> * release-tracker.yml: grant permission-pull-requests to LGTM App Signed-off-by: Tamal Saha <tamal@appscode.com> * Use node-version: '22' in setup-node steps Signed-off-by: Tamal Saha <tamal@appscode.com> * Normalize Prepare git user, fetch-depth, drop permission-issues Signed-off-by: Tamal Saha <tamal@appscode.com> * Add 1gtm-app[bot] to kodiak auto_approve_usernames Signed-off-by: Tamal Saha <tamal@appscode.com> * Normalize kodiak auto_approve_usernames Signed-off-by: Tamal Saha <tamal@appscode.com> * Bump softprops/action-gh-release to v2.6.2; add permissions Signed-off-by: Tamal Saha <tamal@appscode.com> --------- Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent d5e296b commit 679c72a

6 files changed

Lines changed: 40 additions & 37 deletions

File tree

.github/.kodiak.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ strip_html_comments = true # default: false
1515
always = true # default: false
1616

1717
[approve]
18-
auto_approve_usernames = ["1gtm", "tamalsaha"]
18+
auto_approve_usernames = ["tamalsaha", "1gtm", "1gtm-app[bot]"]

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919
name: Build
2020
runs-on: ubuntu-24.04
2121
steps:
22-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2323
with:
2424
submodules: true
2525

26-
- uses: actions/setup-node@v4
26+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
2727
with:
28-
node-version: '20'
28+
node-version: '22'
2929
check-latest: true
3030

3131
- name: Install yq

.github/workflows/preview-website.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,25 @@ jobs:
1515
build:
1616
name: Build
1717
runs-on: ubuntu-24.04
18+
permissions:
19+
contents: read
20+
checks: write
21+
pull-requests: write
1822
steps:
19-
- uses: actions/checkout@v4
23+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2024
with:
2125
submodules: true
2226

2327
- name: Set up Go 1.x
24-
uses: actions/setup-go@v5
28+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
2529
with:
2630
go-version: '1.25'
2731
id: go
2832

2933
- name: Use Node.js
30-
uses: actions/setup-node@v4
34+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
3135
with:
32-
node-version: '20'
36+
node-version: '22'
3337
check-latest: true
3438

3539
- name: Install yq
@@ -59,7 +63,7 @@ jobs:
5963
make docs
6064
make gen-prod
6165
62-
- uses: FirebaseExtended/action-hosting-deploy@v0
66+
- uses: FirebaseExtended/action-hosting-deploy@092436dca3ec6dacb231d965ae56f7ff6c09f258 # v0
6367
with:
6468
repoToken: '${{ secrets.GITHUB_TOKEN }}'
6569
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_QA }}'

.github/workflows/release-tracker.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,27 @@ concurrency:
1212

1313
jobs:
1414
build:
15+
if: github.event.pull_request.merged == true
1516
runs-on: ubuntu-24.04
1617

1718
steps:
18-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
1920
with:
2021
submodules: true
2122

22-
- name: Prepare git
23-
env:
24-
GITHUB_USER: 1gtm
25-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
26-
run: |
27-
git config --global user.name "${GITHUB_USER}"
28-
git config --global user.email "${GITHUB_USER}@appscode.com"
29-
git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
30-
31-
- name: Install GitHub CLI
32-
run: |
33-
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
34-
sudo mv bin/hub /usr/local/bin
23+
- name: Generate LGTM App token
24+
id: lgtm-app-token
25+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
26+
with:
27+
client-id: ${{ secrets.LGTM_APP_CLIENT_ID }}
28+
private-key: ${{ secrets.LGTM_APP_PRIVATE_KEY }}
29+
owner: ${{ github.repository_owner }}
30+
repositories: CHANGELOG
31+
permission-pull-requests: write
3532

3633
- name: Update release tracker
37-
if: |
38-
github.event.action == 'closed' &&
39-
github.event.pull_request.merged == true
4034
env:
41-
GITHUB_USER: 1gtm
42-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
35+
GITHUB_USER: ${{ github.actor }}
36+
GITHUB_TOKEN: ${{ steps.lgtm-app-token.outputs.token }}
4337
run: |
4438
./hack/scripts/update-release-tracker.sh

.github/workflows/release.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@ jobs:
1515
build:
1616
name: Build
1717
runs-on: ubuntu-24.04
18+
permissions:
19+
contents: write
1820
steps:
19-
- uses: actions/checkout@v1
21+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2022
with:
23+
fetch-depth: 0
2124
submodules: true
2225

2326
- name: Set up Go 1.x
24-
uses: actions/setup-go@v5
27+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
2528
with:
2629
go-version: '1.25'
2730
id: go
2831

2932
- name: Use Node.js
30-
uses: actions/setup-node@v4
33+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
3134
with:
32-
node-version: '20'
35+
node-version: '22'
3336
check-latest: true
3437

3538
- name: Install yq
@@ -56,20 +59,22 @@ jobs:
5659
5760
- name: QA
5861
env:
59-
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
60-
GOOGLE_CUSTOM_SEARCH_API_KEY: ${{ secrets.GOOGLE_CUSTOM_SEARCH_API_KEY }}
62+
FIREBASE_SERVICE_ACCOUNT_KEY: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_QA }}
6163
if: startsWith(github.event.ref, 'refs/tags/') && (contains(github.ref, '-alpha.') || contains(github.ref, '-beta.'))
6264
run: |
65+
printf '%s' "$FIREBASE_SERVICE_ACCOUNT_KEY" > "$RUNNER_TEMP/firebase-key.json"
66+
export GOOGLE_APPLICATION_CREDENTIALS="$RUNNER_TEMP/firebase-key.json"
6367
npm install
6468
make docs
6569
make qa
6670
6771
- name: Release
6872
env:
69-
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
70-
GOOGLE_CUSTOM_SEARCH_API_KEY: ${{ secrets.GOOGLE_CUSTOM_SEARCH_API_KEY }}
73+
FIREBASE_SERVICE_ACCOUNT_KEY: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_PROD }}
7174
if: startsWith(github.event.ref, 'refs/tags/') && (contains(github.ref, '-alpha.') || contains(github.ref, '-beta.')) == false
7275
run: |
76+
printf '%s' "$FIREBASE_SERVICE_ACCOUNT_KEY" > "$RUNNER_TEMP/firebase-key.json"
77+
export GOOGLE_APPLICATION_CREDENTIALS="$RUNNER_TEMP/firebase-key.json"
7378
npm install
7479
make docs
7580
make release

hack/scripts/update-release-tracker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ case $GITHUB_BASE_REF in
6969
;;
7070
esac
7171

72-
hub api "$api_url" -f body="$msg"
72+
gh api "$api_url" -f body="$msg"

0 commit comments

Comments
 (0)