Skip to content

Object Read/Write API tokens can't upload to R2, getting a 403 response #9235

Description

@abrahamhurtado

Which Cloudflare product(s) does this pertain to?

R2

What versions & operating system are you using?

Wrangler v4.14.0, node v20.16.0, macOS 14.7

Please provide a link to a minimal reproduction

No response

Describe the Bug

When attempting to upload to a R2 bucket, using an Account API token with the "Object Read & Write" permissions and the wrangler CLI tool, a 403 Forbidden response is returned back. Environment variables CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID are properly set up.

If token permissions are elevated to "Admin Read & Write", upload works. Is this expected? To require elevated permissions to upload objects?

Please provide any relevant error logs

WRANGLER_LOG_SANITIZE=false WRANGLER_LOG=debug npx wrangler r2 object put <bucket_name>/index.esm.js --file=./dist/libs/<folder_name>/index.esm.js --remote --content-type="text/javascript"
🪵  Writing logs to "/Users/<REDACTED>/Library/Preferences/.wrangler/logs/wrangler-2025-05-13_18-21-00_278.log"
Metrics dispatcher: Dispatching disabled - would have sent {"deviceId":"<REDACTED>","event":"wrangler command started","timestamp":1747160460331,"properties":{"amplitude_session_id":1747160460329,"amplitude_event_id":0,"wranglerVersion":"4.14.0","osPlatform":"Mac OS","osVersion":"Darwin Kernel Version 23.6.0: Wed Jul 31 20:48:52 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_T6020","nodeVersion":20,"packageManager":"npm","isFirstUsage":false,"configFileType":"none","isCI":false,"isPagesCI":false,"isWorkersCI":false,"isInteractive":true,"hasAssets":false,"argsUsed":["contentType","ct","f","file","j","remote"],"argsCombination":"contentType, ct, f, file, j, remote","command":"wrangler r2 object put","args":{"file":"<REDACTED>","f":"<REDACTED>","remote":true,"contentType":"<REDACTED>","ct":"<REDACTED>","xJsonConfig":true,"j":true,"objectPath":"<REDACTED>"}}}.
.env file not found at ".env". Continuing... For more details, refer to https://developers.cloudflare.com/workers/wrangler/system-environment-variables/

 ⛅️ wrangler 4.14.0 (update available 4.15.0)
-------------------------------------------------------

Resource location: remote
Creating object "index.esm.js" in bucket "<REDACTED>".
Retrieving cached values for account from node_modules/.cache/wrangler
Saving to cache: {"account":{"id":"<REDACTED>","name":""}}

✘ [ERROR] Failed to fetch /accounts/<REDACTED>/r2/buckets/<REDACTED>/objects/index.esm.js - 403: Forbidden);


Error: Failed to fetch /accounts/<REDACTED>/r2/buckets/<REDACTED>/objects/index.esm.js - 403: Forbidden);
    at fetchR2Objects (/Users/<REDACTED>/<project_name>/node_modules/wrangler/wrangler-dist/cli.js:91452:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async putR2Object (/Users/<REDACTED>/<project_name>/node_modules/wrangler/wrangler-dist/cli.js:102113:18)
    at async Object.handler (/Users/<REDACTED>/<project_name>/node_modules/wrangler/wrangler-dist/cli.js:133813:7)
    at async Object.handler (/Users/<REDACTED>/<project_name>/node_modules/wrangler/wrangler-dist/cli.js:115146:7)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions