Course outline

Google Cloud / Basic: Resource and Access Boundaries / Lesson 7

Trace Application Default Credentials

Compare Google Cloud application credential sources and verify the effective identity and project.

About 19 min read20 worked examples20 practice exercisesContent reviewed
On this page

Lesson goals

  • Explain the ADC credential search strategy.
  • Distinguish local ADC from gcloud CLI credentials.
  • Review identity and target project separately.
  • Trace the selected ADC source and actual principal in each environment.
  • Separate credential discovery from target authorization and token audience.

Understand credential discovery

Application Default Credentials, or ADC, is a strategy used by supported authentication libraries to locate credentials for application code. It is not itself an IAM role or a guarantee of access. The documented search checks an environment-specified credential file, local ADC credentials and then an attached service account through metadata when applicable. The records below are synthetic; no credential is read or service contacted.

Review local context

The first record describes an expected local development identity and project. Local ADC credentials are distinct from the credentials used by the gcloud CLI, even when the same person configured both. A successful CLI command therefore does not prove that application code uses the same principal. Record the expected identity and project without copying credential files, tokens or private keys.

yaml Synthetic local expectation
environment: synthetic-workstation
expected_identity: lab-developer
expected_project: training-project
credential_source: local-adc

This is an expectation checklist, not a credential file or command.

Review an attached identity

The second record describes a service expected to use its attached service account. An earlier ADC source can affect which credentials the library discovers, so inspect the actual runtime context under approved procedures. A credential file can represent different credential types; do not assume every file is a service account key. Avoid distributing long-lived service account keys when a safer supported identity mechanism fits the workload.

yaml Synthetic service expectation
environment: synthetic-service
expected_identity: attached-service-account
credential_source: metadata-server
verification: required

This record names an expected source and leaves actual identity verification open.

Separate identity and authorization

Compare the actual principal, target project, resource and operation. Authentication does not establish IAM permission, and access in one project does not imply access in another. Investigate the exact denial with the owner instead of widening a role based on a local test.

Verify with bounded evidence

In an authorized lab, compare expected and actual identity, then test a read-only operation on a synthetic resource and an approved denial. Preserve sanitized context. Local success does not prove the deployed service uses the same ADC source.

Trace discovery before changing roles

Application Default Credentials is a discovery strategy used by supported Google authentication libraries, not a single fixed identity. The library searches documented sources in order: an environment-specified credential configuration, a well-known local ADC file, and an attached service account through the metadata server in supported environments. Identify the actual environment and selected source before interpreting a permission failure. A source can describe different credential types; the mere presence of a path does not identify the principal without authorized inspection. These fictional records do not load credentials, request tokens or call Google Cloud.

Compare CLI and application contexts

The gcloud CLI’s own authentication configuration and application ADC are distinct contexts. A successful CLI command under one identity does not establish that an application uses the same identity or target project. Record the observed principal, credential source, project, resource and operation for each request. A command can succeed against a development target while an application fails against production, or the two can use different identities against the same resource. Compare those facts before proposing IAM changes. Never print access tokens, private keys or credential file contents into diagnostic logs.

For example, a developer may run a CLI command against a test project while the application points to a production object. Even if both requests appear to read data, the principal, resource path and operation must be compared before their outcomes are meaningful. Keep the evidence for each request in separate rows and label missing values unknown. This prevents a successful command from becoming a shortcut for granting broad permissions to an application whose actual identity has not yet been established.

Inspect the deployed runtime chain

For a deployed workload, distinguish the deployer, configured attached service account, credential source selected by the application and principal observed at the target. A higher-priority environment configuration or local ADC source can take precedence over an attached identity in the documented discovery order. If the observed principal differs from the expected account, determine which source is selected and why it exists. Correct an unintended configuration through the approved change process, then repeat a bounded test. A local developer’s credential state does not prove what a separate deployment uses.

Separate identity from permission

Once the actual principal is known, evaluate the requested operation and exact target using applicable IAM bindings, inherited policies, conditions and service controls. Authentication success or a valid token does not itself grant a bucket read. Conversely, a grant to the expected account does not help a request made as a different principal. A mismatch in token audience or target API may also require investigating the credential request rather than broadening roles. Treat each as a hypothesis until observed evidence identifies the failing boundary; use the least privilege appropriate to an authorized correction.

Capture bounded, sanitized evidence

For each test record its environment, selected source category, principal identifier, project, resource, operation, time and sanitized outcome. Separate configured, observed and proposed values; an unrun or blocked test has no observed principal or authorization result. In an approved isolated environment compare an intended permitted request with a neighboring denied case and document the configuration tested. After a change, repeat the same scoped request and record any remaining uncertainty. A successful result is evidence for that request at that time, not every client, target or later credential configuration.

Name an owner for each unresolved source or policy question and preserve the original observation before changing configuration. If the source changes after an approved correction, verify the actual runtime principal and repeat the same target operation, including a suitable negative case where authorized. A local success, a past test or a planned configuration is not a current deployed observation. These steps make the result reviewable while avoiding credential disclosure and unsupported claims about access.

20 worked examples

1. CLI versus ADC

Problem: Does a successful CLI command establish the application identity?

  1. The CLI and application use different recorded principals.
  2. Investigate B’s credential source and target authorization; the CLI success concerns A.
text Synthetic credential trace
gcloud principal=user:A
application ADC principal=user:B
CLI read=success
application read=denied

This fixture loads no credentials and makes no cloud request.

Expected result: Investigate B’s credential source and target authorization; the CLI success concerns A.

Why this result follows: A result under A does not establish B’s permissions.

2. Environment precedence

Problem: Which source should be investigated when the observed identity is B?

  1. The environment configuration is a higher-priority ADC source than the attached account.
  2. Review why B’s environment source is present before changing A’s role.
text Synthetic credential trace
environment credential configuration=account-B
attached account=account-A
observed principal=account-B

This fixture loads no credentials and makes no cloud request.

Expected result: Review why B’s environment source is present before changing A’s role.

Why this result follows: A grant to A does not change a request actually using B.

3. Local ADC

Problem: Does a local application success prove the deployed workload succeeds?

  1. The local and deployed environments have different recorded identity contexts.
  2. Keep deployed access unverified and inspect its selected source and permission.
text Synthetic credential trace
local ADC=user:developer
local read=success
deployed attached account=account-A
deployed test=not run

This fixture loads no credentials and makes no cloud request.

Expected result: Keep deployed access unverified and inspect its selected source and permission.

Why this result follows: A local result does not establish a remote runtime result.

4. Different project

Problem: Can the two results be compared as the same target?

  1. The requests use different project targets despite sharing an operation label.
  2. Confirm the exact resources and identities before attributing the difference to IAM.
text Synthetic credential trace
CLI project=dev
application project=prod
operation=read object

This fixture loads no credentials and makes no cloud request.

Expected result: Confirm the exact resources and identities before attributing the difference to IAM.

Why this result follows: Different targets can have different policies and data.

5. Uninspected path

Problem: Does a configured credential path reveal its principal?

  1. The record identifies a path but does not identify the credential or observed principal.
  2. Inspect the selected source through authorized means without copying or printing it.
text Synthetic credential trace
credential path=configured
credential contents=not inspected
observed principal=unknown

This fixture loads no credentials and makes no cloud request.

Expected result: Inspect the selected source through authorized means without copying or printing it.

Why this result follows: A path string alone is not proof of the identity used.

6. Attached account

Problem: Does a configured attached account prove ADC selected it?

  1. A higher-priority source may exist, and the actual selection is not observed.
  2. Review source selection and the runtime principal before claiming A is used.
text Synthetic credential trace
attached account=account-A
environment source=unknown
observed principal=unknown

This fixture loads no credentials and makes no cloud request.

Expected result: Review source selection and the runtime principal before claiming A is used.

Why this result follows: Configuration of an attached account is distinct from observed credential discovery.

7. Authentication versus access

Problem: Does obtaining a token prove permission to read the object?

  1. The credential path succeeded but the requested resource operation was denied.
  2. Inspect A’s applicable permission, conditions and target context.
text Synthetic credential trace
token acquisition=success
principal=account-A
object read=denied

This fixture loads no credentials and makes no cloud request.

Expected result: Inspect A’s applicable permission, conditions and target context.

Why this result follows: Authentication and resource authorization are separate boundaries.

8. Grant to wrong account

Problem: Does a grant to account A fix a request made as B?

  1. The recorded binding and observed principal name different accounts.
  2. Trace B’s selection and applicable policy before proposing a narrow correction.
text Synthetic credential trace
bucket reader grant=account-A
application principal=account-B
object read=denied

This fixture loads no credentials and makes no cloud request.

Expected result: Trace B’s selection and applicable policy before proposing a narrow correction.

Why this result follows: A permission granted to A does not automatically apply to B.

9. Audience mismatch

Problem: What should be reviewed when token audience and target differ?

  1. The token is described as intended for a different API from the target.
  2. Review the supported token flow and the target’s audience requirements.
text Synthetic credential trace
token audience=API-A
requested target=API-B
request result=denied

This fixture loads no credentials and makes no cloud request.

Expected result: Review the supported token flow and the target’s audience requirements.

Why this result follows: An identity alone does not establish that a token is intended for every API.

10. Blocked observation

Problem: What does an unavailable test endpoint establish about ADC selection?

  1. No request ran and the selected principal was not observed.
  2. Record the test as blocked and keep identity and access unverified.
text Synthetic credential trace
test endpoint=unavailable
request sent=no
selected principal=not observed

This fixture loads no credentials and makes no cloud request.

Expected result: Record the test as blocked and keep identity and access unverified.

Why this result follows: An unrun request cannot demonstrate credential selection or authorization.

11. Local file precedence

Problem: What source should be reviewed before assuming the attached account was selected?

  1. A local ADC file is listed before an attached service account in the documented search order.
  2. Inspect the runtime environment and selected source without exposing the file contents.
text Synthetic credential trace
environment source=unset
local ADC file=present
attached account=account-A
selected source=not observed

This fixture loads no credentials and makes no cloud request.

Expected result: Inspect the runtime environment and selected source without exposing the file contents.

Why this result follows: The attached account is a later discovery source when an earlier source is available.

12. Different operation

Problem: Does CLI metadata success prove the application can read an object?

  1. The operations differ and the principal comparison is missing.
  2. Compare actual principals and required permissions for each operation.
text Synthetic credential trace
CLI operation=bucket metadata read success
application operation=object read denied
principal comparison=unknown

This fixture loads no credentials and makes no cloud request.

Expected result: Compare actual principals and required permissions for each operation.

Why this result follows: Different operations can require different permissions, even on related resources.

13. Proposed source change

Problem: Does a proposed removal prove the environment variable is absent?

  1. The record is a proposal awaiting approval rather than an observed environment.
  2. Keep the selected source unverified until authorized current evidence is available.
text Synthetic credential trace
proposal=remove credential path
approval=pending
current environment=not observed

This fixture loads no credentials and makes no cloud request.

Expected result: Keep the selected source unverified until authorized current evidence is available.

Why this result follows: A proposed change is not proof of applied runtime state.

14. Wrong resource grant

Problem: Does a reader grant on bucket A establish access to bucket B?

  1. The recorded resource grant and requested bucket are different.
  2. Inspect B’s applicable policies and the exact requested operation.
text Synthetic credential trace
principal=account-A
reader grant=bucket-A
request target=bucket-B

This fixture loads no credentials and makes no cloud request.

Expected result: Inspect B’s applicable policies and the exact requested operation.

Why this result follows: A grant on one resource does not automatically establish access to a sibling.

15. Credential exposure

Problem: What should be retained when a credential file was pasted into a ticket?

  1. The ticket contains sensitive material while the diagnostic need is for sanitized identity context.
  2. Follow the organization’s exposure process and retain identifiers and timing without the credential contents.
text Synthetic credential trace
ticket=credential file contents
incident status=under review
needed evidence=source category and principal

This fixture loads no credentials and makes no cloud request.

Expected result: Follow the organization’s exposure process and retain identifiers and timing without the credential contents.

Why this result follows: Credential material is not required in ordinary trace evidence.

16. Stale observation

Problem: Does a test from last week prove the current ADC source?

  1. The environment changed after the recorded observation.
  2. Review the current source and run an authorized bounded test if needed.
text Synthetic credential trace
last test principal=account-A
environment configuration changed=today
current test=not run

This fixture loads no credentials and makes no cloud request.

Expected result: Review the current source and run an authorized bounded test if needed.

Why this result follows: Earlier evidence describes the previous configuration and time.

17. Nested execution

Problem: Can the host’s ADC result be assumed for a container?

  1. The container may have a different filesystem or environment, neither of which is recorded.
  2. Inspect credential discovery inside the actual container context.
text Synthetic credential trace
host local ADC=user:A
container environment=not inspected
container request=denied

This fixture loads no credentials and makes no cloud request.

Expected result: Inspect credential discovery inside the actual container context.

Why this result follows: A host observation does not establish the container’s selected source.

18. Deployer identity

Problem: Does the deployment principal establish the application’s runtime principal?

  1. The deployer and configured runtime identity differ, and selection is unobserved.
  2. Inspect the deployed application’s selected source and observed principal.
text Synthetic credential trace
deployer=user:A
attached runtime account=account-B
application source=unknown

This fixture loads no credentials and makes no cloud request.

Expected result: Inspect the deployed application’s selected source and observed principal.

Why this result follows: Deployment authorization and runtime credential discovery are different stages.

19. Conditional permission

Problem: Can the reviewer decide access without the condition context?

  1. The binding depends on a request time not provided in the record.
  2. Keep the authorization decision unresolved until the condition and context are evaluated.
text Synthetic credential trace
principal=account-A
reader binding condition=request before cutoff
request time=unknown

This fixture loads no credentials and makes no cloud request.

Expected result: Keep the authorization decision unresolved until the condition and context are evaluated.

Why this result follows: A matching principal and role do not resolve an unevaluated condition.

20. Unexpected success

Problem: Does a successful application request prove it used the intended account?

  1. The result is positive, but the principal is not recorded.
  2. Verify the actual selected identity and target rather than inferring it from success.
text Synthetic credential trace
expected principal=account-A
request=success
observed principal=unknown

This fixture loads no credentials and makes no cloud request.

Expected result: Verify the actual selected identity and target rather than inferring it from success.

Why this result follows: A successful operation can be performed by an unintended identity with access.

Common errors and fixes

CLI success is assumed to prove application identity

Why it happens
CLI credentials and local ADC are distinct.
How to fix it
Inspect the application’s actual credential source and principal.
Prevent it next time
Document both contexts in testing.

The expected attached identity is assumed to be active

Why it happens
An earlier ADC source may be selected.
How to fix it
Review environment and credential discovery without exposing secrets.
Prevent it next time
Keep runtime credential sources intentional.

Authentication is treated as authorization

Why it happens
IAM checks the operation and resource separately.
How to fix it
Review the exact denial and applicable policy.
Prevent it next time
Test intended access and a neighboring denial.

20 practice exercises

1. A gcloud command succeeds but the application receives permission denied. What should be compared?

Show hint

Compare the two requests’ identity and target contexts before editing IAM.

Show worked solution

Compare CLI and ADC identities, target project, resource and exact operation before changing IAM.

The gcloud CLI and application ADC can select different credentials. Record each observed principal, selected source, project, exact resource and operation, then investigate the denied principal’s applicable policy. CLI success under another identity or against another target does not prove that the application request has the required permission.

Check your solution

  • Identify both principals and credential contexts.
  • Compare the exact project, resource and operation.

2. A service expects an attached account but a credential path is configured. What next?

Show hint

A configured path can precede the attached identity in ADC discovery.

Show worked solution

Investigate which ADC source the library uses and correct it through the approved process without copying the credential.

Inspect the runtime environment and determine which source the library actually selects, without copying or printing credential contents. Confirm the observed principal and why the path exists; correct an unintended source using the approved process, then repeat the same bounded request before considering a permission change.

Check your solution

  • Identify the selected source and observed principal.
  • Do not expose credential contents or assume attachment was selected.

3. A gcloud command uses user A and succeeds; the application uses user B and is denied. What should be compared first?

Show hint

The two tools can use distinct credential contexts.

Show worked solution

Record both principals, target project, resource and exact operation, then trace B’s ADC source and applicable authorization. A success under A does not establish B’s permission, so avoid changing A’s roles as a first response.

Check your solution

  • Identify A versus B.
  • Compare the same target and operation.

4. An environment credential configuration selects account B while the attached account is A. The application appears as B. What next?

Show hint

Review discovery order without exposing secrets.

Show worked solution

Investigate why the environment source is present and correct any unintended configuration through the approved process. Then observe the runtime principal and test the intended operation; broadening A does not fix a request using B.

Check your solution

  • Identify the higher-priority environment source.
  • Recheck the observed principal after an approved correction.

5. A local developer read succeeds, but the deployed account’s request has not run. Does local success establish deployment access?

Show hint

Compare the environments and principals.

Show worked solution

No. The result describes the developer’s local credential and request. Inspect the deployed workload’s selected ADC source and target permissions, then run an authorized bounded test if needed.

Check your solution

  • Identify the local credential context.
  • Keep deployed access unverified.

6. The CLI targets a development project and the application targets production. Why is a direct success-versus-denial comparison incomplete?

Show hint

A target is part of the request context.

Show worked solution

The requests address different projects and may encounter different resources and policies. Confirm exact project, resource, operation and principal for each before deciding whether a credential or authorization change is warranted.

Check your solution

  • Identify the project difference.
  • Compare exact resource and principal.

7. A credential path is configured but its identity has not been observed. Can its principal be inferred from the path name?

Show hint

A path is not an identity record.

Show worked solution

No. Inspect the selected source through authorized means and observe the principal without copying or printing credential contents. Record the source category and time, and keep the principal unknown until supported by evidence.

Check your solution

  • Identify the unobserved principal.
  • Avoid exposing the credential file.

8. An attached service account is configured, but a higher-priority environment source may exist. Does attachment prove selection?

Show hint

Trace the documented ADC search order.

Show worked solution

No. Review whether an earlier source is configured and determine the principal actually used by the application. Only then assess the intended account’s resource permissions or propose an approved configuration correction.

Check your solution

  • Identify the possible earlier source.
  • Keep selection unverified until observed.

9. Token acquisition succeeds for account A but object read is denied. What remains to investigate?

Show hint

Authentication and authorization are separate.

Show worked solution

Review the exact object, required permission and account A’s applicable bindings, conditions and service controls. A successful token request establishes the credential path observed, not permission for the target operation.

Check your solution

  • Identify the actual target and operation.
  • Review applicable authorization separately.

10. A reader role is granted to account A but the denied request used account B. Should the team enlarge A’s role?

Show hint

Compare the grant principal with the request principal.

Show worked solution

First trace why B was selected and inspect B’s applicable policy for the actual target. A broader role on A may not affect B’s request and could introduce unnecessary access.

Check your solution

  • Identify the A versus B mismatch.
  • Trace B before changing grants.

11. The environment source is unset, a local ADC file is present, and an attached account is configured. What should be inspected?

Show hint

Review the documented discovery order.

Show worked solution

Inspect the actual runtime context and whether the local ADC file is selected before assuming the attached account is used. Do so without printing credential contents, then observe the principal through authorized evidence.

Check your solution

  • Identify the local ADC file as an earlier source.
  • Avoid exposing credential contents.

12. A CLI metadata read succeeds while an application object read fails, and their principals are unknown. What makes the comparison incomplete?

Show hint

Both identity and operation matter.

Show worked solution

The two operations may require different permissions and the principals have not been compared. Record each actual identity, exact resource and operation before investigating applicable policies or changing a role.

Check your solution

  • Identify the operation difference.
  • Identify the missing principal comparison.

13. Removing a credential path is proposed but approval is pending. Has the runtime source changed?

Show hint

A proposed change is not an observed state.

Show worked solution

The runtime source remains unverified. Complete the applicable approval and inspect the actual environment and selected principal after any authorized change; do not treat the proposal as proof of removal.

Check your solution

  • Identify pending approval.
  • Require current runtime evidence.

14. Account A has reader on bucket X but requests an object in bucket Y. Does the X grant establish Y access?

Show hint

Compare exact resource scopes.

Show worked solution

No. Inspect the applicable policy, conditions and service controls for bucket Y and the requested object. A grant on bucket X alone does not establish permission on a different bucket.

Check your solution

  • Identify X versus Y.
  • Review Y’s applicable policy.

15. Credential contents appear in a support ticket. What should the diagnostic record retain?

Show hint

Separate useful context from secret material.

Show worked solution

Follow the organization’s credential-exposure process and retain sanitized identifiers, source category, timestamps and outcome instead of the credential contents. Verify any authorized credential lifecycle response separately rather than assuming ticket cleanup revoked it.

Check your solution

  • Identify the exposed credential as sensitive.
  • Retain sanitized context and verify response separately.

16. An ADC test last week used account A, but the environment changed today. Is A still established as the current principal?

Show hint

Bind the observation to its configuration and time.

Show worked solution

No. Inspect the current selected source and observe the principal under an authorized bounded test if needed. The prior result describes the previous environment and cannot prove current selection after a change.

Check your solution

  • Identify the intervening change.
  • Require current source and principal evidence.

17. The host has local ADC for user A, but a container’s environment is uninspected. Can the host result be assigned to the container?

Show hint

The runtime contexts can differ.

Show worked solution

No. Inspect credential discovery within the actual container environment, including its available configuration and observed principal, without exposing secrets. A host filesystem or environment observation does not prove the container’s source.

Check your solution

  • Identify the uninspected container context.
  • Keep the container principal unverified.

18. User A deploys a workload with attached account B, but the application source is unknown. Which identity is the runtime caller?

Show hint

Deployer, configured account and observed caller are distinct.

Show worked solution

The runtime caller is unknown from these records. Trace the application’s selected ADC source and obtain sanitized evidence of the actual principal; do not infer it solely from either the deployer or attachment.

Check your solution

  • Identify A and B’s separate roles.
  • Record the caller as unknown.

19. Account A has a conditional reader binding, but the request time needed by the condition is missing. Is access established?

Show hint

A condition requires relevant context.

Show worked solution

No. Obtain the exact condition and request context, then review all applicable policies and the target operation. A matching principal and role name alone cannot resolve a time-dependent binding.

Check your solution

  • Identify missing request time.
  • Keep the effective outcome unresolved.

20. An application request succeeds, but its observed principal is not recorded. Does success prove the intended account was used?

Show hint

A different identity might also have permission.

Show worked solution

No. Verify the selected ADC source, actual principal and exact target using authorized sanitized evidence. The successful operation is useful evidence of that request, but it does not identify the caller by itself.

Check your solution

  • Identify the missing principal.
  • Separate success from identity verification.

Key takeaways

  • ADC discovers credentials; it is not a permission grant.
  • Local ADC and gcloud CLI credentials are distinct.
  • Verify principal, project and operation separately.
  • CLI and application credentials can differ.
  • A configured attached account does not prove it was selected.
  • Sanitized, scoped observations support a bounded diagnosis.

Official references