<p>What is the best way to deploy Google service account credentials inside a custom built CentOS Docker container for running either on Google's Container Engine or their 'container-vm'?  This behavior happens automatically on the <a href="https://registry.hub.docker.com/u/google/cloud-sdk/">google/cloud-sdk</a> container, which runs debian and includes things I'm not using such as app-eng/java/php.  Ideally I am trying to access non-public resources inside my project, e.g., Google Cloud Storage bucket objects, without loging in and authorizing every single time a large number of these containers are launched.  </p>

<p>For example, on a base Centos container running on GCE with custom code and gcloud/gsutil installed, when you run:</p>

<pre><code>docker run --rm -ti custom-container gsutil ls
</code></pre>

<p>You are prompted to run "gsutil config" to gain authorization, which I expect.  </p>

<p>However, pulling down the google/cloud-sdk container onto the same GCE and executing the same command, it seems to have cleverly configured inheritance of credentials (perhaps from the host container-vm's credentials?).  This seems to bypass running "gsutil config" when running the container on GCE to access private resources.  </p>

<p>I am looking to replicate that behavior in a minimal build Centos container for mass deployment.  </p>

<p><strong>Update:</strong> as of 15 Dec 2016, the ability to update the scopes of an existing VM is now in beta; see <a href="https://stackoverflow.com/a/31868837/3618671">this SO answer</a> for more details.</p>

<hr>

<p><strong>Old answer:</strong> One approach is to create the VM with <a href="https://cloud.google.com/compute/docs/api/how-tos/authorization" rel="nofollow noreferrer">appropriate scopes</a> (e.g., Google Cloud Storage read-only or read-write) and then all processes on the VM, including containers, will have access to credentials that they can use via OAuth 2.0; see docs for <a href="https://cloud.google.com/storage/docs/authentication" rel="nofollow noreferrer">Google Cloud Storage</a> and <a href="https://cloud.google.com/compute/docs/authentication" rel="nofollow noreferrer">Google Compute Engine</a>.</p>

<p>Note that once a VM is created with some set of scopes, they cannot be changed later (neither added nor removed), so you have to be sure to set the right set of scopes at the time of VM instance creation.</p>
