Skip to content

Commit e9b492e

Browse files
committed
ci: harden github actions permissions for scorecard compliance
Implement OpenSSF scorecard security recommendations to improve workflow security - Set default `read-all` permissions at the workflow level across all workflows - Define minimal job-level permissions following least privilege principle - Refactor release workflow to separate build and release steps - Add scorecard job to PR checks workflow - Reduce artifact retention to 1 day for scorecard results Signed-off-by: vprashar2929 <[email protected]>
1 parent 81da201 commit e9b492e

File tree

11 files changed

+97
-28
lines changed

11 files changed

+97
-28
lines changed

.github/workflows/assign-labels.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ name: Assign Labels
33
on: # yamllint disable-line rule:truthy
44
pull_request_target:
55

6+
# default permissions as read only
7+
permissions: read-all
8+
69
jobs:
710
assign-labels:
811
permissions:
9-
contents: read
1012
pull-requests: write
1113
issues: write
1214
runs-on: ubuntu-latest

.github/workflows/check-x-crypto-deps.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ name: Check x/crypto
33
on: # yamllint disable-line rule:truthy
44
pull_request:
55

6+
# default permissions as read only
7+
permissions: read-all
8+
69
jobs:
710
check-x-crypto-deps:
811
permissions:
9-
contents: read
1012
pull-requests: write
1113
runs-on: ubuntu-latest
1214
name: Check x/crypto Dependencies in Pull Request

.github/workflows/config-change.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: Check Config Changes
33
on: # yamllint disable-line rule:truthy
44
pull_request:
55

6+
# default permissions as read only
7+
permissions: read-all
8+
69
jobs:
710
check-changes:
811
runs-on: ubuntu-latest

.github/workflows/k8s-bm.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ name: Build and Deploy K8s on Self Hosted BM
33
on: # yamllint disable-line rule:truthy
44
pull_request:
55

6-
permissions:
7-
pull-requests: write
8-
contents: write
6+
# default permissions as read only
7+
permissions: read-all
98

109
jobs:
1110
check-changes:

.github/workflows/pr-checks.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: PR Checks
33
on: # yamllint disable-line rule:truthy
44
pull_request:
55

6+
# default permissions as read only
7+
permissions: read-all
8+
69
jobs:
710
check-changes:
811
runs-on: ubuntu-latest
@@ -97,10 +100,19 @@ jobs:
97100
test-and-codecov:
98101
needs: check-changes
99102
if: needs.check-changes.outputs.changes == 'true'
103+
permissions:
104+
contents: read
100105
uses: ./.github/workflows/test-and-codecov.yaml
101106
secrets:
102107
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
103108

109+
scorecard:
110+
permissions:
111+
contents: read
112+
security-events: write
113+
id-token: write
114+
uses: ./.github/workflows/scorecard.yml
115+
104116
pre-commit:
105117
runs-on: ubuntu-latest
106118
steps:

.github/workflows/pr-comment.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ on: # yamllint disable-line rule:truthy
1111
types:
1212
- completed
1313

14-
permissions:
15-
pull-requests: write
16-
actions: read
14+
# default permissions as read only
15+
permissions: read-all
1716

1817
jobs:
1918
comment-on-pr:
19+
permissions:
20+
pull-requests: write
2021
runs-on: ubuntu-latest
2122
# Only run if the triggering workflow succeeded
2223
if: github.event.workflow_run.conclusion == 'success'

.github/workflows/profiling.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Profiling Report
22
on: # yamllint disable-line rule:truthy
33
pull_request:
44

5+
# default permissions as read only
6+
permissions: read-all
7+
58
jobs:
69
check-changes:
710
runs-on: ubuntu-latest

.github/workflows/push.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@ on: # yamllint disable-line rule:truthy
44
push:
55
branches: [main]
66

7+
# default permissions as read only
8+
permissions: read-all
9+
710
jobs:
811
test-and-codecov:
12+
permissions:
13+
contents: read
914
uses: ./.github/workflows/test-and-codecov.yaml
1015
secrets:
1116
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1217

13-
# for each PR merge, openSSF scan
1418
scorecard:
19+
permissions:
20+
contents: read
21+
security-events: write
22+
id-token: write
1523
uses: ./.github/workflows/scorecard.yml
1624

