microsoft / microsoft/vscode-remote-release

Workaround to make code-server inherit user-defined umask bits

Open
#11,666 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dockerfile
Stars
4.2k
Forks
469
Avg merge
1d 1h
Merged PRs (30d)
1

Description

Following up on https://github.com/microsoft/vscode-remote-release/issues/7902

We created a script that patches the code-server launcher script to make it inherit the user's bash environment's umask bits.

#!/usr/bin/env bash

# This script patches the vscode-server entrypoint script such that the umask bits
# are inherited from the current user's bash environment

TARGET_FILE="$1"

ANCHOR_LINE='#!/usr/bin/env sh'
PATCH_INDICATOR="# vscode-umask-patch"

set -euo pipefail

grep -Fqx "$PATCH_INDICATOR" "$TARGET_FILE" && {
    echo "Already patched"
    exit 0
}

echo "Patching $TARGET_FILE"

PATCH_CONTENT_FILE="/tmp/vscode-patch"

echo "
#
$PATCH_INDICATOR
# Inherit umask bits from your user's environment
# Fixes https://github.com/microsoft/vscode-remote-release/issues/7902
# Workaround as described here (while avoiding to hardcode the bits):
# https://github.com/microsoft/vscode-remote-release/issues/4442#issuecomment-3045033587
#" > "$PATCH_CONTENT_FILE"

echo 'umask "$(/usr/bin/env bash -lc umask)"
' >> "$PATCH_CONTENT_FILE"

escaped_anchor=$(printf '%s\n' "$ANCHOR_LINE" | sed 's/[][\/.^$*]/\\&/g')
sed -i "\|$escaped_anchor|r $PATCH_CONTENT_FILE" "$TARGET_FILE"

rm -f "$PATCH_CONTENT_FILE"

echo "Done."

It basically adds the following lines between the shebang and Microsoft's copyright comment:

#
# vscode-umask-patch
# Inherit umask bits from your user's environment
# Fixes https://github.com/microsoft/vscode-remote-release/issues/7902
#
umask "$(/usr/bin/env bash -lc umask)"

The script is idempotent, i.e. multiple executions result in the same change.

Best! Stefan

Root Cause of the bug

The reason that the umask bit is not inherited from the user's env is because of the SSH shell (see Output > Remote - SSH) that runs code-server:
Generated SSH command: 'type "C:\Users\MyUser\AppData\Local\Temp\156\vscode-linux-multi-line-command-targethostname-429690158.sh" | "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 63716 targethostname bash'

Note the bash at the end without arguments. It creates a shell for the remote SSH session without the user's environment and thus no execution of .bashrc, where we probably put a custom umask command.

Within this bash shell, code-server is executed:
Starting VS Code Server... "/home/MyUser/.vscode-server/bin/c9d77990917f3102ada88be140d28b038d1dd7c7/bin/code-server" --start-server --server-data-dir "/home/MyUser/.vscode-server" --host=127.0.0.1 --accept-server-license-terms --enable-remote-auto-shutdown --port=0 --telemetry-level all &> "/home/MyUser/.vscode-server/.c9d77990917f3102ada88be140d28b038d1dd7c7.log" < /dev/null

And so, code-server gains the default umask bits of 0022 unconditionally.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Remote-SSH launch path that generates the remote bash command and invokes the code-server entrypoint described in the issue. Verify how the user's .bashrc and umask are handled, then test a remote SSH connection with a custom umask; done means the server inherits that umask without manually patching the launcher script.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, vscode
Domain
devtools, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.