Code-server: Enforce user permissions for user data and extension dirs on container startup

Created on 17 Sep 2019  路  12Comments  路  Source: cdr/code-server

Description

When we start code-server as a docker container and mounting a path for extensions we need to make sure on startup that it belongs to the same user as the code-server

Steps to Reproduce

use the oneliner from README.md

Result

docker run -it -p 127.0.0.1:8080:8080 -v "${HOME}/.local/share/code-server:/home/coder/.local/share/code-server" -v "$PWD:/home/coder/project" codercom/code-server
(node:6) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
ERROR { [Error: EACCES: permission denied, mkdir '/home/coder/.local/share/code-server/extensions']
  [stack]:
   'Error: EACCES: permission denied, mkdir \'/home/coder/.local/share/code-server/extensions\'',
  [message]:
   'EACCES: permission denied, mkdir \'/home/coder/.local/share/code-server/extensions\'',
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/home/coder/.local/share/code-server/extensions' }

bug

Most helpful comment

@pedrolucasoliva
i am docker specialist i give you a little hint the --user flag

docker run --user $(id):$(id) -d -p 0.0.0.0:8000:8080 --name codeserver -v "/home/dev/codeserver/.local/share/code-server:/home/coder/.local/share/code-server" -v "/home/dev/projects:/home/coder/project" codercom/code-server:v2

the --user $(id):$(id) will switch the user id of the coder user to your user id and group :)

All 12 comments

or we add instructions for mkdir -p befor running that and chmod 0777 so that it will work

I got the same problem.

This is a open field of debate at the moment as one of the Engineers declined to have the RW access workaround due to "permission concerns" - where it shouldn't. Revisiting this once more.

@sr229 but this issue is about the extensions dir i think there the discussion is less relevant as it is always clear that extensions need to be readwrite by code-server user it self its not about the project files

Yes this is a separate issue. But closely related to #640

I am still getting this error. Are we waiting for an updated push for this to be fixed?

@mukk85 current state is you manualy create the extensions dir befor you run the oneliner and chmod the folder right befor you start the oneliner

because when docker creates the folder while starting it will be owned by root

Running:
docker run -d -p 0.0.0.0:8000:8080 --name codeserver -v "/home/dev/codeserver/.local/share/code-server:/home/coder/.local/share/code-server" -v "/home/dev/projects:/home/coder/project" codercom/code-server:v2
I resolve this problem with:
sudo chmod 777 -R dev/

mode 0777 is a dangerous permission to give since it gives R/W and execution perms, you should only give it R/W perms (mode 0600 AFAIK).

@pedrolucasoliva
i am docker specialist i give you a little hint the --user flag

docker run --user $(id):$(id) -d -p 0.0.0.0:8000:8080 --name codeserver -v "/home/dev/codeserver/.local/share/code-server:/home/coder/.local/share/code-server" -v "/home/dev/projects:/home/coder/project" codercom/code-server:v2

the --user $(id):$(id) will switch the user id of the coder user to your user id and group :)

I still have same issue on Ubuntu server 18.04 LTS
I tried to make the folder manually, but it doesn't work.
image

Edited
Finally It runs very well! 馃帀 馃帀
I used this command
docker run --user 1000:1000 -d -p 0.0.0.0:8000:8080 --name codeserver -v "/home/dev/codeserver/.local/share/code-server:/home/coder/.local/share/code-server" -v "/home/dev/projects:/home/coder/project" codercom/code-server:v2
and it runs perfectly.
image

The only thing I changed is $(id):$(id) to 1000:1000.

Thanks for @frank-dspeed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

balazssoltesz picture balazssoltesz  路  3Comments

RealSlimMahdi picture RealSlimMahdi  路  3Comments

lshamis picture lshamis  路  3Comments

tecosaur picture tecosaur  路  3Comments

korzq picture korzq  路  3Comments