fetch2/wget: add Basic Auth from netrc to checkstatus()
PATCH 1/1 fetch2/wget: add Basic Auth from netrc to checkstatus()
fetch2/wget uses urllib to check the status of the mirrors, wget will use netrc to pass login and password information however checkstatus will skip that.
This adds netrc login and password to checkstatus so both will work the same.
--- lib/bb/fetch2/wget.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
lib/bb/fetch2/wget.py +14 -2
@@ -305,12 +305,24 @@ class Wget(FetchMethod): r = urllib.request.Request(uri) r.get_method = lambda: "HEAD" - if ud.user: + def add_basic_auth(login_str, request): + '''Adds Basic auth to http request, pass in login:password as string''' import base64 - encodeuser = base64.b64encode(ud.user.encode('utf-8')).decode("utf-8") + encodeuser = base64.b64encode(login_str.encode('utf-8')).decode("utf-8") authheader = "Basic %s" % encodeuser r.add_header("Authorization", authheader) + if ud.user: + add_basic_auth(ud.user, r) + + try: + import netrc, urllib.parse + n = netrc.netrc() + login, unused, password = n.authenticators(urllib.parse.urlparse(uri).hostname) + add_basic_auth("%s:%s" % (login, password), r) + except (ImportError, IOError, netrc.NetrcParseError): + pass + opener.open(r) except urllib.error.URLError as e: if try_again:
Signature · 1 line
2.7.4
There was a recent change to wget that allows it to do an 'ASKPASS' when it needs credentials.
This is how we handle that at Wind River. We define a WGET_ASKPASS program that knows how to answer the credential questions [or prompt the user outside of the build system, i.e. via gnome].
(Passing anything on the command line, or even via .netrc is really dangerous. The command line due to 'ps' leakage on a multi-user system, and .netrc as the credentials are stored in plain text.)
Anyway, something to consider.
--Mark
Quoted 44 lines · Matthew McClintock
fetch2/wget uses urllib to check the status of the mirrors, wget will use netrc to pass login and password information however checkstatus will skip that.
This adds netrc login and password to checkstatus so both will work the same.
Signed-off-by Matthew McClintock <[email protected]>--- lib/bb/fetch2/wget.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)lib/bb/fetch2/wget.py +14
-2@@ -305,12 +305,24 @@ class Wget(FetchMethod): r = urllib.request.Request(uri) r.get_method = lambda: "HEAD" - if ud.user: + def add_basic_auth(login_str, request): + '''Adds Basic auth to http request, pass in login:password as string''' import base64 - encodeuser = base64.b64encode(ud.user.encode('utf-8')).decode("utf-8") + encodeuser = base64.b64encode(login_str.encode('utf-8')).decode("utf-8") authheader = "Basic %s" % encodeuser r.add_header("Authorization", authheader) + if ud.user: + add_basic_auth(ud.user, r) + + try: + import netrc, urllib.parse + n = netrc.netrc() + login, unused, password = n.authenticators(urllib.parse.urlparse(uri).hostname) + add_basic_auth("%s:%s" % (login, password), r) + except (ImportError, IOError, netrc.NetrcParseError): + pass + opener.open(r) except urllib.error.URLError as e: if try_again:
Quoted 6 lines · Mark Hatle
There was a recent change to wget that allows it to do an 'ASKPASS' when it needs credentials.
This is how we handle that at Wind River. We define a
WGET_ASKPASSprogram that knows how to answer the credential questions [or prompt the user outside of the build system, i.e. via gnome].
This is somewhat tangential to the patch above though? You could still do both.
Quoted 3 lines
(Passing anything on the command line, or even via .netrc is really dangerous. The command line due to 'ps' leakage on a multi-user system, and .netrc as the credentials are stored in plain text.)
I'm confused how is .netrc dangerous in this regard? The python library actually won't use netrc if the permissions on the file are wrong but I'm not aware of how there is leakage here? Maybe you're just warning against parsing and adding to the command line?
-M
Quoted 9 lines · Matthew McClintock
Quoted 6 lines · Mark Hatle
There was a recent change to wget that allows it to do an 'ASKPASS' when it needs credentials.
This is how we handle that at Wind River. We define a
WGET_ASKPASSprogram that knows how to answer the credential questions [or prompt the user outside of the build system, i.e. via gnome].This is somewhat tangential to the patch above though? You could still do both.
Yes it is.
Quoted 8 lines
Quoted 3 lines
(Passing anything on the command line, or even via .netrc is really dangerous. The command line due to 'ps' leakage on a multi-user system, and .netrc as the credentials are stored in plain text.)
I'm confused how is .netrc dangerous in this regard? The python library actually won't use netrc if the permissions on the file are wrong but I'm not aware of how there is leakage here? Maybe you're just warning against parsing and adding to the command line?
The credentials are stored in plain text in .netrc. This is a problem on multiuser machines, as often user home directories are world accessible, and often users forget to mark things like .netrc as private.
Any time a credential is stored in plain text is potentially dangerous if someone can access the users directory. (I don't consider .ssh credentials in the same category because people and ssh enforce the permissions on the directory for security reasons. wget does not.)
Quoted 2 lines
-M
Quoted 5 lines · Mark Hatle
Quoted 4 lines
I'm confused how is .netrc dangerous in this regard? The python library actually won't use netrc if the permissions on the file are wrong but I'm not aware of how there is leakage here? Maybe you're just warning against parsing and adding to the command line?
Quoted 8 lines
The credentials are stored in plain text in .netrc. This is a problem on multiuser machines, as often user home directories are world accessible, and often users forget to mark things like .netrc as private.
Any time a credential is stored in plain text is potentially dangerous if someone can access the users directory. (I don't consider .ssh credentials in the same category because people and ssh enforce the permissions on the directory for security reasons. wget does not.)
Well you can only go so far to protect users, perhaps we could add a usenetrc=true flag to URI's and then error if the permissions are wrong or even just throw the error from the netrc python lib instead of catching it?
Currently though wget uses netrc and python checkstatus does not so I'd claim this is broken as-is.
-M
Quoted 15 lines · Matthew McClintock
Quoted 5 lines · Mark Hatle
Quoted 4 lines
I'm confused how is .netrc dangerous in this regard? The python library actually won't use netrc if the permissions on the file are wrong but I'm not aware of how there is leakage here? Maybe you're just warning against parsing and adding to the command line?
Quoted 8 lines
The credentials are stored in plain text in .netrc. This is a problem on multiuser machines, as often user home directories are world accessible, and often users forget to mark things like .netrc as private.
Any time a credential is stored in plain text is potentially dangerous if someone can access the users directory. (I don't consider .ssh credentials in the same category because people and ssh enforce the permissions on the directory for security reasons. wget does not.)
Quoted 4 lines
Well you can only go so far to protect users, perhaps we could add a usenetrc=true flag to URI's and then error if the permissions are wrong or even just throw the error from the netrc python lib instead of catching it?
I consider this an issue with the programs using the netrc, not bitbake or others. (Plus the bitbake can be adjusted to use curl or other programs, not just wget that may have different semantics, via re-defining the FETCHCMD_wget)
I just wanted to call this out as an issue, because it has been problematic in the past for us and we had to devise a solution that worked without the .netrc.
Quoted 2 lines
Currently though wget uses netrc and python checkstatus does not so I'd claim this is broken as-is.
Agreed.
--Mark
Quoted 2 lines
-M