Skip to content

Commit f0e1f55

Browse files
authored
workflows: improve security posture (#522)
- Pin actions used to a Git SHA-1 hash instead of a tag - Don't persist credentials when using actions/checkout, except where needed (I did not find any places where it is needed) - Use `gh` CLI to delete/recreate dev release instead of using third-party actions - Use `gh` CLI to create tagged releases instead of using third-party actions - Avoid cache usage when producing release artifacts (to prevent cache poisoning attacks) Signed-off-by: Caleb Xu <[email protected]>
1 parent 37fd981 commit f0e1f55

File tree

9 files changed

+81
-65
lines changed

9 files changed

+81
-65
lines changed

.github/workflows/build.yaml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ jobs:
1717

1818
steps:
1919
- name: Checkout main branch
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
21+
with:
22+
persist-credentials: false
2123

2224
- name: Checkout PR branch
23-
uses: actions/checkout@v4
25+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2426
with:
2527
ref: ${{ github.event.pull_request.head.ref }}
2628
repository: ${{ github.event.pull_request.head.repo.full_name }}
2729
path: "chart-verifier"
30+
persist-credentials: false
2831

2932
- name: Setup Go
30-
uses: actions/setup-go@v5
33+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
3134
with:
3235
go-version-file: ./chart-verifier/go.mod
3336

@@ -76,7 +79,7 @@ jobs:
7679
echo "date=$(/bin/date -u "+%Y%m%d")" | tee -a $GITHUB_OUTPUT
7780
shell: bash
7881

79-
- uses: actions/cache@v4
82+
- uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
8083
id: cache
8184
with:
8285
path: ./chart-verifier/oc
@@ -178,17 +181,21 @@ jobs:
178181
# check if version file was changed
179182
ve1/bin/release-checker --version="${PR_VERSION}"
180183
184+
# TODO: Investigate if it's possible to do this using the `gh` CLI tool instead of
185+
# relying on a third-party action.
181186
- name: Approve PR
182187
id: approve_pr
183188
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
184-
uses: hmarr/auto-approve-action@v4
189+
uses: hmarr/auto-approve-action@f0939ea97e9205ef24d872e76833fa908a770363 # v4.0.0
185190
with:
186191
github-token: ${{ secrets.GITHUB_TOKEN }}
187192

193+
# TODO: Investigate if it's possible to do this using the `gh` CLI tool instead of
194+
# relying on a third-party action.
188195
- name: Merge PR
189196
id: merge_pr
190197
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
191-
uses: pascalgn/[email protected].3
198+
uses: pascalgn/automerge-action@7961b8b5eec56cc088c140b56d864285eabd3f67 # v0.16.4
192199
env:
193200
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
194201
MERGE_METHOD: squash
@@ -202,10 +209,12 @@ jobs:
202209
export ORIGIN_MAIN_SHA=$(git rev-parse origin/main)
203210
echo "origin_main_sha=$ORIGIN_MAIN_SHA" | tee -a $GITHUB_OUTPUT
204211
212+
# TODO: Investigate if it's possible to do this using the `gh` CLI tool instead of
213+
# relying on a third-party action.
205214
- name: Create release tag
206215
id: create_release_tag
207216
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
208-
uses: mathieudutour/[email protected]
217+
uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b # v6.2
209218
with:
210219
# It is necessary to use a Personal Access Token here rather than the usual GITHUB_TOKEN, as this
211220
# step should trigger the release.yaml workflow, and events (such as tags) triggered by the

.github/workflows/codeql.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ jobs:
3636

3737
steps:
3838
- name: Checkout repository
39-
uses: actions/checkout@v4
39+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
40+
with:
41+
persist-credentials: false
4042

4143
# Initializes the CodeQL tools for scanning.
4244
- name: Initialize CodeQL
43-
uses: github/codeql-action/init@v3
45+
uses: github/codeql-action/init@76621b61decf072c1cee8dd1ce2d2a82d33c17ed # v3.29.8
4446
with:
4547
languages: ${{ matrix.language }}
4648
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -65,12 +67,12 @@ jobs:
6567

6668
- name: Perform CodeQL Analysis
6769
id: codeql_analysis
68-
uses: github/codeql-action/analyze@v3
70+
uses: github/codeql-action/analyze@76621b61decf072c1cee8dd1ce2d2a82d33c17ed # v3.29.8
6971

7072
- name: Send message to helm_dev slack channel
7173
id: notify_dev
7274
if: ${{ always() && github.event_name == 'schedule' && steps.codeql_analysis.conclusion != 'success' }}
73-
uses: archive/github-actions-slack@v2.9.0
75+
uses: archive/github-actions-slack@c643e5093620d65506466f2c9b317d5d29a5e517 # v2.10.1
7476
with:
7577
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
7678
slack-channel: C02979BDUPL
@@ -85,7 +87,7 @@ jobs:
8587
- name: Send message to helm_notify slack channel
8688
id: notify
8789
if: ${{ always() && github.event_name == 'schedule' && steps.codeql_analysis.conclusion == 'success' }}
88-
uses: archive/github-actions-slack@v2.9.0
90+
uses: archive/github-actions-slack@c643e5093620d65506466f2c9b317d5d29a5e517 # v2.10.1
8991
with:
9092
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
9193
slack-channel: C04K1ARMH8A

.github/workflows/dev_release.yaml

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ jobs:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- name: Checkout code
22-
uses: actions/checkout@v4
22+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23+
with:
24+
persist-credentials: false
2325

2426
- name: Setup Go
25-
uses: actions/setup-go@v5
27+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
2628
with:
2729
go-version-file: go.mod
2830

@@ -47,30 +49,19 @@ jobs:
4749
# check if release file only is included in PR
4850
ve1/bin/tar-file --release="${DEV_RELEASE}"
4951
50-
- name: Delete previous release and tag
51-
id: delete-previous
52+
- name: Create development tag and release
5253
if: ${{ steps.create-tarfile.outcome == 'success' }}
53-
uses: dev-drprasad/[email protected]
54-
with:
55-
delete_release: true # default: false
56-
tag_name: ${{ env.DEV_RELEASE }} # tag name to delete
57-
github_token: ${{ secrets.GITHUB_TOKEN }}
58-
59-
# The next step seems to periodically create a draft release.
60-
# We think this is because of a race condition.
61-
# Force a wait after the previous release was deleted.
62-
- name: Sleep and to buffer release recreation
63-
id: sleep-after-delete-previous
64-
run: sleep 8
54+
env:
55+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
TARBALL_FULL_NAME: ${{ steps.create-tarfile.outputs.tarball_full_name }}
57+
run: |
58+
gh release delete "${DEV_RELEASE}" --cleanup-tag --yes
6559
66-
- name: Create the release
67-
id: create_release
68-
if: ${{ steps.delete-previous.outcome == 'success' && steps.sleep-after-delete-previous.outcome == 'success' }}
69-
uses: softprops/action-gh-release@v2
70-
with:
71-
tag_name: ${{ env.DEV_RELEASE }}
72-
body: "Development release created with each merge into the main branch."
73-
files: ${{ steps.create-tarfile.outputs.tarball_full_name }}
74-
prerelease: true
75-
draft: false
76-
token: ${{ secrets.GITHUB_TOKEN }}
60+
# The next step seems to periodically create a draft release.
61+
# We think this is because of a race condition.
62+
# Force a wait after the previous release was deleted.
63+
sleep 8
64+
65+
gh release create "${DEV_RELEASE}" "${TARBALL_FULL_NAME}" \
66+
--notes "Development release created with each merge into the main branch." \
67+
--prerelease

.github/workflows/golang-style.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout code
13-
uses: actions/checkout@v4
13+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
14+
with:
15+
persist-credentials: false
1416

1517
- name: Setup Go
16-
uses: actions/setup-go@v5
18+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
1719
with:
1820
go-version-file: go.mod
1921

.github/workflows/main.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Checkout code
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
21+
with:
22+
persist-credentials: false
2123

2224
- name: Get commit ID
2325
id: get_commit_id
@@ -39,7 +41,7 @@ jobs:
3941
4042
- name: Push to quay.io
4143
id: push_to_quay
42-
uses: redhat-actions/push-to-registry@v2
44+
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8
4345
with:
4446
image: chart-verifier
4547
tags: |

.github/workflows/python-style.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout code
19-
uses: actions/checkout@v4
19+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
20+
with:
21+
persist-credentials: false
2022

2123
- name: Set up Python
2224
uses: ./.github/actions/setup-python

.github/workflows/release.yaml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@ jobs:
4141
id-token: write
4242
steps:
4343
- name: Checkout repository
44-
uses: actions/checkout@v4
44+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
45+
with:
46+
persist-credentials: false
4547

4648
- name: Setup Go
47-
uses: actions/setup-go@v5
49+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
4850
with:
4951
go-version-file: go.mod
52+
cache: false
5053

5154
- name: Install cosign
52-
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
55+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0
5356
with:
5457
cosign-release: 'v2.2.4'
5558

@@ -89,7 +92,7 @@ jobs:
8992
- name: Generate SBOM
9093
continue-on-error: true
9194
id: generate_sbom
92-
uses: anchore/sbom-action@v0
95+
uses: anchore/sbom-action@7b36ad622f042cab6f59a75c2ac24ccb256e9b45 # v0.20.4
9396
with:
9497
# Setting path to null works around this bug:
9598
# https://github.com/anchore/sbom-action/issues/389
@@ -114,17 +117,18 @@ jobs:
114117
id: release_body
115118
run: echo "release_body=$(ve1/bin/print-release-body)" | tee -a $GITHUB_OUTPUT
116119

117-
- name: Create the release
118-
id: create_release
119-
uses: softprops/action-gh-release@v2
120-
with:
121-
tag_name: ${{ steps.get_tag.outputs.release_version }}
122-
body: ${{ steps.release_body.outputs.release_body }}
123-
files: |
124-
${{ steps.build_bin.outputs.tarball_path }}
125-
${{ steps.generate_sbom_filename.outputs.sbom_filename }}
120+
- name: Create tag and release
126121
env:
127-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
TAG_NAME: ${{ steps.get_tag.outputs.release_version }}
123+
RELEASE_NOTES: ${{ steps.release_body.outputs.release_body }}
124+
TARBALL_PATH: ${{ steps.build_bin.outputs.tarball_path }}
125+
SBOM_FILENAME: ${{ steps.generate_sbom_filename.outputs.sbom_filename }}
126+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127+
run: |
128+
gh release create "${TAG_NAME}" \
129+
"${TARBALL_PATH}" \
130+
"${SBOM_FILENAME}" \
131+
--notes "${RELEASE_NOTES}"
128132
129133
- name: Build container images
130134
id: build_container_images
@@ -139,7 +143,7 @@ jobs:
139143
140144
- name: Push to quay.io
141145
id: push_to_quay
142-
uses: redhat-actions/push-to-registry@v2
146+
uses: redhat-actions/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8
143147
with:
144148
image: ${{ env.IMAGE_NAME }}
145149
tags: |

.github/workflows/scan-branch-sbom.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Checkout repo
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
21+
with:
22+
persist-credentials: false
2123
- name: Generate SBOM
22-
uses: anchore/sbom-action@v0
24+
uses: anchore/sbom-action@7b36ad622f042cab6f59a75c2ac24ccb256e9b45 # v0.20.4
2325
with:
2426
# Setting path to null works around this bug:
2527
# https://github.com/anchore/sbom-action/issues/389
@@ -31,7 +33,7 @@ jobs:
3133
upload-release-assets: false
3234
- name: Scan SBOM
3335
id: scan
34-
uses: anchore/scan-action@v3
36+
uses: anchore/scan-action@1638637db639e0ade3258b51db49a9a137574c3e # v6.5.1
3537
continue-on-error: true
3638
with:
3739
sbom: temporary.sbom.spdx.json
@@ -45,7 +47,7 @@ jobs:
4547
- name: Send message on scan failure
4648
id: notify
4749
if: ${{ steps.scan.outcome == 'failure' && inputs.notify-on-failure }}
48-
uses: archive/github-actions-slack@v2.9.0
50+
uses: archive/github-actions-slack@c643e5093620d65506466f2c9b317d5d29a5e517 # v2.10.1
4951
with:
5052
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
5153
slack-channel: C02979BDUPL

.github/workflows/vulnerability.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212

1313
steps:
1414
- name: Checkout repository
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
16+
with:
17+
persist-credentials: false
1618

1719
- name: Run Gosec Security Scanner
1820
run: |
@@ -26,7 +28,7 @@ jobs:
2628
fi
2729
2830
- name: Upload SARIF file
29-
uses: github/codeql-action/upload-sarif@v3
31+
uses: github/codeql-action/upload-sarif@76621b61decf072c1cee8dd1ce2d2a82d33c17ed # v3.29.8
3032
if: always()
3133
with:
3234
# Path to SARIF file relative to the root of the repository

0 commit comments

Comments
 (0)