Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Add verify_ssl option to gluon.utils.download #11546

Merged
merged 5 commits into from
Jul 25, 2018
Merged

Conversation

leezu
Copy link
Contributor

@leezu leezu commented Jul 3, 2018

Description

Sometimes datasets may be hosted on servers that serve invalid SSL certificates. If so, this allow disabling the SSL certificate verification. The default behavior is not changed.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Add verify_ssl option to gluon.utils.download

Copy link
Contributor

@marcoabreu marcoabreu left a comment

Choose a reason for hiding this comment

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

Considering this is a security related feature, I'd prefer to have a unit test and a warning printed if that check is disabled. I'd like to emphasize that we as a project should never have any code served with this feature disabled. We should even think whether we want to open that box of Pandora. I think this needs a proper discussion before we employ that functionality.

@leezu
Copy link
Contributor Author

leezu commented Jul 4, 2018

@marcoabreu I agree that checking SSL certificates is important in general and should be (and is) the default. Still, when providing a utility function in gluon, we should let users judge and give them the option to disable SSL verification when necessary. For example, when SHA1 hashes of the to be downloaded files are hardcoded, the authenticity of the files can be verified based on the hash and little is lost by disabling SSL verification.

Again, I do not advocate to disable SSL support in general. However, there may be cases (such as external files which we must not redistribute hosted on a misconfigured server) where it is useful to disable SSL certificate verification. Without this PR, the download utility function is useless in those cases.

@larroy
Copy link
Contributor

larroy commented Jul 4, 2018

LGTM

with warnings.catch_warnings(record=True) as warnings_:
mx.gluon.utils.download(
"https://mxnet.incubator.apache.org/", verify_ssl=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would mock the call to requests to avoid doing network IO on a unit test.

Copy link
Contributor

@marcoabreu marcoabreu left a comment

Choose a reason for hiding this comment

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

LGTM besides the network access. As requested by Pedro, please mock it (or use localhost) and then we're good to go.

@larroy
Copy link
Contributor

larroy commented Jul 4, 2018

Is better to mock it, in python is super simple. Using localhost can also fail if the port is used, so best to avoid it. Let's not overcomplicate things. Mocking the request is easy:

https://stackoverflow.com/questions/15753390/how-can-i-mock-requests-and-the-response

@leezu
Copy link
Contributor Author

leezu commented Jul 9, 2018

Thanks. I have now changed all gluon.utils.download tests to make use of Mocking (the two tests already present before this PR caused network access).

@leezu leezu force-pushed the verifyssl branch 2 times, most recently from 0a55026 to 072dbf2 Compare July 9, 2018 21:45
@leezu
Copy link
Contributor Author

leezu commented Jul 10, 2018

Where are test dependencies currently tracked? This PR would introduce mock as a new dependency. For linux it seems I could add mock the list of installed packages in the CI setup shell scripts, but I am not sure about windows.

In case there is no centralized place to declare test/development dependencies, would it make sense to track these in the setup.py script and adapt the CI scripts to install via pip install -e '.[tests]' to also install these dependencies?

@szha
Copy link
Member

szha commented Jul 10, 2018

AFAIK windows CI slave images are still manually built. @marcoabreu might have update

@larroy
Copy link
Contributor

larroy commented Jul 10, 2018

We can workaround this by adding pip install mock after the activate call on the Jenkinsfile . parametrization of windows host is starting now and will take a while.

Yes they are manually built.

Sometimes datasets may be hosted on servers that serve invalid SSL certificates.
@szha szha merged commit 07a9977 into apache:master Jul 25, 2018
@leezu leezu deleted the verifyssl branch July 25, 2018 16:53
XinYao1994 pushed a commit to XinYao1994/incubator-mxnet that referenced this pull request Aug 29, 2018
* Add verify_ssl option to gluon.utils.download

Sometimes datasets may be hosted on servers that serve invalid SSL certificates.

* Add warning

* Add test

* Mock gluon.utils.download tests

* Add Py2 mock dependency to Jenkinsfile
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.

None yet

4 participants