|
16 | 16 | build-chisel: |
17 | 17 | name: Build Chisel |
18 | 18 | runs-on: ubuntu-22.04 |
| 19 | + outputs: |
| 20 | + chisel_version: ${{ steps.build.outputs.CHISEL_VERSION }} |
19 | 21 | strategy: |
20 | 22 | fail-fast: false |
21 | 23 | matrix: |
@@ -109,37 +111,33 @@ jobs: |
109 | 111 | ${{ steps.archive.outputs.ARCHIVE_FILE }} |
110 | 112 | ${{ steps.archive.outputs.ARCHIVE_FILE_SHA384 }} |
111 | 113 |
|
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 |
113 | 134 | 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 }} |
142 | 137 | 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