Google Professional Cloud Developer Question 421
Single answerGoogle Cloud PlatformYou are developing a serverless application on Google Cloud that needs to access the Google Cloud Translation API to translate user-provided text. The application is deployed on Cloud Run. What is the recommended way to authenticate your application for accessing the Translation API?
- A
Use an API key generated in the Google Cloud Console and include it in your requests.
- B
Deploy the application with a service account that has the required permissions and use Application Default Credentials (ADC).
- C
Manually retrieve an OAuth 2.0 token using client credentials and include it in the Authorization header.
- D
Use a signed JSON Web Token (JWT) and include it in the request header.
Show answer and explanation
Correct answer: B
Explanation
The best practice for authenticating Google Cloud applications running on services like Cloud Run is to use a service account with the necessary IAM permissions and Application Default Credentials (ADC). ADC simplifies authentication by automatically retrieving and rotating credentials securely. This approach is both secure and easy to implement.
- A. Incorrect.
API keys are generally not recommended for server-to-server authentication because they do not support granular permissions and can be less secure compared to service accounts.
- B. Correct.
Using a service account with Application Default Credentials (ADC) is the recommended approach for authenticating applications running on Google Cloud services like Cloud Run. ADC automatically handles authentication securely and ensures the correct permissions are applied.
- C. Incorrect.
Manually retrieving an OAuth 2.0 token is prone to errors, requires additional implementation effort, and is unnecessary when using Google Cloud's built-in authentication mechanisms.
- D. Incorrect.
While JWTs can be used for authentication, this is not the standard method for authenticating applications with Google Cloud APIs when a service account and ADC are available.