Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Add a group for conda commands #26

Merged
merged 4 commits into from
Apr 5, 2023
Merged

Conversation

raydouglass
Copy link
Member

@raydouglass raydouglass commented Mar 27, 2023

In order for downstream images to install conda packages as a non-root user, we should install the conda environment & packages writable by a group. So this image will now create a conda group and ensure permissions are set for group access.

Downstream images can reuse this conda group.

Required for rapidsai/docker#539

I tested locally like so:

docker buildx build -f Dockerfile -t rapidsai/mambaforge-cuda-777:cuda11.8.0-base-ubuntu22.04-py3.10 --build-arg CUDA_VER=11.8.0 --build-arg LINUX_VER=ubuntu22.04 --build-arg PYTHON_VER=3.10 .

Then build this Dockerfile:

FROM rapidsai/mambaforge-cuda-777:cuda11.8.0-base-ubuntu22.04-py3.10

RUN useradd -rm -d /home/rapids -s /bin/bash -g conda -u 1001 rapids

USER rapids

RUN mamba install -n base -y curl

@raydouglass raydouglass self-assigned this Mar 27, 2023
Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

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

I'd like to see a solution that doesn't modify everything to be executable (+x). It also doesn't feel like we're using privileges correctly. We should be able to resolve this by changing users before installing mamba, or some other way?

@raydouglass raydouglass requested a review from bdice March 27, 2023 19:03
Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

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

This is much closer to what I was hoping for! Let's rename the PR title to match the implementation, and I have one question about whether we should re-order some commands. Otherwise this could be merged in its current state.

Dockerfile Outdated
find /opt/conda -follow -type f -name '*.pyc' -delete; \
conda clean -afy;

USER root
Copy link
Contributor

@bdice bdice Mar 27, 2023

Choose a reason for hiding this comment

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

Should we execute the apt-get and other "root" commands first, before copying in conda as the non-root user? Does the image need to end up in "root" mode? It would save us from switching users twice.

@raydouglass raydouglass changed the title Add chmod -R 777 to /opt/conda Add non-root user for conda commands Mar 27, 2023
Copy link
Member

@ajschmidt8 ajschmidt8 left a comment

Choose a reason for hiding this comment

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

in an attempt to keep the changes to the base images to a minimum, I think we should experiment with the suggestions linked below.

they suggest utilizing linux groups to provide write access to a global conda installation.

so we could set up the group in this base image, but create the user in the downstream end-user images.

If this works, I think this should be the approach we adopt

@raydouglass raydouglass requested a review from bdice March 30, 2023 18:25
@raydouglass raydouglass changed the title Add non-root user for conda commands Add a group for conda commands Mar 30, 2023
@raydouglass
Copy link
Member Author

they suggest utilizing linux groups to provide write access to a global conda installation.

The latest commit now uses a conda group and some chmod/umask commands to control the write/setgid permissions. This appears to work for downstream images.

Copy link
Member

@ajschmidt8 ajschmidt8 left a comment

Choose a reason for hiding this comment

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

Changeset

diff --git a/Dockerfile b/Dockerfile
index fccc8ff..7b31691 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,6 @@
 ARG CUDA_VER=11.4.0
 ARG LINUX_VER=ubuntu20.04
-FROM nvidia/cuda:${CUDA_VER}-base-${LINUX_VER}
+FROM nvidia/cuda:${CUDA_VER}-base-${LINUX_VER} as base
 
 ARG LINUX_VER
 ARG PYTHON_VER=3.9
@@ -61,3 +61,11 @@ RUN case "${LINUX_VER}" in \
       echo "Unsupported LINUX_VER: ${LINUX_VER}" && exit 1; \
       ;; \
   esac
+
+FROM base as enduser
+
+RUN useradd -m -g conda rapids;
+
+USER rapids
+
+RUN mamba install -y django; conda remove -y --force-remove cffi

I tested this PR locally by running docker build . with the changeset above and confirmed that the non-root user had access to add and remove packages from the base environment.

@raydouglass raydouglass merged commit c51ddb0 into rapidsai:main Apr 5, 2023
@raydouglass raydouglass deleted the chmod-777 branch April 5, 2023 17:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants