Skip to content

Commit fa07406

Browse files
add missing user groups to fix permission issues for non root user (devcontainers#45)
* add missing user groups * fix username * move chmod: anaconda
1 parent 19fd66a commit fa07406

8 files changed

Lines changed: 74 additions & 12 deletions

File tree

src/anaconda/install.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
VERSION=${VERSION:-"latest"}
12-
1312
USERNAME=${USERNAME:-"automatic"}
1413
UPDATE_RC=${UPDATE_RC:-"true"}
1514
CONDA_DIR=${CONDA_DIR:-"/usr/local/conda"}
@@ -32,8 +31,8 @@ if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
3231
USERNAME=""
3332
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
3433
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
35-
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
36-
USERNAME=${CURRENT_USER}
34+
if id -u "${CURRENT_USER}" > /dev/null 2>&1; then
35+
USERNAME="${CURRENT_USER}"
3736
break
3837
fi
3938
done
@@ -72,11 +71,19 @@ check_packages() {
7271

7372
# Install Conda if it's missing
7473
if ! conda --version &> /dev/null ; then
74+
if ! cat /etc/group | grep -e "^conda:" > /dev/null 2>&1; then
75+
groupadd -r conda
76+
fi
77+
usermod -a -G conda "${USERNAME}"
78+
7579
# Install dependencies
7680
check_packages wget ca-certificates
7781

7882
mkdir -p $CONDA_DIR
79-
chown ${USERNAME}:root $CONDA_DIR
83+
chown -R :conda "${CONDA_DIR}"
84+
chmod -R g+r+w "${CONDA_DIR}"
85+
86+
find "${CONDA_DIR}" -type d | xargs -n 1 chmod g+s
8087
echo "Installing Anaconda..."
8188

8289
CONDA_VERSION=$VERSION

src/dotnet/install.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,16 @@ else
412412
echo "Could not install dotnet from apt. Attempting to install dotnet from releases url"
413413
fi
414414

415+
if ! cat /etc/group | grep -e "^dotnet:" > /dev/null 2>&1; then
416+
groupadd -r dotnet
417+
fi
418+
usermod -a -G dotnet "${USERNAME}"
419+
415420
install_using_dotnet_releases_url "${DOTNET_SDK_OR_RUNTIME}"
421+
422+
chown -R :dotnet "${TARGET_DOTNET_ROOT}"
423+
chmod -R g+r+w "${TARGET_DOTNET_ROOT}"
424+
find "${TARGET_DOTNET_ROOT}" -type d | xargs -n 1 chmod g+s
416425
fi
417426

418427
echo "Done!"

src/hugo/install.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ fi
9090

9191
# Install Hugo if it's missing
9292
if ! hugo version &> /dev/null ; then
93+
if ! cat /etc/group | grep -e "^hugo:" > /dev/null 2>&1; then
94+
groupadd -r hugo
95+
fi
96+
usermod -a -G hugo "${USERNAME}"
97+
9398
echo "Installing Hugo..."
9499
installation_dir="$HUGO_DIR/bin"
95100
mkdir -p "$installation_dir"
@@ -108,6 +113,10 @@ if ! hugo version &> /dev/null ; then
108113
rm "$hugo_filename"
109114

110115
updaterc "export HUGO_DIR=${installation_dir}"
116+
117+
chown -R :hugo "${HUGO_DIR}"
118+
chmod -R g+r+w "${HUGO_DIR}"
119+
find "${HUGO_DIR}" -type d | xargs -n 1 chmod g+s
111120
fi
112121

113122
echo "Done!"

src/oryx/devcontainer-feature.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"containerEnv": {
55
"ORYX_SDK_STORAGE_BASE_URL": "https://oryx-cdn.microsoft.io",
66
"ENABLE_DYNAMIC_INSTALL": "true",
7-
"DYNAMIC_INSTALL_ROOT_DIR": "/tmp/oryx-platforms",
7+
"DYNAMIC_INSTALL_ROOT_DIR": "/usr/local/oryx-platforms",
8+
"ORYX_PREFER_USER_INSTALLED_SDKS": "true",
89
"ORYX_DIR": "/usr/local/oryx",
910
"PATH": "${ORYX_DIR}:${PATH}"
1011
},

src/oryx/install.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ check_packages git sudo wget ca-certificates
8686
if ! oryx --version > /dev/null ; then
8787
echo "Installing Oryx..."
8888

89+
if ! cat /etc/group | grep -e "^oryx:" > /dev/null 2>&1; then
90+
groupadd -r oryx
91+
fi
92+
usermod -a -G oryx "${USERNAME}"
93+
8994
# Install dotnet unless available
9095
if ! dotnet --version > /dev/null ; then
9196
echo "'dotnet' was not detected. Attempting to install the latest version of the dotnet sdk to build oryx."
@@ -104,7 +109,6 @@ if ! oryx --version > /dev/null ; then
104109
mkdir -p ${BUILD_SCRIPT_GENERATOR}
105110
mkdir -p ${ORYX}
106111

107-
chown -R ${USERNAME} ${BUILD_SCRIPT_GENERATOR} ${ORYX}
108112
git clone --depth=1 https://github.com/microsoft/Oryx $GIT_ORYX
109113

110114
$GIT_ORYX/build/buildSln.sh
@@ -118,11 +122,16 @@ if ! oryx --version > /dev/null ; then
118122
ln -s ${BUILD_SCRIPT_GENERATOR}/GenerateBuildScript ${ORYX}/oryx
119123
cp -f $GIT_ORYX/images/build/benv.sh ${ORYX}/benv
120124

121-
ORYX_INSTALL_DIR="/tmp/oryx-platforms"
125+
ORYX_INSTALL_DIR="/usr/local/oryx-platforms"
122126
mkdir -p "${ORYX_INSTALL_DIR}"
123-
chown -R ${USERNAME} "${ORYX_INSTALL_DIR}"
124127

125-
updaterc "export ORYX_SDK_STORAGE_BASE_URL=https://oryx-cdn.microsoft.io && export ENABLE_DYNAMIC_INSTALL=true && DYNAMIC_INSTALL_ROOT_DIR=$ORYX_INSTALL_DIR"
128+
updaterc "export ORYX_SDK_STORAGE_BASE_URL=https://oryx-cdn.microsoft.io && export ENABLE_DYNAMIC_INSTALL=true && DYNAMIC_INSTALL_ROOT_DIR=$ORYX_INSTALL_DIR && ORYX_PREFER_USER_INSTALLED_SDKS=true"
129+
130+
chown -R :oryx "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}"
131+
chmod -R g+r+w "${ORYX_INSTALL_DIR}" "${BUILD_SCRIPT_GENERATOR}" "${ORYX}"
132+
find "${ORYX_INSTALL_DIR}" -type d | xargs -n 1 chmod g+s
133+
find "${BUILD_SCRIPT_GENERATOR}" -type d | xargs -n 1 chmod g+s
134+
find "${ORYX}" -type d | xargs -n 1 chmod g+s
126135
fi
127136

128137
echo "Done!"

src/php/install.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
4040
fi
4141
done
4242
if [ "${USERNAME}" = "" ]; then
43-
USERNAME=vscode
43+
USERNAME=root
4444
fi
4545
elif [ "${USERNAME}" = "none" ]; then
4646
USERNAME=root
@@ -122,6 +122,11 @@ if [ -d "${PHP_INSTALL_DIR}" ]; then
122122
exit 1
123123
fi
124124

125+
if ! cat /etc/group | grep -e "^php:" > /dev/null 2>&1; then
126+
groupadd -r php
127+
fi
128+
usermod -a -G php "${USERNAME}"
129+
125130
PHP_URL="https://www.php.net/distributions/php-${VERSION}.tar.gz"
126131

127132
PHP_INI_DIR="${PHP_INSTALL_DIR}/ini"
@@ -192,4 +197,8 @@ rm -rf ${PHP_SRC_DIR}
192197

193198
updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=${CURRENT_DIR}/bin:\${PATH}; fi"
194199

200+
chown -R :php "${PHP_DIR}"
201+
chmod -R g+r+w "${PHP_DIR}"
202+
find "${PHP_DIR}" -type d | xargs -n 1 chmod g+s
203+
195204
echo "Done!"

src/python/install.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ check_packages curl ca-certificates gnupg2 tar make gcc libssl-dev zlib1g-dev li
341341

342342
# Install Python from source if needed
343343
if [ "${PYTHON_VERSION}" != "none" ]; then
344+
if ! cat /etc/group | grep -e "^python:" > /dev/null 2>&1; then
345+
groupadd -r python
346+
fi
347+
usermod -a -G python "${USERNAME}"
348+
344349
CURRENT_PATH="${PYTHON_INSTALL_PATH}/current"
345350
# If the os-provided versions are "good enough", detect that and bail out.
346351
if [ ${PYTHON_VERSION} = "os-provided" ] || [ ${PYTHON_VERSION} = "system" ]; then
@@ -357,6 +362,10 @@ if [ "${PYTHON_VERSION}" != "none" ]; then
357362
fi
358363

359364
updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_PATH}/bin\"* ]]; then export PATH=${CURRENT_PATH}/bin:\${PATH}; fi"
365+
366+
chown -R :python "${PYTHON_INSTALL_PATH}"
367+
chmod -R g+r+w "${PYTHON_INSTALL_PATH}"
368+
find "${PYTHON_INSTALL_PATH}" -type d | xargs -n 1 chmod g+s
360369
fi
361370

362371
# Install Python tools if needed
@@ -403,6 +412,10 @@ if [ "${INSTALL_PYTHON_TOOLS}" = "true" ]; then
403412
updaterc "export PIPX_HOME=\"${PIPX_HOME}\""
404413
updaterc "export PIPX_BIN_DIR=\"${PIPX_BIN_DIR}\""
405414
updaterc "if [[ \"\${PATH}\" != *\"\${PIPX_BIN_DIR}\"* ]]; then export PATH=\"\${PATH}:\${PIPX_BIN_DIR}\"; fi"
415+
416+
chown -R :python "${PIPX_HOME}"
417+
chmod -R g+r+w "${PIPX_HOME}"
418+
find "${PIPX_HOME}" -type d | xargs -n 1 chmod g+s
406419
fi
407420

408421
# Install JupyterLab if needed

src/ruby/install.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,23 @@ if [ "${SKIP_RBENV_RBUILD}" != "true" ]; then
270270

271271
if [ "${USERNAME}" != "root" ]; then
272272
mkdir -p /home/${USERNAME}/.rbenv/plugins
273-
sudo chown -R ${USERNAME} /home/${USERNAME}/.rbenv
274-
sudo chown -R ${USERNAME} /usr/local/rvm/
275273

276274
if [[ ! -d "/home/${USERNAME}/.rbenv/plugins/ruby-build" ]]; then
277275
ln -s /usr/local/share/ruby-build /home/${USERNAME}/.rbenv/plugins/ruby-build
278276
fi
279277

280278
ln -s /usr/local/rvm/rubies/default/bin/ruby /usr/local/rvm/gems/default/bin
281279

280+
chown -R :rvm "/home/${USERNAME}/.rbenv"
281+
chmod -R g+r+w "/home/${USERNAME}/.rbenv"
282+
find "/home/${USERNAME}/.rbenv" -type d | xargs -n 1 chmod g+s
282283
fi
283284
fi
284285

286+
chown -R :rvm "/usr/local/rvm"
287+
chmod -R g+r+w "/usr/local/rvm"
288+
find "/usr/local/rvm" -type d | xargs -n 1 chmod g+s
289+
285290
# Clean up
286291
rvm cleanup all
287292
${ROOT_GEM} cleanup

0 commit comments

Comments
 (0)