-
Notifications
You must be signed in to change notification settings - Fork 217
ci: harden github actions permissions for scorecard compliance #2345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,22 @@ on: # yamllint disable-line rule:truthy | |
| push: | ||
| branches: [main] | ||
|
|
||
| # default permissions as read only | ||
| permissions: read-all | ||
|
|
||
| jobs: | ||
| test-and-codecov: | ||
| permissions: | ||
| contents: read | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will codecov write anything? as this job will run after push, can we double check with document or anyway to test it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, Codecov does not write anything to the repository. |
||
| uses: ./.github/workflows/test-and-codecov.yaml | ||
| secrets: | ||
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
|
|
||
| # for each PR merge, openSSF scan | ||
| scorecard: | ||
| permissions: | ||
| contents: read | ||
| security-events: write | ||
| id-token: write | ||
| uses: ./.github/workflows/scorecard.yml | ||
|
|
||
| publish: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,14 @@ | |
| tags: | ||
| - v[0-9]+.[0-9]+.[0-9]+ | ||
|
|
||
| jobs: | ||
| release: | ||
| permissions: | ||
| contents: write | ||
| # default permissions as read only | ||
| permissions: read-all | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| IMG_BASE: quay.io/sustainable_computing_io | ||
|
|
||
| steps: | ||
| - name: Checkout source | ||
| uses: actions/checkout@v5 | ||
|
|
@@ -90,19 +89,14 @@ | |
| # Currently the binary is built for linux-amd64 only | ||
| tar -czvf bin/kepler-${VERSION}.linux-amd64.tar.gz bin/kepler | ||
| - name: Create GitHub Release | ||
| uses: softprops/action-gh-release@v2 | ||
| - name: Upload Release Artifacts | ||
| uses: actions/upload-artifact@v4 | ||
|
||
| with: | ||
Check warningCode scanning / Scorecard Pinned-Dependencies Medium
score is 0: third-party GitHubAction not pinned by hash
Remediation tip: update your workflow using https://app.stepsecurity.io Click Remediation section below for further remediation help |
||
| tag_name: ${{ github.ref_name }} | ||
| name: release-${{ steps.version.outputs.version }} | ||
| generate_release_notes: true | ||
| draft: false | ||
| make_latest: true | ||
| files: | | ||
| name: release-artifacts | ||
| retention-days: 1 # Keep the artifacts for 1 day | ||
| path: | | ||
| helm-releases/*.tgz | ||
| bin/*.tar.gz | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Push Image | ||
| shell: bash | ||
|
|
@@ -116,3 +110,38 @@ | |
| # Remove 'v' prefix from version | ||
| CHART_VERSION=${VERSION#v} | ||
| helm push helm-releases/kepler-helm-${CHART_VERSION}.tgz oci://${{ env.IMG_BASE }}/charts | ||
| release: | ||
| needs: build | ||
| permissions: | ||
| # contents: write is required for publishing Github Releases | ||
| # This follows Github's recommended pattern: top-level read-all with minimal job-level permissions | ||
| # See: https://github.com/softprops/action-gh-release?tab=readme-ov-file#permissions | ||
| contents: write | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Download Release Artifacts | ||
| uses: actions/download-artifact@v4 | ||
Check warningCode scanning / Scorecard Pinned-Dependencies Medium
score is 0: GitHub-owned GitHubAction not pinned by hash
Remediation tip: update your workflow using https://app.stepsecurity.io Click Remediation section below for further remediation help |
||
| with: | ||
| name: release-artifacts | ||
|
|
||
| - name: Extract version | ||
| shell: bash | ||
| id: version | ||
| run: | | ||
| TAG_NAME=${{ github.ref_name }} | ||
| echo "version=$TAG_NAME" >> "$GITHUB_OUTPUT" | ||
| - name: Create GitHub Release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: ${{ github.ref_name }} | ||
| name: release-${{ steps.version.outputs.version }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. release-${{ github.ref_name }} ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes we can use |
||
| generate_release_notes: true | ||
| draft: false | ||
| make_latest: true | ||
| files: | | ||
| helm-releases/*.tgz | ||
| bin/*.tar.gz | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a question here for this.
if https://github.com/sustainable-computing-io/kepler/pull/2345/files#diff-7a6a4578fe04c4fc86b28e2dc9672e48d1a9f721315e540b90bac0ef12263053R6-R8 set global permission for all jobs, why do we need a permission setting at here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using reusable workflows (jobs with the uses: keyword), permissions are not inherited from the
global permissions setting at the workflow level. This is a security feature in GitHub Actions.
The global permissions: read-all in the workflow only applies to regular jobs that run steps directly.
For jobs that call reusable workflows, we must explicitly declare what permissions should be passed
to the called workflow.
Without the explicit permissions, the test-and-codecov.yaml workflow would receive
no permissions (or minimal default permissions), which could cause it to fail.