Skip to content

Commit 84046e1

Browse files
authored
Harden CI workflows (#323)
* 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> * 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> * 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> --------- Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent c43b05a commit 84046e1

6 files changed

Lines changed: 34 additions & 36 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
name: Build
1919
runs-on: ubuntu-24.04
2020
steps:
21-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2222

2323
- name: Install link checker
2424
run: |
@@ -38,7 +38,7 @@ jobs:
3838
3939
- name: Create Kubernetes cluster
4040
id: kind
41-
uses: engineerd/setup-kind@v0.5.0
41+
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0
4242
with:
4343
version: v0.29.0
4444

.github/workflows/preview-website.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ jobs:
1414
build:
1515
name: Build
1616
runs-on: ubuntu-24.04
17+
permissions:
18+
contents: read
19+
checks: write
20+
pull-requests: write
1721
steps:
18-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
1923

2024
- name: Set up Go 1.x
21-
uses: actions/setup-go@v5
25+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
2226
with:
2327
go-version: '1.25'
2428
id: go
2529

2630
- name: Use Node.js
27-
uses: actions/setup-node@v4
31+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
2832
with:
29-
node-version: '18'
33+
node-version: '22'
3034

3135
- name: Install yq
3236
run: |
@@ -49,8 +53,8 @@ jobs:
4953
5054
- name: Clone website repository
5155
env:
52-
GITHUB_USER: 1gtm
53-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
56+
GITHUB_USER: ${{ github.actor }}
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5458
WEBSITE_REPOSITORY: ${{ secrets.WEBSITE_REPOSITORY }}
5559
run: |
5660
url="https://${GITHUB_USER}:${GITHUB_TOKEN}@${WEBSITE_REPOSITORY}.git"
@@ -62,8 +66,8 @@ jobs:
6266
6367
- name: Update docs
6468
env:
65-
GITHUB_USER: 1gtm
66-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
69+
GITHUB_USER: ${{ github.actor }}
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6771
WEBSITE_REPOSITORY: ${{ secrets.WEBSITE_REPOSITORY }}
6872
GOOGLE_CUSTOM_SEARCH_API_KEY: ${{ secrets.GOOGLE_CUSTOM_SEARCH_API_KEY }}
6973
run: |
@@ -76,7 +80,7 @@ jobs:
7680
make docs-skip-assets
7781
make gen-prod
7882
79-
- uses: FirebaseExtended/action-hosting-deploy@v0
83+
- uses: FirebaseExtended/action-hosting-deploy@092436dca3ec6dacb231d965ae56f7ff6c09f258 # v0
8084
with:
8185
repoToken: '${{ secrets.GITHUB_TOKEN }}'
8286
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
@@ -11,31 +11,25 @@ concurrency:
1111

1212
jobs:
1313
build:
14+
if: github.event.pull_request.merged == true
1415
runs-on: ubuntu-24.04
1516

1617
steps:
17-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
1819

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

3330
- name: Update release tracker
34-
if: |
35-
github.event.action == 'closed' &&
36-
github.event.pull_request.merged == true
3731
env:
38-
GITHUB_USER: 1gtm
39-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
32+
GITHUB_USER: ${{ github.actor }}
33+
GITHUB_TOKEN: ${{ steps.lgtm-app-token.outputs.token }}
4034
run: |
4135
./hack/scripts/update-release-tracker.sh

hack/scripts/open-pr.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pr_branch=${GITHUB_REPOSITORY}@${GITHUB_SHA:0:8}
3636
git checkout -b $pr_branch
3737
git commit -a -s -m "Update docs for $pr_branch"
3838
git push -u origin HEAD
39-
hub pull-request \
40-
--labels automerge \
41-
--message "Update docs for $pr_branch" \
42-
--message "$(git show -s --format=%b)"
39+
gh pr create \
40+
--label automerge \
41+
--title "Update docs for $pr_branch" \
42+
--body "$(git show -s --format=%b)"

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)