ASSOCIATE-CLOUD-ENGINEER practice question 24 of 35

You received a JSON file that contained a private key of a Service Account in order to get access to several resources in a Google Cloud project. You downloaded and installed the Cloud SDK and want to use this private key for authentication and authorization when performing gcloud commands. What should you do?

Full set: 332 questions
Answer options
A: Use the command gcloud auth login and point it to the private key
B: Use the command gcloud auth activate-service-account and point it to the private key Correct answer
C: Place the private key file in the installation directory of the Cloud SDK and rename it to "credentials ison"
D: Place the private key file in your home directory and rename it to ‘’GOOGLE_APPUCATION_CREDENTiALS".
Correct Answer:
B. Use the command gcloud auth activate-service-account and point it to the private key
Explanation

The gcloud auth activate-service-account command is the designated method within the Cloud SDK to authenticate using a service account's private key file. This command takes the path to the JSON key file and sets the active account for all subsequent gcloud commands to be that service account. This directly addresses the user's need to use the provided private key for authentication and authorization when performing gcloud commands.

Why Incorrect

A. gcloud auth login is used to authorize a human user account via a web-based OAuth 2.0 flow, not to activate a service account using a key file.
C. Placing a key file in the Cloud SDK installation directory with a specific name is not a recognized or documented procedure for authenticating the gcloud tool.
D. Setting the GOOGLEAPPLICATIONCREDENTIALS environment variable is primarily for Application Default Credentials (ADC) used by client libraries, not for configuring the active account for the gcloud CLI tool itself.

References

1. Google Cloud Documentation

gcloud auth activate-service-account: "Authorizes access to Google Cloud with a service account. This command is an alternative to gcloud auth login when you want to authenticate as a service account instead of a user account." (Reference: gcloud auth activate-service-account command reference page).

2. Google Cloud Documentation

Authorizing the Cloud SDK: "To authorize with a service account

use the gcloud auth activate-service-account command... This is useful for running gcloud CLI in a virtual machine." (Reference: "Authorizing the Cloud SDK" documentation

section "Authorizing with a service account").

3. Google Cloud Documentation

gcloud auth login: "Authorizes user accounts to access Google Cloud. The gcloud auth login command is used to obtain and place access credentials for a user account on the local system." (Reference: gcloud auth login command reference page).

4. Google Cloud Documentation

Authenticating as a service account: "To provide credentials to a client library or a tool like Terraform

you set the GOOGLEAPPLICATIONCREDENTIALS environment variable... The gcloud CLI does not use this environment variable to find your credentials." (Reference: "Authentication at Google" documentation

section "Authenticating as a service account").

Scroll to Top