<p>I'm launching container images on Google Cloud AI Training (Cloud ML Engine)</p>

<p>Inside those containers I need to use gsutil.
Some containers have gsutil. In that case I can use it right away without any authentication steps.</p>

<p>Some containers do not have gsutil, so I have to install it.
The problem is that the installed gsutil does not work.</p>

<p>When I'm using the official <code>cloud-sdk</code> image, <code>gsutil</code> works without any auth steps.</p>

<p>When I use the <code>python:3.7</code> image and install <code>gsutil</code> from PyPI it does not work:</p>

<pre><code>python -m pip install gsutil --quiet
gsutil cp a gs://b/c
</code></pre>

<blockquote>
  <p>ServiceException: 401 Anonymous caller does not have storage.objects.get access to ...</p>
</blockquote>

<p>How can I make it so that the standalone gsutil obtains the needed credentials?</p>

<p>Most guides focus on manually calling <code>gcloud auth</code>, copying URL and copying back the token. This is not the solution that I seek (which should be automated). I know that the automated solution is possible since in some images <code>gsutil</code> works out of the box.</p>

<p>This is because that pip install gsutil alone does not configure the credentials, which is why it's anonymous user as the error says.  You'll want to configure credentials to access protected data.</p>

<p>Put following line in your docker file and it should work:</p>

<p>RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg</p>

<p>It's to configure gsutil to use the default service account.</p>
