Skip to content

Instantly share code, notes, and snippets.

@davej
Created February 15, 2025 20:58
Show Gist options
  • Save davej/8adfd3f02210e60a7150d24a3d4f67a8 to your computer and use it in GitHub Desktop.
Save davej/8adfd3f02210e60a7150d24a3d4f67a8 to your computer and use it in GitHub Desktop.
Get S3 Credentials From Cloudflare Token
# Specify these vars first
export CLOUDFLARE_ACCOUNT_ID=24bac...
export CLOUDFLARE_API_TOKEN=eGCxnU...
# then derive the AWS S3 credentials
export AWS_ACCESS_KEY_ID=$(curl -s https://api.cloudflare.com/client/v4/user/tokens/verify -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" | jq -r '.result.id')
export AWS_SECRET_ACCESS_KEY=$(echo -n $CLOUDFLARE_API_TOKEN | shasum -a 256 | awk '{print $1}')
export AWS_ENDPOINT_URL=https://$CLOUDFLARE_ACCOUNT_ID.r2.cloudflarestorage.com
# output the credentials
echo $AWS_ACCESS_KEY_ID
echo $AWS_SECRET_ACCESS_KEY
echo $AWS_ENDPOINT_URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment