Skip to content

fix: fail-fast on missing ECP config file to avoid 30s hang#17377

Open
nbayati wants to merge 2 commits into
googleapis:mainfrom
nbayati:fix-ecp-fail-fast
Open

fix: fail-fast on missing ECP config file to avoid 30s hang#17377
nbayati wants to merge 2 commits into
googleapis:mainfrom
nbayati:fix-ecp-fail-fast

Conversation

@nbayati
Copy link
Copy Markdown
Contributor

@nbayati nbayati commented Jun 4, 2026

This PR resolves two issues in the google-auth package:

First, it adds a fast-fail check for ECP configuration. When the GOOGLE_API_CERTIFICATE_CONFIG environment variable is set but the configuration file is missing (common on corporate workstations or clean sandbox test runners), the SDK was falling through to the well-known SPIFFE path and waiting on a 30-second retry loop. We now check if the config path is set but missing, and if we are not in a workload environment (the well-known credentials directory is absent), we immediately return None to fallback to unbound tokens. (Fixes b/512912028)

Second, it fixes an incorrect mock in test_mtls.py. test_default_client_encrypted_cert_source was mocking open in the test namespace instead of the target module namespace. This caused the test to write actual cert_path and key_path files to the local disk during test runs. This is fixed by patching google.auth.transport.mtls.open.

Unit tests have been added to verify the fast-fail behavior, and existing retry tests have been updated to mock the workload directory. All tests now pass without writing files to disk.

@nbayati nbayati requested review from a team as code owners June 4, 2026 20:43
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 introduces a fail-fast mechanism in _agent_identity_utils.py that immediately returns None if the ECP config path is specified but does not exist on a workstation. The tests have been updated to mock os.path.exists to simulate workload environments, and a new test has been added to verify the workstation fail-fast behavior. The reviewer suggested simplifying the nested helper functions exists_side_effect in the tests to concise lambda expressions to improve readability and reduce boilerplate.

Comment on lines +178 to +182
def exists_side_effect(path):
if path == "/var/run/secrets/workload-spiffe-credentials":
return True
return False
mock_exists.side_effect = exists_side_effect
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The nested helper function exists_side_effect can be simplified to a concise lambda expression to improve readability and reduce boilerplate.

        mock_exists.side_effect = lambda path: path == "/var/run/secrets/workload-spiffe-credentials"

Comment on lines +201 to +205
def exists_side_effect(path):
if path == "/var/run/secrets/workload-spiffe-credentials":
return True
return False
mock_exists.side_effect = exists_side_effect
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The nested helper function exists_side_effect can be simplified to a concise lambda expression to improve readability and reduce boilerplate.

        mock_exists.side_effect = lambda path: path == "/var/run/secrets/workload-spiffe-credentials"

If GOOGLE_API_CERTIFICATE_CONFIG is set but the file is missing, and we are not in a workload environment (e.g. on a workstation), exit early and return None. This avoids a 30-second hang trying to poll the well-known SPIFFE path.
@nbayati nbayati force-pushed the fix-ecp-fail-fast branch from f3b2666 to e63c5ad Compare June 4, 2026 20:48
The test test_default_client_encrypted_cert_source mocked open in the test module itself instead of the target module, causing it to write dummy cert_path and key_path files to disk during test runs.
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.

1 participant