Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/python/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,19 @@ if [[ "${INSTALL_PYTHON_TOOLS}" = "true" ]] && [[ $(python --version) != "" ]];
echo "${util} already installed. Skipping."
fi
done

# Temporary: Removes “setup tools” metadata directory due to https://github.com/advisories/GHSA-r9hx-vwmv-q579

VULNERABLE_VERSIONS=("3.10" "3.11")

for vv in "${VULNERABLE_VERSIONS[@]}"; do

if [ "${PYTHON_VERSION}" == "${vv}" ]; then
rm -rf ${PIPX_HOME}/shared/lib/"python${vv}"/site-packages/setuptools-65.5.0.dist-info
#rm -rf ${PYTHON_INSTALL_PATH}/"${VERSION}"/lib/python${vv}/site-packages/setuptools-65.5.0.dist-info

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this comment?

@bhupendra-vaishnav bhupendra-vaishnav Jan 26, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove that but I would like to highlight that sometime another directory will get created for setuptools-65.5.0 do so you want us to remove that or not?

The other option is to the check the version for dynamically which I can further look into that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

highlight that sometime another directory will get created for setuptools-65.5.0

Do you have a scenario or reproduction for this? Are you aware of the drawbacks of removing that directory?

We shouldn't add code or comments if it's not 💯 needed. However, if the scanners complain about it, then we can definitely add it back.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented a way to dynamically fetch the python version so now no issue.

fi
done

rm -rf /tmp/pip-tmp

updaterc "export PIPX_HOME=\"${PIPX_HOME}\""
Expand Down
68 changes: 68 additions & 0 deletions test/python/install_python_setuptools_vulnerability.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

#check "setuptools version 65.5.0 not installed" bash -c "ls -lrt /usr/local/py-utils/shared/lib/python3.11/site-packages/setuptools-65.5.0.dist-info"
#checkPythonPackageVersion "setuptools" "65.5.1"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this check?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# Check that tools can execute - make sure something didn't get messed up in this scenario
check "autopep8" autopep8 --version
check "black" black --version
check "yapf" yapf --version
check "bandit" bandit --version
check "flake8" flake8 --version
check "mypy" mypy --version
check "pycodestyle" pycodestyle --version
check "pydocstyle" pydocstyle --version
check "pylint" pylint --version
check "pytest" pytest --version
check "setuptools" pip list | grep setuptools

# Check paths in settings
check "current symlink is correct" bash -c "which python | grep /usr/local/python/current/bin/python"
check "current symlink works" /usr/local/python/current/bin/python --version
check "which autopep8" bash -c "which autopep8 | grep /usr/local/py-utils/bin/autopep8"
check "which black" bash -c "which black | grep /usr/local/py-utils/bin/black"
check "which yapf" bash -c "which yapf | grep /usr/local/py-utils/bin/yapf"
check "which bandit" bash -c "which bandit | grep /usr/local/py-utils/bin/bandit"
check "which flake8" bash -c "which flake8 | grep /usr/local/py-utils/bin/flake8"
check "which mypy" bash -c "which mypy | grep /usr/local/py-utils/bin/mypy"
check "which pycodestyle" bash -c "which pycodestyle | grep /usr/local/py-utils/bin/pycodestyle"
check "which pydocstyle" bash -c "which pydocstyle | grep /usr/local/py-utils/bin/pydocstyle"
check "which pylint" bash -c "which pylint | grep /usr/local/py-utils/bin/pylint"
check "which pytest" bash -c "which pytest | grep /usr/local/py-utils/bin/pytest"

echoStderr()
{
echo "$@" 1>&2
}

checkVulnerableDir()
{
DIRECTORY=$1
VERSION=$2

if [ "${VERSION}" == "3.10" ] && [ -d $DIRECTORY ] ; then
echoStderr "❌ check for vulnerable setuptools version failed for python3.10."
return 1
elif [ "${VERSION}" == "3.11" ] && [ -d $DIRECTORY ]; then
echoStderr "❌ check for vulnerable setuptools version failed for python3.11."
return 1
else
echo "✅ Passed! Either the container does not have vulnerable version or vulnerable version specific directory got removed."
return 0
fi
}

# only for 3.10
checkVulnerableDir "/usr/local/py-utils/shared/lib/python3.10/site-packages/setuptools-65.5.0.dist-info" "3.10"
checkVulnerableDir "/usr/local/python/3.10.13/lib/python3.10/site-packages/setuptools-65.5.0.dist-info" "3.10"
# only for 3.11
checkVulnerableDir "/usr/local/py-utils/shared/lib/python3.11/site-packages/setuptools-65.5.0.dist-info" "3.11"
checkVulnerableDir "/usr/local/python/3.11.7/lib/python3.11/site-packages/setuptools-65.5.0.dist-info" "3.11"

# Report result

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add the following command? this way we can see the status of the files.

find . -name "*setuptools*"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

reportResults
9 changes: 9 additions & 0 deletions test/python/scenarios.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"install_python_setuptools_vulnerability": {
"image": "debian:bookworm",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you address previous comment, can you also add a new test scenario with image python:3:11 ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in PR # 815

"features": {
"python": {
"version": "3.10",
"installTools": true
}
Comment on lines +3 to +8

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"image": "debian:bookworm",
"features": {
"python": {
"version": "3.10",
"installTools": true
}
"image": "python:3:10",
"features": {
"python": {
"version": "none",
"installTools": true
}

Can we update the scenario to reflect the python image build?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the points that I wanted to discuss with you. The moment we move to version as "none" the code in install.sh will not work.

@samruddhikhandale samruddhikhandale Jan 26, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code in install.sh will not work.

Can you help specify the code are you referring at? Can you paste some links?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have create a separate code set with different branch name and created a PR. Its by Gaurav and the details are as below :
python : #815
debian : #814

If Debian work in context with Debian image is not require then we can reject PR # 814.

}
},
"install_additional_python": {
"image": "ubuntu:focal",
"features": {
Expand Down