Skip to content

Build package with local UID/GID and fast-retrieve app/package information #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2021
Merged
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
8 changes: 5 additions & 3 deletions monai/deploy/packager/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@ def build_image(args: dict, temp_dir: str):
dockerignore_file.write(docker_ignore_template)

# Build dockerfile into an MAP image
docker_build_cmd = ["docker", "build", "-f", docker_file_path, "-t", tag, temp_dir]
docker_build_cmd = f'''docker build -f "{docker_file_path}" -t {tag} "{temp_dir}"'''
if sys.platform != "win32":
docker_build_cmd += """ --build-arg MONAI_UID=$(id -u) --build-arg MONAI_GID=$(id -g)"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, the user ID and group of the current logged-on user is used to as MONAI_UID in the Docker that can potentially be run on any other server or in another logged-on user's env. Does not sound right to me.

General security principal is that you never do this, instead, a service account needs to be defined, and at deployment time, the account is configured/assigned to the app. It will be important to declare the intensions in this code.

This will work if the same user creates the MAP and then runs the MAP in the same env. What happens if this MAP is run by any other user (say 1000 creates it, 1003 runs it, and 1003 could be in a completely different set of groups)?

if no_cache:
docker_build_cmd.append("--no-cache")
proc = subprocess.Popen(docker_build_cmd, stdout=subprocess.PIPE)
docker_build_cmd += " --no-cache"
proc = subprocess.Popen(docker_build_cmd, stdout=subprocess.PIPE, shell=True)

spinner = ProgressSpinner("Building MONAI Application Package... ")
spinner.start()
Expand Down
10 changes: 8 additions & 2 deletions monai/deploy/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ def fetch_map_manifest(map_name: str) -> Tuple[dict, dict, int]:
logger.info("\nReading MONAI App Package manifest...")

with tempfile.TemporaryDirectory() as info_dir:
cmd = f"docker run --rm -a STDOUT -a STDERR -v {info_dir}:/var/run/monai/export/config {map_name}"

if sys.platform == "win32":
cmd = f'docker run --rm -a STDOUT -a STDERR -v "{info_dir}":/var/run/monai/export/config {map_name}'
else:
cmd = f"""docker_id=$(docker create {map_name})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This whole set of commands can be encapsulated in a method, and Docker SDK used to make it more robust and easier to handle exception.

In any case, It is a good change; don't run docker when one only needs to copy files from within the Docker image.

docker cp $docker_id:/etc/monai/app.json "{info_dir}/app.json"
docker cp $docker_id:/etc/monai/pkg.json "{info_dir}/pkg.json"
docker rm -v $docker_id > /dev/null
"""
returncode = run_cmd(cmd)
if returncode != 0:
return {}, {}, returncode
Expand Down