Skip to contentSkip to conversation

fetch2: obey BB_ALLOWED_NETWORKS when checking network access

PATCH In review Markus Lehtonen 2 participants 3 messages Nov 21, 2016 – Nov 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2: obey BB_ALLOWED_NETWORKS when checking network access

[YOCTO #10508]

---
 lib/bb/fetch2/__init__.py | 7 +++++--
 lib/bb/fetch2/git.py      | 4 ++--
 lib/bb/fetch2/hg.py       | 2 +-
 lib/bb/fetch2/npm.py      | 2 +-
 lib/bb/fetch2/perforce.py | 8 ++++----
 lib/bb/fetch2/svn.py      | 2 +-
 lib/bb/fetch2/wget.py     | 2 +-
 7 files changed, 15 insertions(+), 12 deletions(-)
lib/bb/fetch2/__init__.py +5 -2
index cd7362c..4bb7526 100644
@@ -856,12 +856,15 @@ def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None, workdir=None):
 
     return output
 
-def check_network_access(d, info = "", url = None):
+def check_network_access(d, info, url):
     """
-    log remote network access, and error if BB_NO_NETWORK is set
+    log remote network access, and error if BB_NO_NETWORK is set or the given
+    URI is untrusted
     """
     if d.getVar("BB_NO_NETWORK", True) == "1":
         raise NetworkAccess(url, info)
+    elif not trusted_network(d, url):
+        raise UntrustedUrl(url, info)
     else:
         logger.debug(1, "Fetcher accessed the network with the command %s" % info)
 
lib/bb/fetch2/git.py +2 -2
index 1bec60a..11d0b9c 100644
@@ -252,7 +252,7 @@ class Git(FetchMethod):
                 repourl = repourl[7:]
             clone_cmd = "LANG=C %s clone --bare --mirror %s %s --progress" % (ud.basecmd, repourl, ud.clonedir)
             if ud.proto.lower() != 'file':
-                bb.fetch2.check_network_access(d, clone_cmd)
+                bb.fetch2.check_network_access(d, clone_cmd, ud.url)
             progresshandler = GitProgressHandler(d)
             runfetchcmd(clone_cmd, d, log=progresshandler)
 
@@ -384,7 +384,7 @@ class Git(FetchMethod):
         cmd = "%s ls-remote %s %s" % \
               (ud.basecmd, repourl, search)
         if ud.proto.lower() != 'file':
-            bb.fetch2.check_network_access(d, cmd)
+            bb.fetch2.check_network_access(d, cmd, repourl)
         output = runfetchcmd(cmd, d, True)
         if not output:
             raise bb.fetch2.FetchError("The command %s gave empty output unexpectedly" % cmd, ud.url)
lib/bb/fetch2/hg.py +1 -1
index 20df801..dc87998 100644
@@ -221,7 +221,7 @@ class Hg(FetchMethod):
         """
         Compute tip revision for the url
         """
-        bb.fetch2.check_network_access(d, self._buildhgcommand(ud, d, "info"))
+        bb.fetch2.check_network_access(d, self._buildhgcommand(ud, d, "info"), ud.url)
         output = runfetchcmd(self._buildhgcommand(ud, d, "info"), d)
         return output.strip()
 
lib/bb/fetch2/npm.py +1 -1
index 699ae72..29faea1 100644
@@ -101,7 +101,7 @@ class Npm(FetchMethod):
 
     def _runwget(self, ud, d, command, quiet):
         logger.debug(2, "Fetching %s using command '%s'" % (ud.url, command))
-        bb.fetch2.check_network_access(d, command)
+        bb.fetch2.check_network_access(d, command, ud.url)
         dldir = d.getVar("DL_DIR", True)
         runfetchcmd(command, d, quiet, workdir=dldir)
 
lib/bb/fetch2/perforce.py +4 -4
index 50cb479..e332e7c 100644
@@ -71,7 +71,7 @@ class Perforce(FetchMethod):
             logger.debug(1, 'Trying to use P4CONFIG to automatically set P4PORT...')
             ud.usingp4config = True
             p4cmd = '%s info | grep "Server address"' % ud.basecmd
-            bb.fetch2.check_network_access(d, p4cmd)
+            bb.fetch2.check_network_access(d, p4cmd, ud.url)
             ud.host = runfetchcmd(p4cmd, d, True)
             ud.host = ud.host.split(': ')[1].strip()
             logger.debug(1, 'Determined P4PORT to be: %s' % ud.host)
