vscode-remote-release icon indicating copy to clipboard operation
vscode-remote-release copied to clipboard

Investigate umask behavior

Open bamurtaugh opened this issue 5 years ago • 11 comments

Based on our recent discussion, opening an issue to track investigation into umask behavior.

If we set the umask for the server process, we need the server to set the permissions on it, and/or see if there are any other consequences to this action (i.e. learn more about umask).

bamurtaugh avatar Feb 08 '21 19:02 bamurtaugh

Details - the remote server socket inherits the user's umask when creating the socket. We can set umask, like to 0077 before starting the node process. But, then the umask will be inherited by the user's terminal and may not be what the user expects.

Chuck had the idea to add the umask during setup to limit the socket to just your user - the socket in this case being effectively "personal." We were wondering if there were any potential problems to look out for by doing this?

roblourens avatar Oct 13 '21 01:10 roblourens

Thanks for the followup @roblourens For me it's more than a feature request. As explain in the linked issue #5567, files created by a user with a umask 022 will get different access rights depending the way the file is created (using VSCode with Remote/SSH extension or using the terminal) which is quite ... annoying :) Would be happy to help to test an incoming fix :) Thx for your help

zorrobiwan avatar Oct 19 '21 10:10 zorrobiwan

We have the same problem as @zorrobiwan. we us VSCode with Remote/SSH. The remote server also hosts the git repo and when pushing commits it always messes up the permissions in the repo. That leads to other users not able to contribute to the same parts of code as they get permission denied errors. So we would really like to have a solution, maybe something similar to Remote/WSL https://github.com/microsoft/vscode-remote-release/issues/1518 ?

ccghad avatar Dec 14 '21 10:12 ccghad

I have exactly the same problem as @zorrobiwan. When I create a new file, its permission becomes 664. Setting umask in /etc/profile or ~/.profile does not work.

To mitigate the problem, I run a chmod command for all files everytime I compile files so that I don't include the wrong permission files in a repository.

SSH FS (VSCode extension) has a function that allows a user to set a default permission. https://marketplace.visualstudio.com/items?itemName=Kelvin.vscode-sshfs

2022-02-18

Permission is very important for security. I hope it will be fixed soon.

yoshi-sheep avatar Feb 18 '22 09:02 yoshi-sheep

I found a solution. I added a line below in /etc/pam.d/sshd

session optional pam_umask.so umask=0027

Now, when I create a new file or directory in VSCode, the permission becomes as I set in /etc/pam.d/sshd. This setting is also effective for "ssh hostname command" and SCP connection.

It seems that if you login with ssh, it can read umask but VSCode connection, ssh command, nor SCP does not read umask. Anyway, I'm relieved that I found the solution which sets umask for all ssh connections.

yoshi-sheep avatar Feb 20 '22 03:02 yoshi-sheep

Good to know there is a workaround ... Will test it later Thanks Yoshi!

zorrobiwan avatar Feb 21 '22 07:02 zorrobiwan

session optional pam_umask.so umask=0027

That's very bad. Better is:

The default umask on my servers is 077. I've a dev-base-dir "/a41-dev".

as user "root":

mkdir /a41-dev/src
chmod 775 /a41-dev/src
chown root:users /a41-dev/src
setfacl -d -m u::rwx,g::r-x,o::r-x /a41-dev/src

as user "admin" ... member of users and umask = 077

mkdir /a41-dev/src/test-dir
touch /a41-dev/src/test-file

/a41-dev/src/test-dir will be createded with drwxr-xr-x /a41-dev/src/test-file will be createded with -rw-r--r--

... the default umask of 022 will be ignored. It also works with vscode.

t-r-77 avatar Sep 26 '22 12:09 t-r-77

For me this problem only occurs if I install the tunnel service with.

./code tunnel service install

If I remove the service and run the tunnel as my normal user on the remote server with

./code tunnel

the file permissions are as expected.

abuzze avatar Jul 05 '24 08:07 abuzze

I am getting the same issues here. Is there any update? The vscode-server process has a different umask than the bash terminal. Is there a solution to this?

zamachnoi avatar Jul 04 '25 19:07 zamachnoi

I found a work around.

vs-code server starts with a sh command, and seems to be a non-login shell.

If you can't make any modifications to your etc/profile for example do this:

Fix

  1. In .vscode-server/bin/$COMMIT_ID/bin/code-server (normally located in ~/) on your desired remote server add your umask, (ex: umask 0002) before it calls the js file, the top, or under the case is fine.
  2. On your local Ctrl + Shift + P and run Kill VS Code Server on Host.
  3. Make sure the code server is killed on your remote host. You can check this by running pgrep -af code-server with a regular ssh in your terminal.
  4. Connect to your server and create a file, see if it works.

Example of file

Image

zamachnoi avatar Jul 07 '25 13:07 zamachnoi

I believe the culprit is the bash shell that's opened by the SSH command. I described it in detail here: https://github.com/microsoft/vscode-remote-release/issues/11666

StefanRickli avatar May 28 '26 11:05 StefanRickli