1725
publish:

.github/workflows/release.yaml

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ on: # yamllint disable-line rule:truthy
55
tags:
66
- v[0-9]+.[0-9]+.[0-9]+
77

8-
jobs:
9-
release:
10-
permissions:
11-
contents: write
8+
# default permissions as read only
9+
permissions: read-all
1210

11+
jobs:
12+
build:
1313
runs-on: ubuntu-latest
1414
env:
1515
IMG_BASE: quay.io/sustainable_computing_io
16-
1716
steps:
1817
- name: Checkout source
1918
uses: actions/checkout@v5
@@ -90,19 +89,14 @@ jobs:
9089
# Currently the binary is built for linux-amd64 only
9190
tar -czvf bin/kepler-${VERSION}.linux-amd64.tar.gz bin/kepler
9291
93-
- name: Create GitHub Release
94-
uses: softprops/action-gh-release@v2
92+
- name: Upload Release Artifacts
93+
uses: actions/upload-artifact@v4
9594
with:
96-
tag_name: ${{ github.ref_name }}
97-
name: release-${{ steps.version.outputs.version }}
98-
generate_release_notes: true
99-
draft: false
100-
make_latest: true
101-
files: |
95+
name: release-artifacts
96+
retention-days: 1 # Keep the artifacts for 1 day
97+
path: |
10298
helm-releases/*.tgz
10399
bin/*.tar.gz
104-
env:
105-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106100
107101
- name: Push Image
108102
shell: bash
@@ -116,3 +110,38 @@ jobs:
116110
# Remove 'v' prefix from version
117111
CHART_VERSION=${VERSION#v}
118112
helm push helm-releases/kepler-helm-${CHART_VERSION}.tgz oci://${{ env.IMG_BASE }}/charts
113+
114+
release:
115+
needs: build
116+
permissions:
117+
# contents: write is required for publishing Github Releases
118+
# This follows Github's recommended pattern: top-level read-all with minimal job-level permissions
119+
# See: https://github.com/softprops/action-gh-release?tab=readme-ov-file#permissions
120+
contents: write
121+
runs-on: ubuntu-latest
122+
steps:
123+
- name: Download Release Artifacts
124+
uses: actions/download-artifact@v4
125+
with:
126+
name: release-artifacts
127+
128+
- name: Extract version
129+
shell: bash
130+
id: version
131+
run: |
132+
TAG_NAME=${{ github.ref_name }}
133+
echo "version=$TAG_NAME" >> "$GITHUB_OUTPUT"
134+
135+
- name: Create GitHub Release
136+
uses: softprops/action-gh-release@v2
137+
with:
138+
tag_name: ${{ github.ref_name }}
139+
name: release-${{ steps.version.outputs.version }}
140+
generate_release_notes: true
141+
draft: false
142+
make_latest: true
143+
files: |
144+
helm-releases/*.tgz
145+
bin/*.tar.gz
146+
env:
147+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/scorecard.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ name: Scorecard supply-chain security
66
on: # yamllint disable-line rule:truthy
77
workflow_call:
88

9-
# Declare default permissions as read only.
10-
permissions: read-all
9+
# Restrict permissions for GITHUB_TOKEN by default.
10+
# Each job must explicitly declare what it needs.
11+
permissions: {}
1112

1213
jobs:
1314
analysis:
1415
name: Scorecard analysis
1516
runs-on: ubuntu-latest
1617
permissions:
18+
# Needed to checkout code.
19+
contents: read
1720
# Needed to upload the results to code-scanning dashboard.
1821
security-events: write
1922
# Needed to publish results and get a badge (see publish_results below).
2023
id-token: write
2124
# Uncomment the permissions below if installing in a private repository.
22-
# contents: read
2325
# actions: read
2426

2527
steps:
@@ -55,7 +57,7 @@ jobs:
5557
with:
5658
name: SARIF file
5759
path: scorecard-results.sarif
58-
retention-days: 5
60+
retention-days: 1 # Keeping the results for 1 day
5961

6062
# Upload the results to GitHub's code scanning dashboard.
6163
- name: Upload to code-scanning

0 commit comments

Comments
 (0)