@@ -140,7 +140,7 @@ class Perforce(FetchMethod):
         'p4 files' command, including trailing '#rev' file revision indicator
         """
         p4cmd = self._buildp4command(ud, d, 'files')
-        bb.fetch2.check_network_access(d, p4cmd)
+        bb.fetch2.check_network_access(d, p4cmd, ud.url)
         p4fileslist = runfetchcmd(p4cmd, d, True)
         p4fileslist = [f.rstrip() for f in p4fileslist.splitlines()]
 
@@ -171,7 +171,7 @@ class Perforce(FetchMethod):
 
         for afile in filelist:
             p4fetchcmd = self._buildp4command(ud, d, 'print', afile)
-            bb.fetch2.check_network_access(d, p4fetchcmd)
+            bb.fetch2.check_network_access(d, p4fetchcmd, ud.url)
             runfetchcmd(p4fetchcmd, d, workdir=ud.pkgdir)
 
         runfetchcmd('tar -czf %s p4' % (ud.localpath), d, cleanup=[ud.localpath], workdir=ud.pkgdir)
@@ -191,7 +191,7 @@ class Perforce(FetchMethod):
     def _latest_revision(self, ud, d, name):
         """ Return the latest upstream scm revision number """
         p4cmd = self._buildp4command(ud, d, "changes")
-        bb.fetch2.check_network_access(d, p4cmd)
+        bb.fetch2.check_network_access(d, p4cmd, ud.url)
         tip = runfetchcmd(p4cmd, d, True)
 
         if not tip:
lib/bb/fetch2/svn.py +1 -1
index 6ca79d3..71dee9f 100644
@@ -173,7 +173,7 @@ class Svn(FetchMethod):
         """
         Return the latest upstream revision number
         """
-        bb.fetch2.check_network_access(d, self._buildsvncommand(ud, d, "log1"))
+        bb.fetch2.check_network_access(d, self._buildsvncommand(ud, d, "log1"), ud.url)
 
         output = runfetchcmd("LANG=C LC_ALL=C " + self._buildsvncommand(ud, d, "log1"), d, True)
 
lib/bb/fetch2/wget.py +1 -1
index ecb946a..1d81c08 100644
@@ -95,7 +95,7 @@ class Wget(FetchMethod):
         progresshandler = WgetProgressHandler(d)
 
         logger.debug(2, "Fetching %s using command '%s'" % (ud.url, command))
-        bb.fetch2.check_network_access(d, command)
+        bb.fetch2.check_network_access(d, command, ud.url)
         runfetchcmd(command + ' --progress=dot -v', d, quiet, log=progresshandler)
 
     def download(self, ud, d):
Signature · 1 line
2.6.6
#1 lore raw
Quoted 1 line · Markus Lehtonen

[YOCTO #10508]

I take it this applies to 1.32 ( Morty) as well.

-armin

Quoted 148 lines
---
  lib/bb/fetch2/__init__.py | 7 +++++--
  lib/bb/fetch2/git.py      | 4 ++--
  lib/bb/fetch2/hg.py       | 2 +-
  lib/bb/fetch2/npm.py      | 2 +-
  lib/bb/fetch2/perforce.py | 8 ++++----
  lib/bb/fetch2/svn.py      | 2 +-
  lib/bb/fetch2/wget.py     | 2 +-
  7 files changed, 15 insertions(+), 12 deletions(-)
lib/bb/fetch2/__init__.py +5 -2
index cd7362c..4bb7526 100644
@@ -856,12 +856,15 @@ def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None, workdir=None):
 
      return output
 
-def check_network_access(d, info = "", url = None):
+def check_network_access(d, info, url):
      """
