Skip to content

Commit 97c0d1d

Browse files
authored
ci: drop rocksbot for collaborators list (canonical#309)
This is a CI security enhancement. In canonical#284, we improved the security of the build CI workflow, ensuring the whole CI job wouldn't have unnecessary write permissions to the repository, instead shifting towards a fine grained personal token that would only be used within a single, conditional step that only ran on GitHub release events. NEW: this PR goes one step further by removing the need to have a bot account (which owns the aforementioned fine grained personal token) with write permissions in the repository's collaborators list. Instead, this PR splits the privileged step into a separate privileged job. This means the new job can use the ephemeral GITHUB_TOKEN to perform the privileged step, without giving unnecessary privileges to other jobs&steps of the workflow. Closes: canonical#308
1 parent 3323d36 commit 97c0d1d

1 file changed

Lines changed: 30 additions & 32 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
build-chisel:
1717
name: Build Chisel
1818
runs-on: ubuntu-22.04
19+
outputs:
20+
chisel_version: ${{ steps.build.outputs.CHISEL_VERSION }}
1921
strategy:
2022
fail-fast: false
2123
matrix:
@@ -109,37 +111,33 @@ jobs:
109111
${{ steps.archive.outputs.ARCHIVE_FILE }}
110112
${{ steps.archive.outputs.ARCHIVE_FILE_SHA384 }}
111113
112-
- name: Upload archive to release
114+
upload-release:
115+
name: Upload to Release
116+
if: ${{ github.event_name == 'release' }}
117+
needs: build-chisel
118+
runs-on: ubuntu-24.04
119+
# This job only runs on release events (which can only be triggered by users
120+
# with "write" access) and the only thing it does is to upload the artifacts
121+
# to the release. It does not build anything.
122+
123+
# This job splits the privileged step below from the above job, allowing us to
124+
# use the GITHUB_TOKEN safely, while also removing the need to have a bot account
125+
# as a repo collaborator.
126+
127+
permissions:
128+
contents: write # required for uploading artifacts to a release.
129+
steps:
130+
- name: Download all artifacts
131+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
132+
133+
- name: Upload archives to release
113134
env:
114-
CHISEL_VERSION: ${{ steps.build.outputs.CHISEL_VERSION }}
115-
ARCHIVE_FILE: ${{ steps.archive.outputs.ARCHIVE_FILE }}
116-
ARCHIVE_FILE_SHA384: ${{ steps.archive.outputs.ARCHIVE_FILE_SHA384 }}
117-
# If triggered by a "release" event, this additional and final step
118-
# of the job will upload the Chisel binaries (and checksums) to the corresponding
119-
# GitHub release. This operation NEEDS "contents: write" permissions.
120-
# Security concerns:
121-
# - Why a custom token instead of GITHUB_TOKEN?
122-
# - The GITHUB_TOKEN only has "readonly" permissions by default.
123-
# - Why not add "permissions: {contents:write}" to this workflow [1]?
124-
# - While this would elevate the GITHUB_TOKEN permissions to what we require, it
125-
# would do it for the entire job (ALL steps), which increases the attack surface unnecessarily.
126-
# - Why is it safer to use the ROCKSBOT_CHISEL_CONTENTS token?
127-
# 1. it is limited to this step of the workflow (unlike GITHUB_TOKEN, which is always available)
128-
# 2. this particular step only runs when the "event == release"
129-
# 3. the step's script doesn't rely on 3rd party actions
130-
# 4. the current workflow triggers are all maintainer-driven, except for "pull_request",
131-
# but the latter is designed not to use any secrets during execution from fork-based PRs
132-
# - NOTE: in fact, custom secrets are never passed to fork-based PR workflows, unlike GITHUB_TOKEN
133-
# which is available with "readonly" permissions [2]
134-
# - How could this token be compromised?
135-
# - By unintentionally merging a change that allows this step to run unvetted scripts
136-
# (either via a "pull_request_target", use of an insecure 3rd party action, or malicious changes to the
137-
# current script)
138-
# [1] https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#permissions
139-
# [2] https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflows-in-forked-repositories
140-
GITHUB_TOKEN: ${{ secrets.ROCKSBOT_CHISEL_CONTENTS }}
141-
if: ${{ github.event_name == 'release' }}
135+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
136+
CHISEL_VERSION: ${{ needs.build-chisel.outputs.chisel_version }}
142137
run: |
143-
echo "Uploading $ARCHIVE_FILE to release $CHISEL_VERSION"
144-
gh release upload $CHISEL_VERSION $ARCHIVE_FILE
145-
gh release upload $CHISEL_VERSION $ARCHIVE_FILE_SHA384
138+
for dir in chisel_*/; do
139+
for file in "$dir"*; do
140+
echo "Uploading $file to release $CHISEL_VERSION"
141+
gh release upload "$CHISEL_VERSION" "$file" --repo "$GITHUB_REPOSITORY"
142+
done
143+
done

0 commit comments

Comments
 (0)