Enhancing Skills

How to Download credentials.json from Google Cloud

Before setting up your Docker container or Google Cloud DNS, you need to download the credentials.json file. This file allows you to authenticate your service account and access Google Cloud APIs. Here’s how to get it:


Step 1: Access Google Cloud Console

  1. Open the Google Cloud Console.
  2. Log in with your Google account.

Step 2: Select Your Project

  1. At the top of the page, click the project dropdown menu.
  2. Choose the project you want to use or create a new one.

Step 3: Navigate to the Service Accounts Page

  1. In the left-hand menu, go to IAM & Admin > Service Accounts.
    Alternatively, visit the Service Accounts page.

Step 4: Create a New Service Account

  1. Click Create Service Account.
  2. Fill in the required fields:
    • Name: A descriptive name for the service account (e.g., gcloud-dns-admin).
    • Description: Optionally, add details about the service account’s purpose.
  3. Click Create and Continue.

Step 5: Assign Roles to the Service Account

  1. Assign the appropriate roles for your use case, such as:
    • Editor: Grants full project-level access.
    • DNS Administrator: Grants permissions to manage Cloud DNS.
  2. Click Continue.

Step 6: (Optional) Grant User Access

  1. You can skip this step unless you want others to manage the service account.
  2. Click Done to finalize the service account creation.

Step 7: Generate and Download the credentials.json File

  1. In the list of service accounts, find your new account.
  2. Click the three-dot menu () on the right and select Manage Keys.
  3. Click Add Key > Create New Key.
  4. Choose JSON as the key type and click Create.

The credentials.json file will be downloaded automatically to your computer.


Step 8: Secure the credentials.json File

  • Store it securely: Avoid placing it in publicly accessible locations or version control systems.
  • Set permissions: Restrict access to the file: chmod 400 credentials.json chown [USER]:[GROUP] credentials.json

Step 9: Transfer the File to Your Server or Docker Host

  1. Use a file transfer tool like scp to move the file to your server: scp credentials.json user@your-server:/path/to/destination
  2. Mount the file in your Docker container using a volume: volumes: - ./credentials.json:/gcloud-data/credentials.json

Testing Your Credentials

After setting up, verify your credentials using the following commands inside your container or server:

export GOOGLE_APPLICATION_CREDENTIALS="/gcloud-data/credentials.json"
gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}
gcloud projects list

Summary

Downloading the credentials.json file is a critical step in enabling your GCloud SDK setup. Follow these steps carefully to ensure smooth authentication and access to Google Cloud services.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.