-    log remote network access, and error if BB_NO_NETWORK is set
+    log remote network access, and error if BB_NO_NETWORK is set or the given
+    URI is untrusted
      """
      if d.getVar("BB_NO_NETWORK", True) == "1":
          raise NetworkAccess(url, info)
+    elif not trusted_network(d, url):
+        raise UntrustedUrl(url, info)
      else:
          logger.debug(1, "Fetcher accessed the network with the command %s" % info)
 
lib/bb/fetch2/git.py +2 -2
index 1bec60a..11d0b9c 100644
@@ -252,7 +252,7 @@ class Git(FetchMethod):
                  repourl = repourl[7:]
              clone_cmd = "LANG=C %s clone --bare --mirror %s %s --progress" % (ud.basecmd, repourl, ud.clonedir)
              if ud.proto.lower() != 'file':
-                bb.fetch2.check_network_access(d, clone_cmd)
+                bb.fetch2.check_network_access(d, clone_cmd, ud.url)
              progresshandler = GitProgressHandler(d)
              runfetchcmd(clone_cmd, d, log=progresshandler)
 
@@ -384,7 +384,7 @@ class Git(FetchMethod):
          cmd = "%s ls-remote %s %s" % \
                (ud.basecmd, repourl, search)
          if ud.proto.lower() != 'file':
-            bb.fetch2.check_network_access(d, cmd)
+            bb.fetch2.check_network_access(d, cmd, repourl)
          output = runfetchcmd(cmd, d, True)
          if not output:
              raise bb.fetch2.FetchError("The command %s gave empty output unexpectedly" % cmd, ud.url)
lib/bb/fetch2/hg.py +1 -1
index 20df801..dc87998 100644
@@ -221,7 +221,7 @@ class Hg(FetchMethod):
          """
          Compute tip revision for the url
          """
-        bb.fetch2.check_network_access(d, self._buildhgcommand(ud, d, "info"))
+        bb.fetch2.check_network_access(d, self._buildhgcommand(ud, d, "info"), ud.url)
          output = runfetchcmd(self._buildhgcommand(ud, d, "info"), d)
          return output.strip()
 
lib/bb/fetch2/npm.py +1 -1
index 699ae72..29faea1 100644
@@ -101,7 +101,7 @@ class Npm(FetchMethod):
 
      def _runwget(self, ud, d, command, quiet):
          logger.debug(2, "Fetching %s using command '%s'" % (ud.url, command))
-        bb.fetch2.check_network_access(d, command)
+        bb.fetch2.check_network_access(d, command, ud.url)
          dldir = d.getVar("DL_DIR", True)
          runfetchcmd(command, d, quiet, workdir=dldir)
 
lib/bb/fetch2/perforce.py +4 -4
index 50cb479..e332e7c 100644
@@ -71,7 +71,7 @@ class Perforce(FetchMethod):
              logger.debug(1, 'Trying to use P4CONFIG to automatically set P4PORT...')
              ud.usingp4config = True
              p4cmd = '%s info | grep "Server address"' % ud.basecmd
-            bb.fetch2.check_network_access(d, p4cmd)
+            bb.fetch2.check_network_access(d, p4cmd, ud.url)
              ud.host = runfetchcmd(p4cmd, d, True)
              ud.host = ud.host.split(': ')[1].strip()
              logger.debug(1, 'Determined P4PORT to be: %s' % ud.host)
@@ -140,7 +140,7 @@ class Perforce(FetchMethod):
          'p4 files' command, including trailing '#rev' file revision indicator
          """
          p4cmd = self._buildp4command(ud, d, 'files')
-        bb.fetch2.check_network_access(d, p4cmd)
+        bb.fetch2.check_network_access(d, p4cmd, ud.url)
          p4fileslist = runfetchcmd(p4cmd, d, True)
          p4fileslist = [f.rstrip() for f in p4fileslist.splitlines()]
 
@@ -171,7 +171,7 @@ class Perforce(FetchMethod):
 
          for afile in filelist:
              p4fetchcmd = self._buildp4command(ud, d, 'print', afile)
-            bb.fetch2.check_network_access(d, p4fetchcmd)
+            bb.fetch2.check_network_access(d, p4fetchcmd, ud.url)
              runfetchcmd(p4fetchcmd, d, workdir=ud.pkgdir)
 
          runfetchcmd('tar -czf %s p4' % (ud.localpath), d, cleanup=[ud.localpath], workdir=ud.pkgdir)
@@ -191,7 +191,7 @@ class Perforce(FetchMethod):
      def _latest_revision(self, ud, d, name):
          """ Return the latest upstream scm revision number """
          p4cmd = self._buildp4command(ud, d, "changes")
-        bb.fetch2.check_network_access(d, p4cmd)
+        bb.fetch2.check_network_access(d, p4cmd, ud.url)
          tip = runfetchcmd(p4cmd, d, True)
 
          if not tip:
lib/bb/fetch2/svn.py +1 -1
index 6ca79d3..71dee9f 100644
@@ -173,7 +173,7 @@ class Svn(FetchMethod):
          """
          Return the latest upstream revision number
          """
-        bb.fetch2.check_network_access(d, self._buildsvncommand(ud, d, "log1"))
+        bb.fetch2.check_network_access(d, self._buildsvncommand(ud, d, "log1"), ud.url)
 
          output = runfetchcmd("LANG=C LC_ALL=C " + self._buildsvncommand(ud, d, "log1"), d, True)
 
lib/bb/fetch2/wget.py +1 -1
index ecb946a..1d81c08 100644
@@ -95,7 +95,7 @@ class Wget(FetchMethod):
          progresshandler = WgetProgressHandler(d)
 
          logger.debug(2, "Fetching %s using command '%s'" % (ud.url, command))
-        bb.fetch2.check_network_access(d, command)
+        bb.fetch2.check_network_access(d, command, ud.url)
          runfetchcmd(command + ' --progress=dot -v', d, quiet, log=progresshandler)
 
      def download(self, ud, d):
#2 lore raw
Quoted 5 lines · On Mon, 2016-11-21 at 07:47 -0800, akuster808 wrote:
Quoted 1 line · Markus Lehtonen

[YOCTO #10508]

I take it this applies to 1.32 ( Morty) as well.

Yes, I think so.

However, it may have some side effects for users of BB_ALLOWED_NETWORKS. Basically, after this patch git update (and mercurial and other VCSes, too) from upstream sources stops working unless the upstream repo is trusted by BB_ALLOWED_NETWORKS.

Thanks,
Markus