google-auth 2.62.2__tar.gz → 2.63.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {google_auth-2.62.2/google_auth.egg-info → google_auth-2.63.0}/PKG-INFO +1 -1
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_regional_access_boundary_utils.py +38 -7
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/credentials.py +9 -1
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/environment_vars.py +10 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/external_account.py +3 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/version.py +1 -1
- {google_auth-2.62.2 → google_auth-2.63.0/google_auth.egg-info}/PKG-INFO +1 -1
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/compute_engine/test_credentials.py +53 -2
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/conftest.py +4 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test__regional_access_boundary_utils.py +123 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_credentials.py +11 -3
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_external_account.py +38 -3
- {google_auth-2.62.2 → google_auth-2.63.0}/LICENSE +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/MANIFEST.in +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/README.rst +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_agent_identity_utils.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_cache.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_cloud_sdk.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_credentials_async.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_credentials_base.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_default.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_default_async.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_exponential_backoff.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_helpers.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_jwt_async.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_oauth2client.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_refresh_worker.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/_service_account_info.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/aio/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/aio/_helpers.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/aio/credentials.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/aio/transport/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/aio/transport/aiohttp.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/aio/transport/mtls.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/aio/transport/sessions.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/api_key.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/app_engine.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/aws.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/compute_engine/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/compute_engine/_metadata.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/compute_engine/_mtls.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/compute_engine/credentials.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/crypt/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/crypt/_cryptography_rsa.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/crypt/_helpers.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/crypt/_python_rsa.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/crypt/base.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/crypt/es.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/crypt/es256.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/crypt/rsa.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/downscoped.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/exceptions.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/external_account_authorized_user.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/iam.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/identity_pool.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/impersonated_credentials.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/jwt.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/metrics.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/pluggable.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/py.typed +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/_aiohttp_requests.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/_custom_tls_signer.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/_http_client.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/_mtls_helper.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/_requests_base.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/grpc.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/mtls.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/requests.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/auth/transport/urllib3.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/_client.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/_client_async.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/_credentials_async.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/_id_token_async.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/_reauth_async.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/_service_account_async.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/challenges.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/credentials.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/gdch_credentials.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/id_token.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/py.typed +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/reauth.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/service_account.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/sts.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/utils.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/webauthn_handler.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/webauthn_handler_factory.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google/oauth2/webauthn_types.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google_auth.egg-info/SOURCES.txt +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google_auth.egg-info/dependency_links.txt +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google_auth.egg-info/requires.txt +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/google_auth.egg-info/top_level.txt +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/setup.cfg +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/setup.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/aio/test__helpers.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/compute_engine/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/compute_engine/data/smbios_product_name +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/compute_engine/data/smbios_product_name_non_google +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/compute_engine/test__metadata.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/compute_engine/test__mtls.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/crypt/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/crypt/test__cryptography_rsa.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/crypt/test__python_rsa.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/crypt/test_crypt.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/crypt/test_es.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/crypt/test_es256.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/crypt/test_rsa.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/authorized_user.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/authorized_user_cloud_sdk.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/authorized_user_cloud_sdk_with_quota_project_id.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/authorized_user_with_rapt_token.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/client_secrets.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/context_aware_metadata.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/enterprise_cert_invalid.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/enterprise_cert_valid.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/enterprise_cert_valid_provider.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/es256_privatekey.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/es256_public_cert.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/es256_publickey.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/es256_service_account.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/es384_privatekey.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/es384_public_cert.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/es384_publickey.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/es384_service_account.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/external_account_authorized_user.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/external_account_authorized_user_non_gdu.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/external_subject_token.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/external_subject_token.txt +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/gdch_service_account.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/impersonated_service_account_authorized_user_source.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/impersonated_service_account_external_account_authorized_user_source.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/impersonated_service_account_service_account_source.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/impersonated_service_account_with_quota_project.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/old_oauth_credentials_py3.pickle +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/other_cert.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/pem_from_pkcs12.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/privatekey.p12 +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/privatekey.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/privatekey.pub +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/public_cert.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/service_account.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/service_account_non_gdu.json +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/trust_chain_with_leaf.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/trust_chain_without_leaf.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/data/trust_chain_wrong_order.pem +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test__client.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_challenges.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_credentials.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_gdch_credentials.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_id_token.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_reauth.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_service_account.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_sts.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_utils.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_webauthn_handler.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_webauthn_handler_factory.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/oauth2/test_webauthn_types.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test__cache.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test__cloud_sdk.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test__default.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test__exponential_backoff.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test__helpers.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test__oauth2client.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test__refresh_worker.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test__service_account_info.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_agent_identity_utils.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_api_key.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_app_engine.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_aws.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_credentials_async.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_downscoped.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_exceptions.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_external_account_authorized_user.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_iam.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_identity_pool.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_impersonated_credentials.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_jwt.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_metrics.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_packaging.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/test_pluggable.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/__init__.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/aio/conftest.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/aio/test_aiohttp.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/aio/test_mtls.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/aio/test_sessions.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/aio/test_sessions_mtls.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/aioresponses_compat.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/compliance.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/test__custom_tls_signer.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/test__http_client.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/test__mtls_helper.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/test_aio_mtls_helper.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/test_grpc.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/test_mtls.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/test_requests.py +0 -0
- {google_auth-2.62.2 → google_auth-2.63.0}/tests/transport/test_urllib3.py +0 -0
|
@@ -20,10 +20,11 @@ import datetime
|
|
|
20
20
|
import functools
|
|
21
21
|
import inspect
|
|
22
22
|
import logging
|
|
23
|
+
import os
|
|
23
24
|
import threading
|
|
24
25
|
from typing import TYPE_CHECKING, NamedTuple, Optional
|
|
25
26
|
|
|
26
|
-
from google.auth import _helpers
|
|
27
|
+
from google.auth import _helpers, environment_vars
|
|
27
28
|
|
|
28
29
|
if TYPE_CHECKING: # pragma: NO COVER
|
|
29
30
|
import google.auth.credentials
|
|
@@ -31,6 +32,28 @@ if TYPE_CHECKING: # pragma: NO COVER
|
|
|
31
32
|
|
|
32
33
|
_LOGGER = logging.getLogger(__name__)
|
|
33
34
|
|
|
35
|
+
# Environment variable values that enable an opt-in feature.
|
|
36
|
+
_TRUTHY_VALUES = ("y", "yes", "t", "true", "on", "1")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def is_regional_access_boundary_lookup_enabled() -> bool:
|
|
40
|
+
"""Checks if Regional Access Boundary lookup is enabled via environment variable.
|
|
41
|
+
|
|
42
|
+
Defaults to disabled unless
|
|
43
|
+
``GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED``
|
|
44
|
+
is set to a truthy value (``"y"``, ``"yes"``, ``"t"``, ``"true"``, ``"on"``,
|
|
45
|
+
or ``"1"``, case-insensitive, ignoring surrounding whitespace). Any other
|
|
46
|
+
value, including unrecognized ones, leaves lookup disabled.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
bool: True if Regional Access Boundary lookup is enabled, False otherwise.
|
|
50
|
+
"""
|
|
51
|
+
value = os.environ.get(
|
|
52
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
53
|
+
"",
|
|
54
|
+
)
|
|
55
|
+
return value.strip().lower() in _TRUTHY_VALUES
|
|
56
|
+
|
|
34
57
|
|
|
35
58
|
# The default lifetime for a cached Regional Access Boundary.
|
|
36
59
|
DEFAULT_REGIONAL_ACCESS_BOUNDARY_TTL = datetime.timedelta(hours=6)
|
|
@@ -117,12 +140,18 @@ class _RegionalAccessBoundaryManager(object):
|
|
|
117
140
|
def set_initial_regional_access_boundary(self, encoded_locations=None, expiry=None):
|
|
118
141
|
"""Manually sets the regional access boundary to the client provided initial values.
|
|
119
142
|
|
|
143
|
+
If Regional Access Boundary lookup is disabled via environment variable,
|
|
144
|
+
any existing or provided boundary values are cleared to None.
|
|
145
|
+
|
|
120
146
|
Args:
|
|
121
147
|
encoded_locations (Optional[str]): The encoded locations string.
|
|
122
148
|
expiry (Optional[datetime.datetime]): The expiry time for the boundary.
|
|
123
149
|
If encoded_locations is not provided, expiry is ignored.
|
|
124
150
|
"""
|
|
125
|
-
if not
|
|
151
|
+
if not is_regional_access_boundary_lookup_enabled():
|
|
152
|
+
encoded_locations = None
|
|
153
|
+
expiry = None
|
|
154
|
+
elif not encoded_locations:
|
|
126
155
|
expiry = None
|
|
127
156
|
|
|
128
157
|
self._data = _RegionalAccessBoundaryData(
|
|
@@ -135,17 +164,19 @@ class _RegionalAccessBoundaryManager(object):
|
|
|
135
164
|
def apply_headers(self, headers):
|
|
136
165
|
"""Applies the Regional Access Boundary header to the provided dictionary.
|
|
137
166
|
|
|
138
|
-
If the boundary is valid
|
|
139
|
-
|
|
140
|
-
data is sent.
|
|
167
|
+
If the boundary is valid and Regional Access Boundary lookup is enabled,
|
|
168
|
+
the 'x-allowed-locations' header is added or updated. Otherwise, the
|
|
169
|
+
header is removed to ensure no stale data is sent.
|
|
141
170
|
|
|
142
171
|
Args:
|
|
143
172
|
headers (MutableMapping[str, str]): The headers dictionary to update.
|
|
144
173
|
"""
|
|
145
174
|
rab_data = self._data
|
|
146
175
|
|
|
147
|
-
if
|
|
148
|
-
|
|
176
|
+
if (
|
|
177
|
+
is_regional_access_boundary_lookup_enabled()
|
|
178
|
+
and rab_data.encoded_locations
|
|
179
|
+
and (rab_data.expiry is not None and _helpers.utcnow() < rab_data.expiry)
|
|
149
180
|
):
|
|
150
181
|
headers[_REGIONAL_ACCESS_BOUNDARY_HEADER] = rab_data.encoded_locations
|
|
151
182
|
else:
|
|
@@ -346,11 +346,15 @@ class CredentialsWithRegionalAccessBoundary(Credentials):
|
|
|
346
346
|
@property
|
|
347
347
|
def regional_access_boundary(self):
|
|
348
348
|
"""Optional[str]: The encoded Regional Access Boundary locations."""
|
|
349
|
+
if not _regional_access_boundary_utils.is_regional_access_boundary_lookup_enabled():
|
|
350
|
+
return None
|
|
349
351
|
return self._rab_manager._data.encoded_locations
|
|
350
352
|
|
|
351
353
|
@property
|
|
352
354
|
def regional_access_boundary_expiry(self):
|
|
353
355
|
"""Optional[datetime.datetime]: The expiration time of the Regional Access Boundary."""
|
|
356
|
+
if not _regional_access_boundary_utils.is_regional_access_boundary_lookup_enabled():
|
|
357
|
+
return None
|
|
354
358
|
return self._rab_manager._data.expiry
|
|
355
359
|
|
|
356
360
|
@abc.abstractmethod
|
|
@@ -490,11 +494,15 @@ class CredentialsWithRegionalAccessBoundary(Credentials):
|
|
|
490
494
|
def _is_regional_access_boundary_lookup_required(self):
|
|
491
495
|
"""Checks if a Regional Access Boundary lookup is required.
|
|
492
496
|
|
|
493
|
-
A lookup is required if
|
|
497
|
+
A lookup is required if Regional Access Boundary lookup is enabled and
|
|
498
|
+
the universe domain is supported.
|
|
494
499
|
|
|
495
500
|
Returns:
|
|
496
501
|
bool: True if a Regional Access Boundary lookup is required, False otherwise.
|
|
497
502
|
"""
|
|
503
|
+
if not _regional_access_boundary_utils.is_regional_access_boundary_lookup_enabled():
|
|
504
|
+
return False
|
|
505
|
+
|
|
498
506
|
# Skip for non-default universe domains.
|
|
499
507
|
if self.universe_domain != DEFAULT_UNIVERSE_DOMAIN:
|
|
500
508
|
return False
|
|
@@ -112,6 +112,16 @@ GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED = "GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED"
|
|
|
112
112
|
This environment variable is deprecated and no longer has any effect.
|
|
113
113
|
"""
|
|
114
114
|
|
|
115
|
+
GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED = (
|
|
116
|
+
"GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED"
|
|
117
|
+
)
|
|
118
|
+
"""Experimental environment variable controlling whether to enable Regional
|
|
119
|
+
Access Boundary lookup.
|
|
120
|
+
|
|
121
|
+
Defaults to disabled; setting a case-insensitive truthy value (such as
|
|
122
|
+
``"true"`` or ``"1"``) enables it.
|
|
123
|
+
"""
|
|
124
|
+
|
|
115
125
|
GOOGLE_API_CERTIFICATE_CONFIG = "GOOGLE_API_CERTIFICATE_CONFIG"
|
|
116
126
|
"""Environment variable defining the location of Google API certificate config
|
|
117
127
|
file."""
|
|
@@ -455,6 +455,9 @@ class Credentials(
|
|
|
455
455
|
HTTP requests.
|
|
456
456
|
url (str): The URL of the request.
|
|
457
457
|
"""
|
|
458
|
+
if not _regional_access_boundary_utils.is_regional_access_boundary_lookup_enabled():
|
|
459
|
+
return
|
|
460
|
+
|
|
458
461
|
if self._should_initialize_impersonated_credentials():
|
|
459
462
|
with self._impersonation_lock:
|
|
460
463
|
if self._impersonated_credentials is None:
|
|
@@ -22,6 +22,7 @@ import responses # type: ignore
|
|
|
22
22
|
|
|
23
23
|
from google.auth import (
|
|
24
24
|
_helpers,
|
|
25
|
+
environment_vars,
|
|
25
26
|
exceptions,
|
|
26
27
|
jwt,
|
|
27
28
|
metrics,
|
|
@@ -424,7 +425,11 @@ class TestCredentials(object):
|
|
|
424
425
|
url = creds._build_regional_access_boundary_lookup_url()
|
|
425
426
|
assert url is None
|
|
426
427
|
|
|
427
|
-
def test_is_regional_access_boundary_lookup_required(self):
|
|
428
|
+
def test_is_regional_access_boundary_lookup_required(self, monkeypatch):
|
|
429
|
+
monkeypatch.setenv(
|
|
430
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
431
|
+
"true",
|
|
432
|
+
)
|
|
428
433
|
creds = self.credentials
|
|
429
434
|
creds._universe_domain_cached = True
|
|
430
435
|
|
|
@@ -456,8 +461,12 @@ class TestCredentials(object):
|
|
|
456
461
|
"google.auth.compute_engine._metadata.get_service_account_info", autospec=True
|
|
457
462
|
)
|
|
458
463
|
def test_regional_access_boundary_disabled_state_transitions(
|
|
459
|
-
self, mock_get_service_account_info
|
|
464
|
+
self, mock_get_service_account_info, monkeypatch
|
|
460
465
|
):
|
|
466
|
+
monkeypatch.setenv(
|
|
467
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
468
|
+
"true",
|
|
469
|
+
)
|
|
461
470
|
mock_get_service_account_info.return_value = {
|
|
462
471
|
"email": "spiffe://trust-domain/ns/ns/sa/sa",
|
|
463
472
|
"scopes": ["one", "two"],
|
|
@@ -588,6 +597,48 @@ class TestCredentials(object):
|
|
|
588
597
|
assert creds._rab_manager._use_blocking_regional_access_boundary_lookup
|
|
589
598
|
assert new_creds is creds
|
|
590
599
|
|
|
600
|
+
@responses.activate
|
|
601
|
+
def test_before_request_skips_rab_when_disabled_by_env_var(
|
|
602
|
+
self, monkeypatch, tmp_path
|
|
603
|
+
):
|
|
604
|
+
monkeypatch.setenv(environment_vars.CLOUD_SDK_CONFIG_DIR, str(tmp_path))
|
|
605
|
+
monkeypatch.setenv(
|
|
606
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
607
|
+
"false",
|
|
608
|
+
)
|
|
609
|
+
responses.add(
|
|
610
|
+
responses.GET,
|
|
611
|
+
"http://metadata.google.internal/computeMetadata/v1/instance/"
|
|
612
|
+
"service-accounts/default/?recursive=true",
|
|
613
|
+
status=200,
|
|
614
|
+
content_type="application/json",
|
|
615
|
+
json={"email": "service-account@project.iam.gserviceaccount.com"},
|
|
616
|
+
)
|
|
617
|
+
responses.add(
|
|
618
|
+
responses.GET,
|
|
619
|
+
"http://metadata.google.internal/computeMetadata/v1/instance/"
|
|
620
|
+
"service-accounts/default/token",
|
|
621
|
+
status=200,
|
|
622
|
+
content_type="application/json",
|
|
623
|
+
json={"access_token": "mds-token", "expires_in": 500},
|
|
624
|
+
)
|
|
625
|
+
|
|
626
|
+
creds = credentials.Credentials()
|
|
627
|
+
creds._set_blocking_regional_access_boundary_lookup()
|
|
628
|
+
headers = {}
|
|
629
|
+
creds.before_request(
|
|
630
|
+
requests.Request(), "GET", "https://storage.googleapis.com", headers
|
|
631
|
+
)
|
|
632
|
+
|
|
633
|
+
assert headers["authorization"] == "Bearer mds-token"
|
|
634
|
+
assert "x-allowed-locations" not in headers
|
|
635
|
+
assert [call.request.url for call in responses.calls] == [
|
|
636
|
+
"http://metadata.google.internal/computeMetadata/v1/instance/"
|
|
637
|
+
"service-accounts/default/?recursive=true",
|
|
638
|
+
"http://metadata.google.internal/computeMetadata/v1/instance/"
|
|
639
|
+
"service-accounts/default/token",
|
|
640
|
+
]
|
|
641
|
+
|
|
591
642
|
|
|
592
643
|
class TestIDTokenCredentials(object):
|
|
593
644
|
credentials = None
|
|
@@ -55,6 +55,10 @@ def clean_cert_config_env(monkeypatch, tmp_path):
|
|
|
55
55
|
environment_vars.CLOUDSDK_CONTEXT_AWARE_CERTIFICATE_CONFIG_FILE_PATH,
|
|
56
56
|
raising=False,
|
|
57
57
|
)
|
|
58
|
+
monkeypatch.delenv(
|
|
59
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
60
|
+
raising=False,
|
|
61
|
+
)
|
|
58
62
|
monkeypatch.setattr(
|
|
59
63
|
_mtls_helper,
|
|
60
64
|
"_GKE_CREDENTIAL_BUNDLE_PATH",
|
|
@@ -23,6 +23,7 @@ from google.auth import (
|
|
|
23
23
|
_helpers,
|
|
24
24
|
_regional_access_boundary_utils,
|
|
25
25
|
credentials,
|
|
26
|
+
environment_vars,
|
|
26
27
|
)
|
|
27
28
|
from google.oauth2 import credentials as oauth2_credentials
|
|
28
29
|
|
|
@@ -71,7 +72,64 @@ class CredentialsImpl(credentials.CredentialsWithRegionalAccessBoundary):
|
|
|
71
72
|
return new_credentials
|
|
72
73
|
|
|
73
74
|
|
|
75
|
+
@pytest.fixture(autouse=True)
|
|
76
|
+
def enable_rab_lookup(monkeypatch):
|
|
77
|
+
monkeypatch.setenv(
|
|
78
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
79
|
+
"true",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
74
83
|
class TestCredentialsWithRegionalAccessBoundary(object):
|
|
84
|
+
def test_is_regional_access_boundary_lookup_enabled_unset(self, monkeypatch):
|
|
85
|
+
monkeypatch.delenv(
|
|
86
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
87
|
+
raising=False,
|
|
88
|
+
)
|
|
89
|
+
assert (
|
|
90
|
+
_regional_access_boundary_utils.is_regional_access_boundary_lookup_enabled()
|
|
91
|
+
is False
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
@pytest.mark.parametrize(
|
|
95
|
+
"env_value,expected",
|
|
96
|
+
[
|
|
97
|
+
("", False),
|
|
98
|
+
("true", True),
|
|
99
|
+
("1", True),
|
|
100
|
+
(" True \n", True),
|
|
101
|
+
("false", False),
|
|
102
|
+
("ture", False),
|
|
103
|
+
],
|
|
104
|
+
)
|
|
105
|
+
def test_is_regional_access_boundary_lookup_enabled_values(
|
|
106
|
+
self, monkeypatch, env_value, expected
|
|
107
|
+
):
|
|
108
|
+
monkeypatch.setenv(
|
|
109
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
110
|
+
env_value,
|
|
111
|
+
)
|
|
112
|
+
assert (
|
|
113
|
+
_regional_access_boundary_utils.is_regional_access_boundary_lookup_enabled()
|
|
114
|
+
is expected
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def test_maybe_start_refresh_is_skipped_when_disabled_by_env_var(self, monkeypatch):
|
|
118
|
+
monkeypatch.setenv(
|
|
119
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
120
|
+
"false",
|
|
121
|
+
)
|
|
122
|
+
creds = CredentialsImpl()
|
|
123
|
+
creds.token = "access-token"
|
|
124
|
+
request = mock.Mock()
|
|
125
|
+
headers = {}
|
|
126
|
+
|
|
127
|
+
creds.before_request(request, "GET", "http://example.com", headers)
|
|
128
|
+
|
|
129
|
+
request.assert_not_called()
|
|
130
|
+
assert creds._rab_manager.refresh_manager._worker is None
|
|
131
|
+
assert headers == {"authorization": "Bearer access-token"}
|
|
132
|
+
|
|
75
133
|
@mock.patch(
|
|
76
134
|
"google.auth._regional_access_boundary_utils._RegionalAccessBoundaryRefreshManager.start_refresh"
|
|
77
135
|
)
|
|
@@ -590,6 +648,25 @@ class AsyncCredentialsImpl(_credentials_async.CredentialsWithRegionalAccessBound
|
|
|
590
648
|
|
|
591
649
|
|
|
592
650
|
class TestAsyncCredentialsWithRegionalAccessBoundary(object):
|
|
651
|
+
@pytest.mark.asyncio
|
|
652
|
+
async def test_maybe_start_refresh_async_skipped_when_disabled_by_env_var(
|
|
653
|
+
self, monkeypatch
|
|
654
|
+
):
|
|
655
|
+
monkeypatch.setenv(
|
|
656
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
657
|
+
"false",
|
|
658
|
+
)
|
|
659
|
+
creds = AsyncCredentialsImpl()
|
|
660
|
+
creds.token = "access-token"
|
|
661
|
+
request = mock.AsyncMock()
|
|
662
|
+
headers = {}
|
|
663
|
+
|
|
664
|
+
await creds.before_request(request, "GET", "http://example.com", headers)
|
|
665
|
+
|
|
666
|
+
request.assert_not_called()
|
|
667
|
+
assert creds._rab_manager.refresh_manager._worker_task is None
|
|
668
|
+
assert headers == {"authorization": "Bearer access-token"}
|
|
669
|
+
|
|
593
670
|
@pytest.mark.asyncio
|
|
594
671
|
async def test_maybe_start_refresh_async_blocking(self):
|
|
595
672
|
creds = AsyncCredentialsImpl()
|
|
@@ -885,6 +962,52 @@ def test_set_initial_regional_access_boundary_with_value():
|
|
|
885
962
|
assert manager._data.expiry == expiry
|
|
886
963
|
|
|
887
964
|
|
|
965
|
+
def test_set_initial_regional_access_boundary_skipped_when_disabled(monkeypatch):
|
|
966
|
+
creds = CredentialsImpl()
|
|
967
|
+
monkeypatch.setenv(
|
|
968
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
969
|
+
"false",
|
|
970
|
+
)
|
|
971
|
+
creds._set_regional_access_boundary(
|
|
972
|
+
{
|
|
973
|
+
"encodedLocations": "0xNEW",
|
|
974
|
+
"expiry": _helpers.utcnow() + datetime.timedelta(hours=1),
|
|
975
|
+
}
|
|
976
|
+
)
|
|
977
|
+
|
|
978
|
+
monkeypatch.setenv(
|
|
979
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
980
|
+
"true",
|
|
981
|
+
)
|
|
982
|
+
assert creds.regional_access_boundary is None
|
|
983
|
+
assert creds.regional_access_boundary_expiry is None
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
def test_apply_headers_strips_header_when_disabled(monkeypatch):
|
|
987
|
+
creds = CredentialsImpl()
|
|
988
|
+
creds.token = "access-token"
|
|
989
|
+
creds._set_regional_access_boundary(
|
|
990
|
+
{
|
|
991
|
+
"encodedLocations": "0xABC",
|
|
992
|
+
"expiry": _helpers.utcnow() + datetime.timedelta(hours=1),
|
|
993
|
+
}
|
|
994
|
+
)
|
|
995
|
+
|
|
996
|
+
headers = {}
|
|
997
|
+
creds.apply(headers)
|
|
998
|
+
assert headers["x-allowed-locations"] == "0xABC"
|
|
999
|
+
|
|
1000
|
+
monkeypatch.setenv(
|
|
1001
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
1002
|
+
"false",
|
|
1003
|
+
)
|
|
1004
|
+
assert creds.regional_access_boundary is None
|
|
1005
|
+
assert creds.regional_access_boundary_expiry is None
|
|
1006
|
+
creds.apply(headers)
|
|
1007
|
+
assert "x-allowed-locations" not in headers
|
|
1008
|
+
assert headers["authorization"] == "Bearer access-token"
|
|
1009
|
+
|
|
1010
|
+
|
|
888
1011
|
def test_sync_refresh_manager_start_refresh_executes():
|
|
889
1012
|
manager = _regional_access_boundary_utils._RegionalAccessBoundaryRefreshManager()
|
|
890
1013
|
creds = mock.Mock()
|
|
@@ -17,7 +17,7 @@ from unittest import mock
|
|
|
17
17
|
|
|
18
18
|
import pytest # type: ignore
|
|
19
19
|
|
|
20
|
-
from google.auth import _helpers, credentials
|
|
20
|
+
from google.auth import _helpers, credentials, environment_vars
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class CredentialsImpl(credentials.CredentialsWithRegionalAccessBoundary):
|
|
@@ -123,7 +123,11 @@ def test_before_request():
|
|
|
123
123
|
assert "x-allowed-locations" not in headers
|
|
124
124
|
|
|
125
125
|
|
|
126
|
-
def test_before_request_with_regional_access_boundary():
|
|
126
|
+
def test_before_request_with_regional_access_boundary(monkeypatch):
|
|
127
|
+
monkeypatch.setenv(
|
|
128
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
129
|
+
"true",
|
|
130
|
+
)
|
|
127
131
|
DUMMY_BOUNDARY = "0xA30"
|
|
128
132
|
creds = CredentialsImpl()
|
|
129
133
|
creds._rab_manager._data = credentials._regional_access_boundary_utils._RegionalAccessBoundaryData(
|
|
@@ -405,7 +409,11 @@ def test_credentials_with_trust_boundary_bridge():
|
|
|
405
409
|
assert creds._build_regional_access_boundary_lookup_url() == "http://legacy.url"
|
|
406
410
|
|
|
407
411
|
|
|
408
|
-
def test_before_request_triggers_rab_refresh():
|
|
412
|
+
def test_before_request_triggers_rab_refresh(monkeypatch):
|
|
413
|
+
monkeypatch.setenv(
|
|
414
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
415
|
+
"true",
|
|
416
|
+
)
|
|
409
417
|
with mock.patch("google.oauth2._client._lookup_regional_access_boundary") as lookup:
|
|
410
418
|
lookup.return_value = {"encodedLocations": "0xA30"}
|
|
411
419
|
|
|
@@ -20,7 +20,13 @@ from unittest import mock
|
|
|
20
20
|
|
|
21
21
|
import pytest # type: ignore
|
|
22
22
|
|
|
23
|
-
from google.auth import
|
|
23
|
+
from google.auth import (
|
|
24
|
+
_helpers,
|
|
25
|
+
environment_vars,
|
|
26
|
+
exceptions,
|
|
27
|
+
external_account,
|
|
28
|
+
transport,
|
|
29
|
+
)
|
|
24
30
|
from google.auth.credentials import DEFAULT_UNIVERSE_DOMAIN, TokenState
|
|
25
31
|
|
|
26
32
|
IMPERSONATE_ACCESS_TOKEN_REQUEST_METRICS_HEADER_VALUE = "gl-python/<python-version> auth/<library-version> auth-request-type/at cred-type/imp"
|
|
@@ -1029,7 +1035,11 @@ class TestCredentials(object):
|
|
|
1029
1035
|
is credentials._impersonated_credentials._rab_manager
|
|
1030
1036
|
)
|
|
1031
1037
|
|
|
1032
|
-
def test_cached_token_initializes_impersonated_credentials(self):
|
|
1038
|
+
def test_cached_token_initializes_impersonated_credentials(self, monkeypatch):
|
|
1039
|
+
monkeypatch.setenv(
|
|
1040
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
1041
|
+
"true",
|
|
1042
|
+
)
|
|
1033
1043
|
# Initialize credentials with impersonation.
|
|
1034
1044
|
credentials = self.make_credentials(
|
|
1035
1045
|
service_account_impersonation_url=self.SERVICE_ACCOUNT_IMPERSONATION_URL,
|
|
@@ -1060,6 +1070,27 @@ class TestCredentials(object):
|
|
|
1060
1070
|
# Verify delegation occurred.
|
|
1061
1071
|
mock_rab_refresh.assert_called_once_with(request, "https://example.com")
|
|
1062
1072
|
|
|
1073
|
+
def test_cached_token_skips_impersonated_init_when_rab_disabled(self, monkeypatch):
|
|
1074
|
+
monkeypatch.setenv(
|
|
1075
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
1076
|
+
"false",
|
|
1077
|
+
)
|
|
1078
|
+
credentials = self.make_credentials(
|
|
1079
|
+
service_account_impersonation_url=self.SERVICE_ACCOUNT_IMPERSONATION_URL,
|
|
1080
|
+
scopes=self.SCOPES,
|
|
1081
|
+
)
|
|
1082
|
+
credentials.token = "CACHED_SA_TOKEN"
|
|
1083
|
+
credentials.expiry = _helpers.utcnow() + datetime.timedelta(seconds=3600)
|
|
1084
|
+
|
|
1085
|
+
request = self.make_mock_request(status=http_client.OK, data={})
|
|
1086
|
+
headers = {}
|
|
1087
|
+
credentials.before_request(request, "GET", "https://example.com", headers)
|
|
1088
|
+
|
|
1089
|
+
assert credentials._impersonated_credentials is None
|
|
1090
|
+
assert headers["authorization"] == "Bearer CACHED_SA_TOKEN"
|
|
1091
|
+
assert "x-allowed-locations" not in headers
|
|
1092
|
+
request.assert_not_called()
|
|
1093
|
+
|
|
1063
1094
|
@mock.patch(
|
|
1064
1095
|
"google.auth.metrics.token_request_access_token_impersonate",
|
|
1065
1096
|
return_value=IMPERSONATE_ACCESS_TOKEN_REQUEST_METRICS_HEADER_VALUE,
|
|
@@ -2300,8 +2331,12 @@ class TestCredentials(object):
|
|
|
2300
2331
|
credentials._impersonated_credentials.refresh.assert_called_once_with(request)
|
|
2301
2332
|
|
|
2302
2333
|
def test_regional_access_boundary_refresh_delegates_to_impersonated_credentials(
|
|
2303
|
-
self,
|
|
2334
|
+
self, monkeypatch
|
|
2304
2335
|
):
|
|
2336
|
+
monkeypatch.setenv(
|
|
2337
|
+
environment_vars.GOOGLE_SDK_EXPERIMENTAL_PYTHON_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENABLED,
|
|
2338
|
+
"true",
|
|
2339
|
+
)
|
|
2305
2340
|
credentials = self.make_credentials(
|
|
2306
2341
|
service_account_impersonation_url=self.SERVICE_ACCOUNT_IMPERSONATION_URL
|
|
2307
2342
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|