Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Permission denied (os error 13) #1925

Closed
bramses opened this issue May 20, 2021 · 10 comments
Closed

Permission denied (os error 13) #1925

bramses opened this issue May 20, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@bramses
Copy link

bramses commented May 20, 2021

🐛 Bug report

Describe the bug

For any wrangler command, I get a permission error if I don't run sudo. Im using nvm as my node manager.

Reproduce the bug

% wrangler dev
⚠️ Specifying the same KV namespace ID for both preview and production sessions may cause bugs in your production worker! Proceed with caution.
Warning: webpack's output filename is being renamed to worker.js because of requirements from the Workers runtime
/Users/bram/Library/Caches/.wrangler/wranglerjs-1.16.0/index.js:100
throw err;
^

[Error: EACCES: permission denied, open './dist/worker.js'] {
errno: -13,
code: 'EACCES',
syscall: 'open',
path: './dist/worker.js'
}
Error: failed to execute "/Users/bram/.nvm/versions/node/v16.2.0/bin/node" "/Users/bram/Library/Caches/.wrangler/wranglerjs-1.16.0" "--output-file=/var/folders/qy/2h97wl010rlb1ls9tp_d73qc0000gn/T/.wranglerjs_outputOW0dJ" "--wasm-binding=WASM_MODULE" "--webpack-config=webpack.config.js": exited with exit code: 1

Expected behavior

Successful dev load 🤷

Environment and versions

  • operating system:
  • output of wrangler -V: 👷 ✨ wrangler 1.16.0
  • output of node -v: v16.2.0
@bramses bramses added the bug Something isn't working label May 20, 2021
@bramses bramses changed the title Permission Denied Permission denied (os error 13) May 20, 2021
@nilslice
Copy link
Contributor

Hi @bramses - do you recall how you installed wrangler and nvm? If either were done as a root user, this requirement makes sense. If that is the case, you'll likely need to reinstall these tools.

@bramses
Copy link
Author

bramses commented May 26, 2021

Hi @nilslice thanks for getting back. Initially I installed wrangler to my global npm, but I uninstalled that version and reinstalled with nvm.

$ which node
/Users/bram/.nvm/versions/node/v16.2.0/bin/node
$ which npm
/Users/bram/.nvm/versions/node/v16.2.0/bin/npm
$ which wrangler
/Users/bram/.nvm/versions/node/v16.2.0/bin/wrangler

but it still wants sudo for everything

@bramses
Copy link
Author

bramses commented Jun 4, 2021

Hi @nilslice, just following up on this!

@xortive
Copy link
Contributor

xortive commented Jun 4, 2021

@bramses If you've used sudo to run wrangler build or any command that builds like dev or publish, directories and files created by the build will be owned by root. It looks like this is what's happening in the error you provided with the file that holds the output of wrangler's build

code: 'EACCES',
syscall: 'open',
path: './dist/worker.js'

If you create a new project in a new directory, without using sudo, do you still get permission errors? If so, is the path different from ./dist/worker.js?

@bramses
Copy link
Author

bramses commented Jun 4, 2021

@xortive

Thanks for the comment! Tried starting a new wrangler worker from scratch and still got permission errors, output below:

bram@brams-air wrangler-test % wrangler login
Allow Wrangler to open a page in your browser? [y/n]
y
💁  Opened a link in your default browser: https://dash.cloudflare.com/wrangler?key=some_long_id_str
💁  Validating credentials...
**Error: Permission denied (os error 13)**
bram@brams-air wrangler-test % wrangler generate my-worker
⬇️   Installing cargo-generate v0.5.0...
🔧   Creating project called `my-worker`...
✨   Done! New project created /Users/bram/Desktop/PARA/Projects/wrangler-test/my-worker
🕵️  You can find your zone_id in the right sidebar of a zone's overview tab at https://dash.cloudflare.com
🕵️  You can find your account_id in the right sidebar of your account's Workers page
🕵️  You will need to update the following fields in the created wrangler.toml file before continuing:
- account_id
bram@brams-air wrangler-test % cd my-worker/
bram@brams-air my-worker % wrangler whoami
Error: Permission denied (os error 13)

Both login and whoami threw permission errors

node and wrangler still owned by nvm:

bram@brams-air my-worker % which node
/Users/bram/.nvm/versions/node/v16.2.0/bin/node
bram@brams-air my-worker % which wrangler
/Users/bram/.nvm/versions/node/v16.2.0/bin/wrangler

@xortive
Copy link
Contributor

xortive commented Jun 4, 2021

These permissions errors aren't from the installation process (which is where using nvm is important), but from running wrangler as root in the past using sudo.

Make sure the ~/.wrangler and ~/.cache/.wrangler directories and any of their contents are not owned by root as well -- any files that wrangler created (build output, configuration) while run as root will now be owned by root, and any operations that require accessing or modifying those files will fail as a result.

We'd like to do better here, but it's potentially a breaking change. More details in #1863 (that issue is specifically about the cache directory, but it's a problem for other files wrangler creates)

@bramses
Copy link
Author

bramses commented Jun 4, 2021

Just checked this is what came back from ls -l:

bram@brams-air .wrangler % ls -l
total 8
drwxrwxrwx  4 bram  staff  128 Apr 20 16:47 bin
drwxr-xr-x  3 bram  staff   96 Apr 20 17:43 config
-rw-r--r--  1 bram  staff  102 May 30 15:44 version.toml

Couldn't find .cache on local:

bram@brams-air ~ % cd ~/.cache/.wrangler
cd: no such file or directory: /Users/bram/.cache/.wrangler

@xortive
Copy link
Contributor

xortive commented Jun 4, 2021

how about inside ~/.wrangler/bin and ~/.wrangler/config? (The permissions errors on wrangler login, wrangler config, and wrangler whoami are likely from ~/.wrangler/config/default.toml)

@bramses
Copy link
Author

bramses commented Jun 4, 2021

So good news/bad news:

Good news: running your suggestion on ~/.wrangler/bin worked for the new test directory we just made:

bram@brams-air my-worker % wrangler dev
🕵️  You can copy your account_id below
+-----------------------------------+----------------------------------+
| Account Name                      | Account ID                       |
+-----------------------------------+----------------------------------+
| Bram@sharingfiction.com's Account | my_id_str |
+-----------------------------------+----------------------------------+
Error: field `account_id` is required to deploy to workers.dev

Bad news:
sudo is still required for my main Cloudflare Worker project I have in production:

[Error: EACCES: permission denied, open '/Users/bram/Desktop/PARA/Projects/live-project/dist/worker.js'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/Users/bram/Desktop/PARA/Projects/live-project/dist/worker.js'
}

worker.js is owned by user it seems though

bram@brams-air dist % ls -l
total 104
-rw-r--r--  1 bram  staff  52290 Jun  4 12:37 worker.js

@bramses
Copy link
Author

bramses commented Jul 27, 2021

Still running into this issue for my local Cloudflare Workers, but the new ones seem to not require sudo. Gonna close this one, though, thanks for the help @xortive.

For posterity, this is what helped:

Make sure the ~/.wrangler and ~/.cache/.wrangler directories and any of their contents are not owned by root as well -- any files that wrangler created (build output, configuration) while run as root will now be owned by root, and any operations that require accessing or modifying those files will fail as a result.

@bramses bramses closed this as completed Jul 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants