<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>10508</bug_id>
          
          <creation_ts>2016-10-27 16:04:38 +0000</creation_ts>
          <short_desc>bitbake fetcher does not always check for trusted_network</short_desc>
          <delta_ts>2016-12-06 17:26:58 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>1.4.5</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>2.3 M1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="JoergS">guru</reporter>
          <assigned_to name="Markus Lehtonen">markus.lehtonen</assigned_to>
          <cc>jose.perez.carranza</cc>
    
    <cc>markus.lehtonen</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>richard.purdie</cc>
          
          <qa_contact name="David Lopez Barriba">davidx.lopez.barriba</qa_contact>
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>67648</commentid>
    <comment_count>0</comment_count>
    <who name="JoergS">guru</who>
    <bug_when>2016-10-27 16:04:38 +0000</bug_when>
    <thetext>We are using local mirrors on our local network, therefor not disabling global network access via BB_NO_NETWORK, but limiting the network access to our own servers only via BB_ALLOWED_NETWORKS.
this does not work in case there is already an extracted git-tarball in the download directory but its content is outdated (e.g. the according tarball on the local mirror was updated).

the (in this case git-)fetcher calls &quot;bb.fetch2.check_network_access()&quot; to verify that it is allowed to update the git repo from origin, but the implementation of check_network_access() only checks if BB_NO_NETWORK is not &quot;1&quot;, it does not validate the given network address vs. any servers listed in BB_ALLOWED_NETWORKS in case BB_NO_NETWORK is &quot;0&quot;!

in my opinion, check_network_access() should be enhanced like this:
def check_network_access(d, info = &quot;&quot;, url = None):
    &quot;&quot;&quot;
    log remote network access, and error if BB_NO_NETWORK is set
    or url is untrusted
    &quot;&quot;&quot;
    if d.getVar(&quot;BB_NO_NETWORK&quot;, True) == &quot;1&quot;:
        raise NetworkAccess(url, info)
    elif not trusted_network(d, url):
        raise UntrustedUrl(url, info)
    else:
        logger.debug(1, &quot;Fetcher accessed the network with the command %s&quot; % info)

p.s.
this still does not solve the described bug, for this the local git-repo/-tarball should simply be deleted and re-downloaded/-extracted from the local mirror, but at least the build breaks with an &quot;untrusted network&quot; exception and no fetch from an untrusted source is happening!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68025</commentid>
    <comment_count>1</comment_count>
    <who name="JoergS">guru</who>
    <bug_when>2016-11-07 16:52:05 +0000</bug_when>
    <thetext>I noticed the optional &apos;url&apos;-parameter in &quot;check_network_access()&quot; too late,
but a valid &apos;url&apos; is needed for &apos;trusted_network()&apos; to work properly
- otherwise a misleading &quot;MalformedURL&quot; exception may be raised!

so, here is a slightly improved check_network_access():

 def check_network_access(d, info = &quot;&quot;, url = None):
     &quot;&quot;&quot;
     log remote network access, and error if BB_NO_NETWORK is set
+    or url is untrusted
     &quot;&quot;&quot;
     if d.getVar(&quot;BB_NO_NETWORK&quot;, True) == &quot;1&quot;:
         raise NetworkAccess(url, info)
+    elif url is None and \
+         (d.getVarFlag(&apos;BB_ALLOWED_NETWORKS&apos;, d.expand(d.getVar(&apos;PN&apos;, False))) or \
+          d.getVar(&apos;BB_ALLOWED_NETWORKS&apos;, True)):
+        raise FetchError(&quot;cannot verify allowed hosts without URL&quot;)
+    elif not trusted_network(d, url):
+        raise UntrustedUrl(url, info)
+    elif info:
+        logger.debug(1, &quot;Fetcher accessed the network with the command &apos;%s&apos;&quot; % info)
     else:
-        logger.debug(1, &quot;Fetcher accessed the network with the command %s&quot; % info)
+        logger.debug(1, &quot;Fetcher accessed the network&quot;)


p.s.
the logger texts (w/ or w/o &apos;info&apos;) in case of a successful check can most probably
written shorter with some fancy python oneliner-magic, but I am not such pro yet...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68419</commentid>
    <comment_count>2</comment_count>
    <who name="Markus Lehtonen">markus.lehtonen</who>
    <bug_when>2016-11-17 18:05:41 +0000</bug_when>
    <thetext>I wrote a simple patch that is available here:
http://git.openembedded.org/openembedded-core-contrib/log/?h=marquiz/bitbake/fixes-10508

The forces all calls of check_network_access() to check that the URI is trusted (i.e. that it is not banned by BB_ALLOWED_NETWORKS). Basically, I think this would be the right thing to do. However, it causes multiple complications, e.g. git ls-remote may stop to work which badly breaks and &quot;AUTOREV&quot; packages. Similar breakages happens for &quot;ls-remote&quot; of other VCSes, too.

Regarding Git update in the case that BB_ALLOWED_NETWORKS bans upstream source, I don&apos;t know what would be the right thing to do. The problem is that (AFAIU) bitbake only supports git mirrors through mirror tarballs and is not able to handle real git:// mirrors. Thinking to myself: I think the only thing we could reasonably do is delete/re-download/extract as you suggested.

I don&apos;t know if Richard has any comments/ideas?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68453</commentid>
    <comment_count>3</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2016-11-21 12:09:47 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; I don&apos;t know if Richard has any comments/ideas?

FWIW I think the patch is the right thing to do...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68455</commentid>
    <comment_count>4</comment_count>
    <who name="Markus Lehtonen">markus.lehtonen</who>
    <bug_when>2016-11-21 12:52:53 +0000</bug_when>
    <thetext>Patch sent for review:
https://patchwork.openembedded.org/patch/134042/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68830</commentid>
    <comment_count>5</comment_count>
    <who name="Markus Lehtonen">markus.lehtonen</who>
    <bug_when>2016-12-05 09:07:44 +0000</bug_when>
    <thetext>Fix merged in:
http://git.openembedded.org/bitbake/commit/?id=ddd3bc2d64d7240ecb6b6e4a1ae29b1faef6cc22</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>