Professional Machine Learning Engineer free question 2 / 10 · Domain 2: Collaborating within and across teams to manage data and models
In a notebook you ran gcloud auth application-default login and created an ADC file from your own user credentials. You now also want to read Google Drive files with this ADC. Which statement matches the ADC page?
- The default scope is cloud-platform, and you add Drive by supplying a client ID and using --scopes
- The default scope is cloud-platform, and Drive can be read after your account is granted a Drive IAM role
- The default scope is cloud-platform, and Drive falls inside that scope, so it can be read as it is
- The default scopes already include Drive, so you can keep using the ADC file without recreating it
Show the answer and explanation
Answer: A
Why this is correct
The page says the access token generated from a local ADC file created with user credentials includes the cloud-wide scope https://www.googleapis.com/auth/cloud-platform by default. To add the scope of a service outside Google Cloud, such as Google Drive, you create an OAuth client ID, pass it with --client-id-file, specify the scopes with --scopes, and run gcloud auth application-default login again. Impersonating a service account is the other option.
Why the other options are wrong
"The default scope is cloud-platform, and Drive falls inside that scope, so it can be read as it is" … The page says that to add the scope of a service outside Google Cloud, such as Google Drive, you follow either the OAuth client ID procedure or the service account impersonation procedure. The cloud-platform scope alone does not cover Drive.
"The default scope is cloud-platform, and Drive can be read after your account is granted a Drive IAM role" … The cloud-platform default is right, but the page's way to add scopes of services outside Google Cloud is to pass an OAuth client ID with --client-id-file and specify the scopes with --scopes, or to impersonate a service account. Granting an IAM role is not part of it.
"The default scopes already include Drive, so you can keep using the ADC file without recreating it" … The default scope of a local ADC file created with user credentials is the cloud-wide cloud-platform scope. Drive is not in the default scopes, so it cannot be read without further steps.
Key point
When you use a service account, pass its email address with --impersonate-service-account and specify the scopes with --scopes. If you only need to name scopes explicitly, use --scopes. On Linux and macOS the ADC file is created at $HOME/.config/gcloud/application_default_credentials.json.