Skip to content

Upload to R2 with the AWS CLI instead of a third-party action - #191

Merged
Jesse Hills (jesserockz) merged 1 commit into
mainfrom
jesserockz-2026-763
Oct 14, 2026
Merged

Jesse Hills (jesserockz) merged 1 commit into
mainfrom
jesserockz-2026-763

Conversation

@jesserockz

Copy link
Copy Markdown
Member

Replaces ryand56/r2-upload-action in upload-to-r2.yml and promote-r2.yml with a plain aws s3 cp --recursive step. R2 is S3-compatible and the AWS CLI ships in the runner image (AWS CLI 2.36.2 on the Ubuntu 24.04 image, 2.36.16 on 26.04, both listed under CLI Tools in actions/runner-images), so the upload needs no third-party action and no install step.

The main motivation is credential exposure: the action is a JavaScript action that received CLOUDFLARE_R2_SECRET_ACCESS_KEY in its environment and ran a bundled aws-sdk-js plus whatever else it shipped. SHA-pinning froze that code but also froze its dependencies. Removing it takes third-party code off the path that holds R2 write credentials for firmware.esphome.io.

I considered factoring the shared step into a composite action in this repo, but a relative uses: ./.github/actions/... inside a called reusable workflow resolves against the caller's workspace rather than this repo, and these workflows do no checkout. It would mean adding an actions/checkout of esphome/workflows at a hardcoded self-referential ref to every consumer run, which is not worth it for eight lines used twice.

Behaviour is unchanged

  • Key layout is identical. The action computed destination-dir + the path relative to source-dir; aws s3 cp <dir> s3://bucket/prefix/ --recursive does the same, so files/<device>/<version>/manifest.json still lands at <directory>/<device>/<version>/manifest.json.
  • Content types match where it matters: .json resolves to application/json (the web installer fetches the manifests), and .bin / .elf end up as octet-stream either way.
  • cp rather than sync, deliberately: promote re-uploads a manifest whose size may be unchanged, and sync would skip it.
  • ${DIRECTORY%/}/ strips a trailing slash, so a caller passing foo/ no longer produces a foo// prefix. The previous ${{ inputs.directory }}/ would have.
  • Uploads now run with the CLI's default concurrency instead of the action's serial JavaScript loop.

Things worth knowing

AWS_REQUEST_CHECKSUM_CALCULATION: when_required guards against the CRC32 trailers AWS CLI 2.23 and newer send by default, which R2 has intermittently rejected. Cloudflare's current docs no longer mention the workaround, but it costs nothing to keep.

The tradeoff is that the CLI version now floats with the runner image where the pinned action was frozen. That is the failure mode that bit R2 users in January 2025, when an image bump to CLI 2.23 started breaking uploads. Worth noting the pinned action was not immune to that class of bug either, since aws-sdk-js v3.729.0 had the same breakage. If we would rather have determinism, the alternative is installing a pinned CLI in the step at roughly 15s per job.

CI has no R2 secrets, so nothing here exercises the upload path. It is unverified until a real release run. yamllint passes, and actionlint with shellcheck reports nothing on the new steps.

R2 is S3-compatible and the AWS CLI ships in the runner image, so the
upload needs no third-party action. This takes third-party code off the
path that holds the Cloudflare R2 write credentials.

Keeps the same key layout: aws s3 cp --recursive maps the source
directory's contents under the destination prefix exactly as the action's
source-dir/destination-dir pair did. Uses cp rather than sync so promote
always rewrites a manifest whose size happens to be unchanged, and
strips a trailing slash from the directory input so a caller passing
"foo/" no longer yields a "foo//" prefix.
@jesserockz
Jesse Hills (jesserockz) merged commit 31d160e into main Oct 14, 2026
39 checks passed
@jesserockz
Jesse Hills (jesserockz) deleted the jesserockz-2026-763 branch October 14, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant