Skip to content

fix(auth): fail-fast on invalid or non-workload certificate configs in agent identity discovery#17116

Open
nbayati wants to merge 3 commits into
googleapis:mainfrom
nbayati:fix-agent-bound-token-cert-discovery
Open

fix(auth): fail-fast on invalid or non-workload certificate configs in agent identity discovery#17116
nbayati wants to merge 3 commits into
googleapis:mainfrom
nbayati:fix-agent-bound-token-cert-discovery

Conversation

@nbayati
Copy link
Copy Markdown
Contributor

@nbayati nbayati commented May 14, 2026

The GOOGLE_API_CERTIFICATE_CONFIG environment variable is shared between Managed Workload Identity (MWLID) token-binding and other flows like Enterprise Certificate Provider (ECP) configs (e.g., PKCS#11).

When this env var is set, agent identity discovery is triggered. If the config file exists but lacks the "workload" section (as with ECP configurations),we should exit early and return None to avoid delaying non-workload flows.

In addition, if the config file on disk had syntax errors or invalid JSON, the previous logic entered a 30-second blocking retry loop before failing with RefreshError. To resolve this, the lookup logic now assumes that if the config file exists on disk, it is in its final format. If the file exists but lacks a "workload" section, has syntax errors, or is unreadable, we return None immediately to fail-fast and avoid startup delays.

b/512912028

…n agent identity discovery

The `GOOGLE_API_CERTIFICATE_CONFIG` environment variable is shared between Managed Workload Identity (MWLID) token-binding and other flows like Enterprise Certificate Provider (ECP) configs (e.g., PKCS#11).

When this env var is set, agent identity discovery is triggered. If the config file exists but lacks the `"workload"` section (as with ECP configurations),we should exit early and return `None` to avoid delaying non-workload flows.

In addition, if the config file on disk had syntax errors or invalid JSON, the previous logic entered a 30-second blocking retry loop before failing with `RefreshError`.
To resolve this, the lookup logic now assumes that if the config file exists on disk, it is in its final format. If the file exists but lacks a `"workload"` section, has syntax errors, or is unreadable, we return `None` immediately to fail-fast and avoid startup delays.
@nbayati nbayati requested review from a team as code owners May 14, 2026 00:26
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the get_agent_identity_certificate_path function to support a well-known workload directory fallback and improves the robustness of configuration parsing with better type checking and fail-fast logic. New test cases were added to cover various invalid configuration scenarios. Feedback was provided to add an explicit type check for the cert_configs dictionary to prevent a potential AttributeError and to raise an error instead of returning None for malformed configurations.

Comment thread packages/google-auth/google/auth/_agent_identity_utils.py
Comment thread packages/google-auth/google/auth/_agent_identity_utils.py
# The config was parsed, but the cert file is not ready yet
target_path = cert_path

# Path B: Config is NOT set, fallback to the the well-known path
Copy link
Copy Markdown
Contributor

@agrawalradhika-cell agrawalradhika-cell May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: # Path B: Config is NOT set, fallback to the well-known path

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I'm following what this nit is about. Can you please clarify?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, thanks for flagging it, Done!

Copy link
Copy Markdown
Contributor

@agrawalradhika-cell agrawalradhika-cell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided some minor comments, rest looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants