Skip to contentSkip to conversation

fetch2/git.py: Added handling of the user's password in url

PATCH In review Jakub Dębski 5 participants 6 messages Apr 12, 2018 – Apr 18, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2/git.py: Added handling of the user's password in url

Fetching source code from private repository (using https or http) fails because password passed in url (git://user:pass@domain) is ignored.

---
 lib/bb/fetch2/git.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
lib/bb/fetch2/git.py +6 -3
index 3de83be..6600e19 100644
@@ -527,10 +527,13 @@ class Git(FetchMethod):
         Return the repository URL
         """
         if ud.user:
-            username = ud.user + '@'
+            if ud.pswd:
+                userinfo = ud.user + ':' + ud.pswd '@'
+            else:
+                userinfo = ud.user + '@'
         else:
-            username = ""
-        return "%s://%s%s%s" % (ud.proto, username, ud.host, ud.path)
+            userinfo = ""
+        return "%s://%s%s%s" % (ud.proto, userinfo, ud.host, ud.path)
 
     def _revision_key(self, ud, d, name):
         """
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 lines · Jakub Dębski

Fetching source code from private repository (using https or http) fails because password passed in url (git://user:pass@domain) is ignored.

Maybe this is by design to prevent credentials leaking into bitbake recipes.

Alternative is to set the usernames, passwords etc in e.g. ~/.netrc and ~/.ssh/config files which have the same effect.

-Mikko

#2 lore raw
Quoted 7 lines

Maybe this is by design to prevent credentials leaking into bitbake recipes.

Alternative is to set the usernames, passwords etc in e.g. ~/.netrc and ~/.ssh/config files which have the same effect.

-Mikko

Certainly, credentials could be set in other ways, but there is some inconsistency with other fetchers (e.g. perforce, wget, hg) which use password from SRC_URI.

--
Jakub Dębski

#3 lore raw
Quoted 11 lines · Jakub Dębski
Quoted 7 lines

Maybe this is by design to prevent credentials leaking into bitbake recipes.

Alternative is to set the usernames, passwords etc in e.g. ~/.netrc and ~/.ssh/config files which have the same effect.

-Mikko

Certainly, credentials could be set in other ways, but there is some inconsistency with other fetchers (e.g. perforce, wget, hg) which use password from SRC_URI.

that merits an entry in bugzilla

#4 lore raw
In reply to [email protected]
Quoted 9 lines · On 4/12/18 5:16 AM, [email protected] wrote:
Quoted 2 lines · Jakub Dębski

Fetching source code from private repository (using https or http) fails because password passed in url (git://user:pass@domain) is ignored.

Maybe this is by design to prevent credentials leaking into bitbake recipes.

Alternative is to set the usernames, passwords etc in e.g. ~/.netrc and ~/.ssh/config files which have the same effect.

Yes, this has come up a few times in the past, and it's been rejected -- as we don't want credentials to end up in bitbake. (Way too easy to accidentally leak them to others.)

--Mark

Quoted 2 lines

-Mikko

#5 lore raw
In reply to Jakub Dębski
Quoted 3 lines · Jakub Dębski

Fetching source code from private repository (using https or http) fails because password passed in url (git://user:pass@domain) is ignored.

this is a security issue since SRC_URIs get into the package metadata
infact a patch to detect this case and warn/error about it will be better. You might want to use .netrc to specify the credentials.

Quoted 27 lines
---
  lib/bb/fetch2/git.py | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
lib/bb/fetch2/git.py +6 -3
index 3de83be..6600e19 100644
@@ -527,10 +527,13 @@ class Git(FetchMethod):
          Return the repository URL
          """
          if ud.user:
-            username = ud.user + '@'
+            if ud.pswd:
+                userinfo = ud.user + ':' + ud.pswd '@'
+            else:
+                userinfo = ud.user + '@'
          else:
-            username = ""
-        return "%s://%s%s%s" % (ud.proto, username, ud.host, ud.path)
+            userinfo = ""
+        return "%s://%s%s%s" % (ud.proto, userinfo, ud.host, ud.path)
 
      def _revision_key(self, ud, d, name):
          """