Question

Difficulty: MediumProgrammatic GCP Interaction via SDK, CLI, and APIs

A security team is reviewing a Python administrative automation service running on a Compute Engine instance. The service programmatically manages Cloud Storage resources across multiple production Google Cloud projects. Currently, the service authenticates using static JSON service account keys stored on the local instance disk, violating enterprise compliance policies. The architecture team needs a solution that eliminates long-lived credentials while enabling secure programmatic interaction across project boundaries. Which approach should be implemented to meet these requirements?

  1. Authenticate using Application Default Credentials (ADC) associated with the VM's attached service account, and use short-lived service account impersonation to interact with target projects.Answer
  2. B
    Embed the service account JSON keys directly into environment variables within the application source code repository.
  3. C
    Assign the primitive Owner IAM role to the VM instance service account at the Google Cloud organization level.
  4. D
    Store the JSON service account key files on an unversioned local disk partition attached to the instance.

Answer

The application should authenticate using Application Default Credentials (ADC) provided by the compute platform's metadata server and utilize service account impersonation with short-lived tokens for cross-project access.
Utilizing Application Default Credentials (ADC) allows Google Cloud SDKs to dynamically retrieve short-lived OAuth 2.0 access tokens from the Compute Engine metadata server. When combined with service account impersonation (`roles/iam.serviceAccountTokenCreator`), the application can securely generate short-lived tokens to access resources across project boundaries without creating or storing long-lived service account JSON key files.

Step-by-Step Solution

1
Identify the credential security requirement
Recognize that downloading and storing long-lived service account JSON key files on disk must be eliminated.
Static keys pose significant exfiltration and governance risks.
2
Select native authentication mechanisms for GCP compute resources
Attach a custom service account to the Compute Engine instance and leverage Application Default Credentials (ADC).
ADC fetches short-lived identity tokens directly from the internal compute metadata server.
3
Enable cross-project authorization
Grant the attached service account the ability to impersonate target service accounts in destination projects.
Impersonation yields short-lived OAuth 2.0 access tokens on demand without needing key files.

Key Concept

Programmatic Authentication via Application Default Credentials (ADC) and Service Account Impersonation
Rate this question