Skip to content

Commit cc7f623

Browse files
authored
Harden CI workflows (#123)
* 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 4bad7ac commit cc7f623

6 files changed

Lines changed: 42 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
@@ -31,7 +31,7 @@ jobs:
3131
needs: label-detector
3232
runs-on: "${{ needs.label-detector.outputs.runs-on }}"
3333
steps:
34-
- uses: actions/checkout@v4
34+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
3535

3636
- name: Install kubectl
3737
run: |
@@ -47,7 +47,7 @@ jobs:
4747
4848
- name: Create Kubernetes cluster
4949
id: kind
50-
uses: engineerd/setup-kind@v0.5.0
50+
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0
5151
with:
5252
version: v0.31.0
5353

.github/workflows/preview-website.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ jobs:
1414
label-detector:
1515
name: Runner Label
1616
runs-on: label-detector
17+
permissions:
18+
contents: read
19+
checks: write
20+
pull-requests: write
1721
outputs:
1822
runs-on: ${{ steps.detector.outputs.label }}
23+
permissions:
24+
contents: read
25+
checks: write
26+
pull-requests: write
1927
steps:
2028
- name: Detect Label
2129
id: detector
@@ -27,21 +35,25 @@ jobs:
2735
name: Build
2836
needs: label-detector
2937
runs-on: "${{ needs.label-detector.outputs.runs-on }}"
38+
permissions:
39+
contents: read
40+
checks: write
41+
pull-requests: write
3042
steps:
31-
- uses: actions/checkout@v4
43+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
3244
with:
3345
submodules: true
3446

3547
- name: Set up Go 1.x
36-
uses: actions/setup-go@v5
48+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
3749
with:
3850
go-version: '1.25'
3951
id: go
4052

4153
- name: Use Node.js
42-
uses: actions/setup-node@v4
54+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
4355
with:
44-
node-version: '20'
56+
node-version: '22'
4557

4658
- name: Install yq
4759
run: |
@@ -63,8 +75,8 @@ jobs:
6375
6476
- name: Clone website repository
6577
env:
66-
GITHUB_USER: 1gtm
67-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
78+
GITHUB_USER: ${{ github.actor }}
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6880
WEBSITE_REPOSITORY: ${{ secrets.WEBSITE_REPOSITORY }}
6981
run: |
7082
url="https://${GITHUB_USER}:${GITHUB_TOKEN}@${WEBSITE_REPOSITORY}.git"
@@ -76,8 +88,8 @@ jobs:
7688
7789
- name: Update docs
7890
env:
79-
GITHUB_USER: 1gtm
80-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
91+
GITHUB_USER: ${{ github.actor }}
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8193
WEBSITE_REPOSITORY: ${{ secrets.WEBSITE_REPOSITORY }}
8294
GOOGLE_CUSTOM_SEARCH_API_KEY: ${{ secrets.GOOGLE_CUSTOM_SEARCH_API_KEY }}
8395
run: |
@@ -91,7 +103,7 @@ jobs:
91103
make docs-platform
92104
make gen-prod
93105
94-
- uses: FirebaseExtended/action-hosting-deploy@v0
106+
- uses: FirebaseExtended/action-hosting-deploy@092436dca3ec6dacb231d965ae56f7ff6c09f258 # v0
95107
with:
96108
repoToken: '${{ secrets.GITHUB_TOKEN }}'
97109
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
@@ -23,32 +23,26 @@ jobs:
2323
echo "label=$(curl -fsSL https://this-is-nats.appscode.ninja/runs-on/${{ github.repository_owner }}?visibility=${{ github.repository_visibility }})" >> $GITHUB_OUTPUT
2424
2525
build:
26+
if: github.event.pull_request.merged == true
2627
name: Build
2728
needs: label-detector
2829
runs-on: "${{ needs.label-detector.outputs.runs-on }}"
2930
steps:
30-
- uses: actions/checkout@v4
31+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
3132

32-
- name: Prepare git
33-
env:
34-
GITHUB_USER: 1gtm
35-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
36-
run: |
37-
git config --global user.name "${GITHUB_USER}"
38-
git config --global user.email "${GITHUB_USER}@appscode.com"
39-
git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
40-
41-
- name: Install GitHub CLI
42-
run: |
43-
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
44-
sudo mv bin/hub /usr/local/bin
33+
- name: Generate LGTM App token
34+
id: lgtm-app-token
35+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
36+
with:
37+
client-id: ${{ secrets.LGTM_APP_CLIENT_ID }}
38+
private-key: ${{ secrets.LGTM_APP_PRIVATE_KEY }}
39+
owner: ${{ github.repository_owner }}
40+
repositories: CHANGELOG
41+
permission-pull-requests: write
4542

4643
- name: Update release tracker
47-
if: |
48-
github.event.action == 'closed' &&
49-
github.event.pull_request.merged == true
5044
env:
51-
GITHUB_USER: 1gtm
52-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
45+
GITHUB_USER: ${{ github.actor }}
46+
GITHUB_TOKEN: ${{ steps.lgtm-app-token.outputs.token }}
5347
run: |
5448
./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)