Soru

Zorluk: KolayProgrammatic GCP Interaction via SDK, CLI, and APIs

An application deployed on a Compute Engine virtual machine (VM) needs to read objects from a Cloud Storage bucket programmatically using the Google Cloud SDK. Which approach is the most secure and recommended method to handle authentication for this application?

  1. Attach a custom service account with specific Cloud Storage roles to the VM and authenticate using Application Default Credentials (ADC).Cevap
  2. B
    Create a service account JSON key file and hardcode the credentials directly into the application source code repository.
  3. C
    Assign the Owner primitive IAM role to the default Compute Engine service account to ensure the application has all necessary permissions.
  4. D
    Download a service account key file to unversioned local disk storage on the VM and read the file path during application initialization.

Cevap

Attach a custom service account with specific Cloud Storage roles to the VM and authenticate using Application Default Credentials (ADC).
Attaching a custom service account to a Compute Engine VM enables the Google Cloud SDK and client libraries to automatically retrieve short-lived OAuth 2.0 access tokens from the instance metadata server via Application Default Credentials (ADC). This eliminates the management and security risks associated with storing or rotating long-lived service account key files.

Adım Adım Çözüm

1
Determine the optimal identity mechanism for workloads running on Google Cloud.
Identify that Compute Engine instances can inherit identity from attached service accounts.
This allows applications to use Application Default Credentials (ADC) seamlessly.
2
Apply Google Cloud security best practices.
Grant only the fine-grained IAM roles needed for Cloud Storage object access to the service account.
Enforces the principle of least privilege and avoids managing static JSON key files.

Anahtar Kavram

Application Default Credentials (ADC) and Service Account Attachments
Bu soruyu puanla