Unverified Commit c1df45b1 authored by Prabhakar Kumar's avatar Prabhakar Kumar Committed by GitHub

Adds /home/USER/.local/bin/ to PATH in /etc/sudoers.d/vscode, (#887)

* Adds /home/USER/.local/bin/ to PATH in /etc/sudoers.d/vscode,  fixes devcontainers/features#870

* Bumping up version to 1.4.2

* Adds to sudoers file if already present

* Tests to ensure Default secure_path is not overwritten

* Bump to version 1.4.4

* Fix version as 1.4.3
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>

* Update src/python/install.sh
Co-authored-by: 's avatarPrabhakar Kumar <64955767+prabhakk-mw@users.noreply.github.com>

* Update src/python/devcontainer-feature.json

---------
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>
Co-authored-by: 's avatarSamruddhi Khandale <skhandale@microsoft.com>
parent 32797f4f
{ {
"id": "python", "id": "python",
"version": "1.5.0", "version": "1.6.0",
"name": "Python", "name": "Python",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/python", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/python",
"description": "Installs the provided version of Python, as well as PIPX, and other common Python utilities. JupyterLab is conditionally installed with the python feature. Note: May require source code compilation.", "description": "Installs the provided version of Python, as well as PIPX, and other common Python utilities. JupyterLab is conditionally installed with the python feature. Note: May require source code compilation.",
......
...@@ -865,6 +865,23 @@ if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then ...@@ -865,6 +865,23 @@ if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then
install_user_package $INSTALL_UNDER_ROOT jupyterlab install_user_package $INSTALL_UNDER_ROOT jupyterlab
install_user_package $INSTALL_UNDER_ROOT jupyterlab-git install_user_package $INSTALL_UNDER_ROOT jupyterlab-git
if [ "$INSTALL_UNDER_ROOT" = false ]; then
# JupyterLab would have installed into /home/${USERNAME}/.local/bin
# Adding it to default path for Codespaces which use non-login shells
SUDOERS_FILE="/etc/sudoers.d/$USERNAME"
SEARCH_STR="Defaults secure_path="
REPLACE_STR="Defaults secure_path=/home/${USERNAME}/.local/bin"
if grep -qs ${SEARCH_STR} ${SUDOERS_FILE}; then
# string found and file is present
sed -i "s|${SEARCH_STR}|${REPLACE_STR}:|g" "${SUDOERS_FILE}"
else
# either string is not found, or file is not present
# In either case take same action, note >> places at end of file
echo "${REPLACE_STR}:${PATH}" >> ${SUDOERS_FILE}
fi
fi
# Configure JupyterLab if needed # Configure JupyterLab if needed
if [ -n "${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}" ]; then if [ -n "${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}" ]; then
# Resolve config directory # Resolve config directory
......
...@@ -22,5 +22,8 @@ check "jupyterlab_git" grep jupyterlab_git <<< "$packages" ...@@ -22,5 +22,8 @@ check "jupyterlab_git" grep jupyterlab_git <<< "$packages"
# Check for correct JupyterLab configuration # Check for correct JupyterLab configuration
check "config" grep ".*.allow_origin = '*'" /home/vscode/.jupyter/jupyter_server_config.py check "config" grep ".*.allow_origin = '*'" /home/vscode/.jupyter/jupyter_server_config.py
# Check for PATH modification
check "default path has jupyterlab" sudo grep "/home/${user}/.local/bin" /etc/sudoers.d/$user
# Report result # Report result
reportResults reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Always run these checks as the non-root user
user="$(whoami)"
check "user" grep vscode <<< "$user"
# Check for an installation of JupyterLab
check "version" jupyter lab --version
# Check location of JupyterLab installation
packages="$(python3 -m pip list)"
check "location" grep jupyter <<< "$packages"
# Check for git extension
check "jupyterlab_git" grep jupyterlab_git <<< "$packages"
# Check for correct JupyterLab configuration
check "config" grep ".*.allow_origin = '*'" /home/vscode/.jupyter/jupyter_server_config.py
# Check for PATH modification
check "default path has jupyterlab" grep "Defaults secure_path=/home/${user}/.local/bin" /etc/sudoers.d/$user
# Check if previous PATH exists
check "existing default path is preserved" grep "Defaults secure_path=.*original_content_of_sudoers_file" /etc/sudoers.d/$user
# Check if PATH modification includes original and new paths
check "existing path included with jupyterlab" grep "Defaults secure_path.*/home/${user}/.local/bin.*original_content_of_sudoers_file" /etc/sudoers.d/$user
# Report result
reportResults
# Builds an image with a preconfigured SUDOERS file
# Used to test the install script for JupyterLab which modifies this file
FROM mcr.microsoft.com/devcontainers/base:focal
COPY --chown=root sudoers.test /etc/sudoers.d/vscode
# Sudoers File for testing, after install script runs the Defaults secure_path should be appended to
Defaults secure_path=/original_content_of_sudoers_file
\ No newline at end of file
...@@ -68,6 +68,19 @@ ...@@ -68,6 +68,19 @@
} }
} }
}, },
"install_jupyterlab_existing_sudoers_file": {
"build": {
"dockerfile": "Dockerfile"
},
"remoteUser": "vscode",
"features": {
"python": {
"version": "latest",
"installJupyterlab": true,
"configureJupyterlabAllowOrigin": "*"
}
}
},
"install_jupyterlab_rhel_family": { "install_jupyterlab_rhel_family": {
"image": "almalinux:8", "image": "almalinux:8",
"remoteUser": "vscode", "remoteUser": "vscode",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment