Skip to content

Commit 04b6b90

Browse files
[universal] Update Python 3.10 due to CVE-2022-40897 (devcontainers#594)
* [universal] Update Python 3.10 due to CVE-2022-40897 - Bump Python version: `3.10.4` -> `3.10.11` * Remove temp fix for `setuptools` * Revert "Remove temp fix for `setuptools`" This reverts commit 3e4908e. * Rework fix - Change Python to v3.10.8 (To be compatible with Oryx); - Introduce `patch-python` feature; - Move Python patches from `setup-user` feature to `patch-python`;
1 parent cf9e010 commit 04b6b90

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

src/universal/.devcontainer/devcontainer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"./local-features/nvs": "latest",
2525
"ghcr.io/devcontainers/features/python:1": {
26-
"version": "3.10.4",
26+
"version": "3.10.8",
2727
"additionalVersions": "3.9.16",
2828
"installJupyterlab": "true",
2929
"configureJupyterlabAllowOrigin": "*"
@@ -71,7 +71,8 @@
7171
},
7272
"./local-features/jekyll": "latest",
7373
"ghcr.io/devcontainers/features/oryx:1": "latest",
74-
"./local-features/setup-user": "latest"
74+
"./local-features/setup-user": "latest",
75+
"./local-features/patch-python": "latest"
7576
},
7677
"overrideFeatureInstallOrder": [
7778
"ghcr.io/devcontainers/features/common-utils",
@@ -81,6 +82,7 @@
8182
"ghcr.io/devcontainers/features/node",
8283
"./local-features/nvs",
8384
"ghcr.io/devcontainers/features/python",
85+
"./local-features/patch-python",
8486
"./local-features/machine-learning-packages",
8587
"ghcr.io/devcontainers/features/php",
8688
"ghcr.io/devcontainers/features/conda",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "patch-python",
3+
"name": "Patch Python Packages",
4+
"install": {
5+
"app": "",
6+
"file": "install.sh"
7+
}
8+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
7+
USERNAME=${USERNAME:-"codespace"}
8+
9+
set -eux
10+
11+
if [ "$(id -u)" -ne 0 ]; then
12+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
13+
exit 1
14+
fi
15+
16+
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
17+
rm -f /etc/profile.d/00-restore-env.sh
18+
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
19+
chmod +x /etc/profile.d/00-restore-env.sh
20+
21+
export DEBIAN_FRONTEND=noninteractive
22+
23+
sudo_if() {
24+
COMMAND="$*"
25+
if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then
26+
su - "$USERNAME" -c "$COMMAND"
27+
else
28+
"$COMMAND"
29+
fi
30+
}
31+
32+
update_package() {
33+
PYTHON_PATH=$1
34+
PACKAGE=$2
35+
36+
sudo_if "$PYTHON_PATH -m pip uninstall --yes $PACKAGE"
37+
sudo_if "$PYTHON_PATH -m pip install --user --upgrade --no-cache-dir $PACKAGE"
38+
}
39+
40+
# Temporary: Upgrade python packages due to security vulnerabilities
41+
# They are installed by the base image (python) which does not have the patch.
42+
43+
# https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-40897
44+
update_package /usr/local/python/3.9.*/bin/python setuptools
45+
update_package /usr/local/python/3.10.*/bin/python setuptools
46+
47+
# https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-32681
48+
update_package /usr/local/python/3.10.*/bin/python requests

src/universal/.devcontainer/local-features/setup-user/install.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ sudo_if() {
4141
fi
4242
}
4343

44-
# Temporary: Upgrade python packages due to https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-40897
45-
# They are installed by the base image (python) which does not have the patch.
46-
sudo_if /usr/local/python/current/bin/python -m pip uninstall --yes setuptools
47-
sudo_if /usr/local/python/current/bin/python -m pip install --user --upgrade --no-cache-dir setuptools
48-
sudo_if /usr/local/python/3.9.*/bin/python -m pip uninstall --yes setuptools
49-
sudo_if /usr/local/python/3.9.*/bin/python -m pip install --user --upgrade --no-cache-dir setuptools
50-
5144
# Enables the oryx tool to generate manifest-dir which is needed for running the postcreate tool
5245
DEBIAN_FLAVOR="focal-scm"
5346
mkdir -p /opt/oryx && echo "vso-focal" > /opt/oryx/.imagetype

0 commit comments

Comments
 (0)