-
Notifications
You must be signed in to change notification settings - Fork 179
New feature: Safe repo urls #642
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
Conversation
It looks like local paths are not treated specially. They should be considered "secure". |
What do you mean by "local paths"? |
|
The patch wasn't/isn't ready for PR. Could you please close it? |
@screamerbg Sure. What does it need? |
@theotherjimmy More work and wider testing. I started writing remote tests for this, that also use py.test too enhance test coverage. It's a very obtrusive rewrite of the url handling. |
Thanks. The current CI did show an issue with handling of local paths with this change. |
188a4eb
to
c6a08a4
Compare
@theotherjimmy Reopened and fixed issues. |
Thanks @screamerbg. For testing, should I just build and test directly from this branch? Or should I merge this PR back into master? Or merge into your apparent v1.5.0 WIP (development from your repo)? |
@screamerbg I have updated the PR description with the wonderful motivation section you wrote in #621 |
ff7b971
to
0039628
Compare
@bmcdonnell-ionx I just rebased my branch on top of master (now the 1.5.0 release) |
Setup
OK, I did the same.
ResultsI came across some unexpected results, so I didn't run every conceivable test. Here's what I have so far...
|
mbed/mbed.py
Outdated
# Safely convert repo URL to https schema if this is a public SCM service (github/butbucket), supporting all schemas. | ||
# This allows anonymous cloning of public repos without having to have ssh keys and associated accounts at github/bitbucket/etc. | ||
# Without this anonymous users will get clone errors with ssh repository links even if the repository is public. | ||
# See hhttps://help.github.com/articles/which-remote-url-should-i-use/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo "hhttps" -> "https"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo "hhttps" -> "https"
Basically, yes. |
@theotherjimmy Is that desired behavior? |
@bmcdonnell-ionx That's a question for @screamerbg. |
@@ -328,7 +325,7 @@ def cleanup(): | |||
shutil.rmtree(fl) | |||
|
|||
def clone(url, path=None, depth=None, protocol=None): | |||
m = Bld.isurl(url) | |||
m = Bld.isvalidurl(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that cloning a repo from the filesystem is not supported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bld is emulation of SCM. It only exists as a function of the mbed Website.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I would say that Bld is not SCM, but is supported by Mbed CLI. just my 2c.
return re.match(regex_build_url, m_url.group(1)) | ||
else: | ||
return False | ||
|
||
def init(path): | ||
if not os.path.exists(path): | ||
os.mkdir(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silly question. Are we assuming that this will always work (say, in the case where a user attempts to create a directory where they don't have permissions to)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bld.init()
is called within try:
statement. See Bld.clone()
below.
mbed/mbed.py
Outdated
@classmethod | ||
def isinsecure(cls, url): | ||
up = urlparse(url) | ||
return not up or (up.scheme and up.scheme not in ['http', 'https', 'ssh', 'git']) or (up.port and int(up.port) not in [22, 80, 443]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this suppose to read as (not up) or ...
or not (up or ...)
?
@bmcdonnell-ionx Yes. The point is not to nag you with On unrelated note, I just pushed a commit to escape cache paths based on repo url. Could you please try with the latest commit on the branch and see whether the cache warnings are now fixed. |
They are not.
|
@bmcdonnell-ionx I've introduced further changes to handle the cache paths with special characters that usually appear on Windows. Could you please retest? |
@screamerbg did you see my PR on your repo? |
@bmcdonnell-ionx Just did. Thank you! Now merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments.
mbed/mbed.py
Outdated
|
||
for _, scm in sorted_scms: | ||
info("Trying to guess source control management tool. Supported SCMs: %s" % ', '.join([s.name for s in scms.values()])) | ||
for _, scm in scms.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be written as:
for scm in scms.values()
this is okay if you don't want to change it.
mbed/mbed.py
Outdated
# Safely convert repo URL to https schema if this is a public SCM service (github/butbucket), supporting all schemas. | ||
# This allows anonymous cloning of public repos without having to have ssh keys and associated accounts at github/bitbucket/etc. | ||
# Without this anonymous users will get clone errors with ssh repository links even if the repository is public. | ||
# See hhttps://help.github.com/articles/which-remote-url-should-i-use/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo "hhttps" -> "https"
@screamerbg Technically, this is my PR, so you can review it! |
Since @screamerbg made the changes, I would think you and/or someone else should review, whether or not that satisfies whatever automated checks are in place. Or were you implying that you already did review, and you're satisfied? |
Yeah, I was implying that I had already reviewed this
…On Wed, Apr 11, 2018, 18:32 bmcdonnell-ionx ***@***.***> wrote:
@theotherjimmy <https://github.com/theotherjimmy>
@screamerbg <https://github.com/screamerbg> Technically, this is my PR,
so you can review it!
Since @screamerbg <https://github.com/screamerbg> made the changes, I
would think you and/or someone else should review, whether or not that
satisfies whatever automated checks are in place.
Or were you implying that you already did review, and you're satisfied?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#642 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAp1YaIcACrDDZgiOnTp4F1fgZL0ZDhJks5tnpKjgaJpZM4SsZSC>
.
|
@screamerbg, @theotherjimmy, @cmonr - Are further reviews necessary, or is it mergin' time? |
@bmcdonnell-ionx Someone, probably @screamerbg, still needs to add a token github review. Then we have all of the automated checks and can merge this. |
@screamerbg / @cmonr, per @theotherjimmy, can one of you add a "token review" and merge this? |
…epo URLs, including for ssh clone links used in Github Add support for host ports Add insecure option to `import`, `add`, `deploy` and `update`
…e (github/butbucket), supporting all schemas. This allows anonymous cloning of public repos without having to have ssh keys and associated accounts at github/bitbucket/etc. Without this anonymous users will get clone errors with ssh repository links even if the repository is public. See hhttps://help.github.com/articles/which-remote-url-should-i-use/
f9a4c13
to
2f47b91
Compare
I've just rebased this on top of master (1.5.1) and addressed some of the comments @theotherjimmy made. @theotherjimmy @cmonr Please review and thumbs up if you're happy with the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@screamerbg Looks good. Merge at will. |
Thanks! |
This series of commits adds a sense of "secure" and "insecure" URLs to Mbed CLI.
Security and Liability in Mbed CLI
A user of Mbed CLI does not know about every single repository URL that will be accessed/cloned during
mbed import
andmbed add
. Unlike thegit clone <url>
command, where end-user is de-facto aware what's being cloned (essentially it's a "consensual clone" as they can see the URL before executinggit
), Mbed CLI clones many repositories recursively without prior consent or user awareness, except for the starting repository or program URL.This poses some challenges, including legally, as an end-user could blame Mbed CLI for causing their
git
orhg
to try to access a funky URL/service port.For example, combining the recursive nature of Mbed CLI with bad intentions, could lead to terrifying results. It's not hard to imagine a malicious program containing 100s .lib files pointing at different ports at
b1-rtr0-hsrp.jpl.nasa.gov
(as repo URLs), which, once mbed CLI start cracking on it, would look a lot like port scanning. Making many connection attempts on a government monitored network, like NASA's, can get you in real trouble.Furthermore, in many corporate networks, any connection attempt on arbitrary ports (usually below port 1024), is being flagged, logged and reported - even if it was for all the good reasons.
With everything said above
--insecure
provides this user consent, effectively acting as a legally binding agreement that the end-user know what they're doing.Secure URLs
These URLs specify the scheme and either do not specify the port of the remote service, or specify the service to have port 22, 80 or 443.
Insecure URLs
Mbed CLI identifies insecure URLs as URLs that are missing scheme information, or specifie a port other than 22, 80 or 443. When an insecure URL is present on the command line, in a
.lib
file or in a.bld
file, Mbed CLI refuses to use the URL and exits with an error. A user may explicitly ask Mbed CLI to use these URLs by specifying the--insecure
option on the command line.