NVFlare icon indicating copy to clipboard operation
NVFlare copied to clipboard

Remove external 'zip' dependency from DistributionBuilder (zip_password=True)

Open parkeraddison opened this issue 4 years ago • 3 comments

Hi there, first off I want to acknowledge your efforts towards making an incredible tool, thank you!

The issue: I faced the exception FileNotFoundError: [Errno 2] No such file or directory: 'zip' when trying to specify zip_password: true for the DistributionBuilder args while running provision -p project.yml, and tracked the cause to zip not being installed on the local machine, which was a problem since installing additional software is not allowed on that machine.

Replicate

# Launch a docker container with image python:3.8 running interactive bash
docker run -it --rm python:3.8 bash

# === Within docker container ===
pip install nvflare
provision # create example project.yml

# Set zip_password to true
sed -i 's/zip_password: false/zip_password: true/' project.yml

provision -p project.yml

We will find the following output:

Project yaml file: /project.yml.
Exception raised during provision.  Incomplete prod_n folder removed.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/nvflare/lighter/spec.py", line 166, in provision
    b.build(study, ctx)
  File "/usr/local/lib/python3.8/site-packages/nvflare/lighter/impl/workspace.py", line 109, in build
    subprocess.run(run_args)
  File "/usr/local/lib/python3.8/subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/local/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'zip'

Whereas it'll work if we install zip

# === Within docker container ===
apt-get update && apt-get install -y zip
provision -p project.yml

Fix

The build function of the DistributionBuilder uses shutil to make the non-password protected zip but relies on subprocess.run(['zip', ...]) in order to create password-protected files, since shutil doesn't support passwords.

I'd propose adding a package requirement of something like pyminizip or pyzipper to handle password protection.

https://github.com/NVIDIA/NVFlare/blob/c8d51bfb534c02eff874a760c47086c87cbff59f/nvflare/lighter/impl/workspace.py#L100-L113

parkeraddison avatar Jun 03 '22 01:06 parkeraddison

I think another option is to either remove the password option or remove the DistributionBuilder completely. That builder does nothing but zip the folder one by one. Most likely, users can do that with their familiar tools.

IsaacYangSLA avatar Jun 06 '22 17:06 IsaacYangSLA

Hi @parkeraddison ,

Thanks for the report and suggestion.

If we introduce another pypi package, from release perspective, we will need to include their licenses and do some security scans.

We added a text in docstring to specify that if people want to use this builder (with zip password), they need to install "zip".

Otherwise, as @IsaacYangSLA mentioned, some folders will be generated and if users need to zip these folders, they can do it using the tools they have.

YuanTingHsieh avatar Jun 07 '22 20:06 YuanTingHsieh

That all makes a lot of sense, thanks for the reply

parkeraddison avatar Jun 16 '22 23:06 parkeraddison