title: How to access to a Google Cloud Storage bucket from a Cloud Run service without using a local Service Account key file?
body: <p>I just deployed a Cloud Run REST API application, which uses the Google Cloud Storage API to get the last file from a bucket and a folder inside that bucket. This is the code I'm using:</p>
  <pre><code>import os
  import logging
  from flask import Flask
  from flask import request, jsonify, render_template
  from google.oauth2 import service_account
  from google.cloud import storage
  from bson.json_util import dumps
  
  
  app = Flask(__name__)
  
  storage_client = storage.Client.from_service_account_json('sa.json')
  
  @app.route('/')
  # API Version 1.0
  def index():
      &quot;&quot;&quot;Welcome to Last File API Version 1.0.&quot;&quot;&quot;
      button_text = &quot;Add File&quot;
      return render_template('main.html', button_text=button_text)
  
  @app.route(&quot;/last_file_m_individual/&quot;, methods=[&quot;GET&quot;])
  def list_m_individual_files():
      &quot;&quot;&quot;List all files in GCP bucket.&quot;&quot;&quot;
      bucketName = request.args.get('bucketname')
      bucketFolder = request.args.get('bucketfolder')
      bucket = storage_client.get_bucket(bucketName)
      files = bucket.list_blobs(prefix=bucketFolder)
      fileList = [file.name for file in files if '.' in file.name]
      last_file_pep = fileList[-1]
      last_file_p = last_file_pep.split(&quot;/&quot;)
      last_file = last_file_p[-1]
      return last_file
  
  @app.errorhandler(500)
  def server_error(e):
      # Log the error and stacktrace.
      logging.exception('An error occurred during a request.')
      return 'An internal error occurred.', 500
  
  if __name__ == &quot;__main__&quot;:
      app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080)))
  </code></pre>
  <p>How can I have a <strong>service-to-service authentication between Google Cloud Storage and Cloud Run without having locally the Service Account key file for it</strong>?</p>
  <p>Thanks in advance.</p>