Bug 197164 - webkitpy auto installer should download packages using `curl` instead of python's urllib.
Summary: webkitpy auto installer should download packages using `curl` instead of pyth...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Dean Johnson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-04-22 10:31 PDT by Dean Johnson
Modified: 2019-04-22 15:08 PDT (History)
8 users (show)

See Also:


Attachments
Patch (2.37 KB, patch)
2019-04-22 13:39 PDT, Dean Johnson
no flags Details | Formatted Diff | Diff
Patch (2.28 KB, patch)
2019-04-22 14:25 PDT, Dean Johnson
no flags Details | Formatted Diff | Diff
Patch (2.28 KB, patch)
2019-04-22 14:27 PDT, Dean Johnson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dean Johnson 2019-04-22 10:31:32 PDT
I think webkitpy's auto installer should use `curl` to download packages instead of Python's urllib2 library. There are many reasons for this:
1. urllib2 can fail with obscure messages due to failures to TLS versions[1] or permissions on certs[2]. These messages could be communicated back to the user, but they generally do not have clear solutions to them.
2. Hashes for expected packages are already stored in Tools/Scripts/webkitpy/thirdparty/__init__.py.

So using `curl`, we could get around TLS version issues and cert permission issues using --no-verify, but also still guarantee we're getting the package we expect by checking the hashes of the downloaded packages against what they are known to be.

I'm not sure if this should be done for Windows as well, but would err on the side of caution and say to use the default behavior on Windows until someone was able to verify the same codepath worked.

[1] via https://bugs.webkit.org/show_bug.cgi?id=197046 - <urlopen error [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)>
[2] via https://bugs.webkit.org/show_bug.cgi?id=197046 - <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>
Comment 1 Jonathan Bedard 2019-04-22 10:40:55 PDT
(In reply to Dean Johnson from comment #0)
> I think webkitpy's auto installer should use `curl` to download packages
> instead of Python's urllib2 library. There are many reasons for this:
> 1. urllib2 can fail with obscure messages due to failures to TLS versions[1]
> or permissions on certs[2]. These messages could be communicated back to the
> user, but they generally do not have clear solutions to them.
> 2. Hashes for expected packages are already stored in
> Tools/Scripts/webkitpy/thirdparty/__init__.py.
> 
> So using `curl`, we could get around TLS version issues and cert permission
> issues using --no-verify, but also still guarantee we're getting the package
> we expect by checking the hashes of the downloaded packages against what
> they are known to be.
> 
> I'm not sure if this should be done for Windows as well, but would err on
> the side of caution and say to use the default behavior on Windows until
> someone was able to verify the same codepath worked.
> 
> [1] via https://bugs.webkit.org/show_bug.cgi?id=197046 - <urlopen error
> [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version
> (_ssl.c:590)>
> [2] via https://bugs.webkit.org/show_bug.cgi?id=197046 - <urlopen error
> [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>

I don't know that we'd get the SSL error with curl anyways, since curl definitely relies on the system certs, where Python's libraries are far less consistent in that regard.
Comment 2 Dean Johnson 2019-04-22 13:04:05 PDT
It looks like I was mis-remembering. webkitpy/common/system/autoinstall.py does not appear to have any notion of checking for the hash of the tarball that was downloaded.

So we can't use --no-verify to curl, but according to local testing it looks like even TLS version issues seen using `urllib2` are not a problem using `curl`.
Comment 3 Dean Johnson 2019-04-22 13:05:32 PDT
Submitted comment too early.

...are not a problem using `curl` *even when --no-verify is omitted*.
Comment 4 Dean Johnson 2019-04-22 13:39:11 PDT
Created attachment 367967 [details]
Patch
Comment 5 Darin Adler 2019-04-22 13:55:12 PDT
Comment on attachment 367967 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=367967&action=review

> Tools/ChangeLog:11
> +        * Scripts/webkitpy/common/system/autoinstall.py:
> +        (AutoInstaller._download): Use curl to download packages necessary for webkitpy/thirdparty/autoinstalled
> +        since Python2's urllib2 module sometimes spews useless error messages about TLS versions or certificate access
> +        even if invoking a command to do the same thing with `curl` would work without issue.

No elegant way to quiet the messages?
Comment 6 Dean Johnson 2019-04-22 14:18:36 PDT
(In reply to Darin Adler from comment #5)
> Comment on attachment 367967 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=367967&action=review
> 
> > Tools/ChangeLog:11
> > +        * Scripts/webkitpy/common/system/autoinstall.py:
> > +        (AutoInstaller._download): Use curl to download packages necessary for webkitpy/thirdparty/autoinstalled
> > +        since Python2's urllib2 module sometimes spews useless error messages about TLS versions or certificate access
> > +        even if invoking a command to do the same thing with `curl` would work without issue.
> 
> No elegant way to quiet the messages?

Thanks for the review.

I'll update the ChangeLog to make it more clear, but the issue being addressed is not the spewing of error messages, but rather that using Python2's urllib2 module for this download results in a variety of errors that don't give a clear indication of how they can be fixed. They also are errors that only seem to be shown by urllib2, since curl(1) does the package download without any issues.

This bug was primarily initiated based on the detailed bug report by yevseytsev in https://bugs.webkit.org/show_bug.cgi?id=197046, where the only way he was able to run our tests (after deleting the previous local admin user on macOS *2 years* ago) was to do a complete re-installation of his system.
Comment 7 Dean Johnson 2019-04-22 14:25:28 PDT
Created attachment 367973 [details]
Patch
Comment 8 Dean Johnson 2019-04-22 14:27:02 PDT
Created attachment 367974 [details]
Patch
Comment 9 WebKit Commit Bot 2019-04-22 15:07:53 PDT
Comment on attachment 367974 [details]
Patch

Clearing flags on attachment: 367974

Committed r244513: <https://trac.webkit.org/changeset/244513>
Comment 10 WebKit Commit Bot 2019-04-22 15:07:55 PDT
All reviewed patches have been landed.  Closing bug.
Comment 11 Radar WebKit Bug Importer 2019-04-22 15:08:28 PDT
<rdar://problem/50109280>