Skip to content

Commit 1459344

Browse files
[anaconda]-auto install vuln pkgs from conda / pip (#1079)
* [anaconda]-auto install vuln pkgs from conda / pip * Misc change * for test runs fails * misc change * changes requested * minor change * MSG CHANGE * changes suggested * changes acc. to review comments.. * [anaconda] - changes as requested
1 parent ac4f805 commit 1459344

File tree

2 files changed

+58
-29
lines changed

2 files changed

+58
-29
lines changed

src/anaconda/.devcontainer/Dockerfile

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,9 @@ RUN . /etc/os-release && if [ "${VERSION_CODENAME}" != "bullseye" ]; then exit 1
55

66
# Temporary: Upgrade python packages due to mentioned CVEs
77
# They are installed by the base image (continuumio/anaconda3) which does not have the patch.
8-
RUN conda install \
9-
# https://github.com/advisories/GHSA-mr82-8j83-vxmv
10-
pydantic==2.5.3
11-
12-
RUN python3 -m pip install --upgrade \
13-
# https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-21797
14-
joblib==1.3.1 \
15-
# https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-34749
16-
mistune==3.0.1 \
17-
# https://github.com/advisories/GHSA-2g68-c3qc-8985
18-
werkzeug==3.0.3 \
19-
# https://github.com/advisories/GHSA-v68g-wm8c-6x7j
20-
transformers==4.36.0 \
21-
# https://github.com/advisories/GHSA-44wm-f244-xhp3
22-
pillow==10.3.0 \
23-
# https://github.com/advisories/GHSA-5h86-8mv2-jq9f
24-
aiohttp==3.9.4 \
25-
# https://github.com/advisories/GHSA-6vqw-3v5j-54x4
26-
cryptography==42.0.4 \
27-
# https://github.com/advisories/GHSA-2mqj-m65w-jghx
28-
gitpython==3.1.41 \
29-
# https://github.com/advisories/GHSA-4qhp-652w-c22x
30-
jupyter-lsp==2.2.2 \
31-
# https://github.com/advisories/GHSA-jjg7-2v4v-x38h
32-
idna==3.7 \
33-
# https://github.com/advisories/GHSA-h75v-3vvj-5mfj
34-
jinja2==3.1.4 \
35-
# https://github.com/advisories/GHSA-4qqq-9vqf-3h3f
36-
scrapy==2.11.2
8+
COPY ./apply_security_patches.sh /tmp/apply_security_patches.sh
9+
RUN chmod +x /tmp/apply_security_patches.sh
10+
RUN /tmp/apply_security_patches.sh
3711

3812
# Reset and copy updated files with updated privs to keep image size down
3913
FROM mcr.microsoft.com/devcontainers/base:1-bullseye
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
vulnerable_packages=( "pydantic=2.5.3" "joblib=1.3.1" "mistune=3.0.1" "werkzeug=3.0.3" "transformers=4.36.0" "pillow=10.3.0" "aiohttp=3.9.4" \
4+
"cryptography=42.0.4" "gitpython=3.1.41" "jupyter-lsp=2.2.2" "idna=3.7" "jinja2=3.1.4" "scrapy=2.11.2" )
5+
6+
# Define the number of rows (based on the length of vulnerable_packages)
7+
rows=${#vulnerable_packages[@]}
8+
9+
# Define the number of columns
10+
cols=2
11+
12+
# Define the 2D array
13+
declare -A packages_array
14+
15+
# Fill the 2D array
16+
for ((i=0; i<rows; i++)); do
17+
# Split each element of vulnerable_packages by the '=' sign
18+
IFS='=' read -ra parts <<< "${vulnerable_packages[$i]}"
19+
# Assign the parts to the 2D array
20+
packages_array[$i,0]=${parts[0]}
21+
packages_array[$i,1]=${parts[1]}
22+
done
23+
24+
for ((i=0; i<rows; i++)); do
25+
CURRENT_VERSION=$(pip show "${packages_array[$i,0]}" --disable-pip-version-check | grep '^Version:' | awk '{print $2}')
26+
REQUIRED_VERSION="${packages_array[$i,1]}"
27+
GREATER_VERSION_A=$((echo ${REQUIRED_VERSION}; echo ${CURRENT_VERSION}) | sort -V | tail -1)
28+
# Check if the required_version is greater than current_version
29+
if [[ $CURRENT_VERSION != $GREATER_VERSION_A ]]; then
30+
echo "${packages_array[$i,0]} version v${CURRENT_VERSION} installed by the base image is not greater or equal to the required: v${REQUIRED_VERSION}"
31+
# Check whether conda channel has a greater or equal version available, so install from conda, otherwise use pip package manager
32+
channel_name="anaconda"
33+
CONDA_VERSION=$(conda search --override-channels "${packages_array[$i,0]}" -c "$channel_name" | \
34+
grep -E '^[[:alnum:]]' | \
35+
awk '{print $2}' | \
36+
sort -V | \
37+
uniq | \
38+
tail -n 2 | \
39+
head -n 1)
40+
if [[ -z "$CONDA_VERSION" ]]; then
41+
echo "No version for ${packages_array[$i,0]} found in conda channel."
42+
CONDA_VERSION="0"
43+
fi
44+
GREATER_VERSION_B=$((echo ${REQUIRED_VERSION}; echo ${CONDA_VERSION}) | sort -V | tail -1)
45+
if [[ $CONDA_VERSION == $GREATER_VERSION_B ]]; then
46+
echo -e "Found Version v${CONDA_VERSION} in the Conda channel which is greater than or equal to the required version: v${REQUIRED_VERSION}. \n";
47+
echo "Installing ${packages_array[$i,0]} from source from conda channel for v${REQUIRED_VERSION}..."
48+
conda install "${packages_array[$i,0]}==${CONDA_VERSION}"
49+
elif [[ $REQUIRED_VERSION == $GREATER_VERSION_B ]]; then
50+
echo -e "Required version: v${REQUIRED_VERSION} is greater than the version found in the Conda channel v${CONDA_VERSION}. \n";
51+
echo "Installing ${packages_array[$i,0]} from source from pip package manager for v${REQUIRED_VERSION}..."
52+
python3 -m pip install --upgrade --no-cache-dir "${packages_array[$i,0]}==${REQUIRED_VERSION}"
53+
fi
54+
fi
55+
done

0 commit comments

Comments
 (0)