Prepare and test your skills

Prepare and test your skills

Free sample question with answers and detailed explanation below. The Professional Cloud Developer practice bank has an additional 608 practice questions.Try 10 free realistic questions: instant score, no credit card, and no account required.
You are building a Python service that uses a Cloud Client Library with Application Default Credentials (ADC) to access Cloud Storage without environment-specific code changes.
GOOGLE_APPLICATION_CREDENTIALS pointing to test-key.json and later ran gcloud auth application-default login --impersonate-service-account=dev-sa@my-project.iam.gserviceaccount.com.prod-sa@my-project.iam.gserviceaccount.com), with no GOOGLE_APPLICATION_CREDENTIALS variable or local ADC file present.How does ADC discover and select credentials in each environment?
gcloud auth application-default login and uses dev-sa; on Compute Engine, ADC queries the metadata server for prod-sa.Running gcloud auth application-default login—with or without --impersonate-service-account—writes a JSON credential configuration to a well-known user path ($HOME/.config/gcloud/application_default_credentials.json on Linux/macOS or %APPDATA%\gcloud\application_default_credentials.json on Windows). Python and several other Cloud Client Libraries natively support reading impersonated service account configurations from this file.
This option reverses the first two steps of the ADC search order. Running gcloud auth application-default login later in time does not unset or override an existing GOOGLE_APPLICATION_CREDENTIALS environment variable in your shell. Because ADC always evaluates GOOGLE_APPLICATION_CREDENTIALS before inspecting the well-known local file path, ADC continues to authenticate as test-key.json locally.
GOOGLE_APPLICATION_CREDENTIALS first, the local gcloud ADC file second, and the metadata server third.GOOGLE_APPLICATION_CREDENTIALS is specifically designed to take highest precedence so developers or external workloads can force a particular credential file without deleting local user ADC files.GOOGLE_APPLICATION_CREDENTIALS export in a shell startup script is a common cause of unexpected identity or permission errors during local testing.This behavior would occur only if you first unset GOOGLE_APPLICATION_CREDENTIALS (for example, unset GOOGLE_APPLICATION_CREDENTIALS in bash) on the local workstation so that ADC skips step 1 and proceeds to the impersonated local ADC file for dev-sa.
gcloud CLI configuration credentials before checking environment variables; on Compute Engine, ADC checks GOOGLE_APPLICATION_CREDENTIALS only if the metadata server fails to return prod-sa.The Google Cloud CLI (gcloud) maintains its own authentication state and named configurations (managed via gcloud auth login and gcloud config set) strictly for running gcloud commands. By contrast, Application Default Credentials (ADC) provides credentials exclusively to Cloud Client Libraries, Google API Client Libraries, and ADC-compatible tools.
This option contains two major misconceptions about how ADC works:
gcloud CLI configuration credentials; switching gcloud configurations or running gcloud auth login does not affect which identity an application uses through ADC.GOOGLE_APPLICATION_CREDENTIALS. The metadata server is always the third and final fallback in the ADC discovery sequence.gcloud CLI credentials separate from ADC prevents accidental privilege escalation or identity mismatches when running local applications.GOOGLE_APPLICATION_CREDENTIALS or a local ADC file is present inside the container or filesystem, ADC uses those first instead of the attached service account.Neither half reflects how ADC operates; gcloud CLI configurations govern gcloud commands (and REST tokens printed via gcloud auth print-access-token), whereas ADC always checks GOOGLE_APPLICATION_CREDENTIALS, then the local ADC file, and finally the metadata server.
test-key.json only after failing to reach a local metadata server; on Compute Engine, you must update the client library initialization to pass prod-sa explicitly instead of using ADC.The core purpose of Application Default Credentials (ADC) is environment portability: developers write client initialization code once (such as storage.Client() in Python) without hardcoding file paths, keys, or metadata calls. The authentication library inspects the runtime environment and supplies appropriate credentials automatically.
This option misunderstands both the order of discovery and the role of attached service accounts:
GOOGLE_APPLICATION_CREDENTIALS immediately and stops once it finds a valid credential file (test-key.json). It does not attempt to contact a metadata server before checking environment variables.prod-sa), ADC automatically queries the metadata server once the first two checks find nothing. Explicitly constructing credential objects in code is unnecessary.Credentials object directly to a client constructor is only needed for specialized scenarios, such as loading credentials dynamically from an in-memory secret vault rather than relying on ADC.Explicitly passing credentials to the client library would only be necessary if the application deliberately bypassed ADC to load service account credentials from a custom in-memory configuration stream or external secret manager.
GOOGLE_APPLICATION_CREDENTIALS first and uses test-key.json; on Compute Engine, after finding neither the environment variable nor a local ADC file, ADC retrieves prod-sa credentials from the metadata server.Application Default Credentials (ADC) is an authentication strategy used by Google Cloud authentication libraries to automatically locate credentials based on the runtime environment. By abstracting credential discovery away from application code, ADC allows Cloud Client Libraries and Google API Client Libraries to authenticate identically across local workstations and Google Cloud managed services.
ADC searches for credentials in a strict, fixed sequence regardless of the relative security merit of each method:
GOOGLE_APPLICATION_CREDENTIALS is set to a credential JSON file (such as a service account key or a Workload/Workforce Identity Federation configuration file).gcloud auth application-default login (stored at $HOME/.config/gcloud/application_default_credentials.json on Linux/macOS or %APPDATA%\gcloud\application_default_credentials.json on Windows).GOOGLE_APPLICATION_CREDENTIALS is evaluated first, exporting it overrides any subsequent gcloud auth application-default login command—even one using --impersonate-service-account.prod-sa) to a Google Cloud resource is the recommended production pattern because it avoids managing static service account keys.On the local workstation, GOOGLE_APPLICATION_CREDENTIALS takes precedence and resolves to test-key.json. On the Compute Engine VM, the first two locations are empty, so ADC falls through to the metadata server and seamlessly acquires credentials for prod-sa.
Answer them yourself and get your score the moment you finish. No account needed.
Full access includes
Keep the momentum going with these hand-picked practice scenarios
Last updated Validated