google-auth 2.62.2__tar.gz → 2.63.1__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.
Files changed (200) hide show
  1. {google_auth-2.62.2/google_auth.egg-info → google_auth-2.63.1}/PKG-INFO +1 -1
  2. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_regional_access_boundary_utils.py +38 -7
  3. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/credentials.py +9 -1
  4. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/environment_vars.py +10 -0
  5. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/external_account.py +3 -0
  6. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/jwt.py +100 -4
  7. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/version.py +1 -1
  8. {google_auth-2.62.2 → google_auth-2.63.1/google_auth.egg-info}/PKG-INFO +1 -1
  9. {google_auth-2.62.2 → google_auth-2.63.1}/tests/compute_engine/test_credentials.py +53 -2
  10. {google_auth-2.62.2 → google_auth-2.63.1}/tests/conftest.py +4 -0
  11. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test__regional_access_boundary_utils.py +123 -0
  12. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_credentials.py +11 -3
  13. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_external_account.py +38 -3
  14. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_jwt.py +496 -3
  15. {google_auth-2.62.2 → google_auth-2.63.1}/LICENSE +0 -0
  16. {google_auth-2.62.2 → google_auth-2.63.1}/MANIFEST.in +0 -0
  17. {google_auth-2.62.2 → google_auth-2.63.1}/README.rst +0 -0
  18. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/__init__.py +0 -0
  19. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_agent_identity_utils.py +0 -0
  20. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_cache.py +0 -0
  21. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_cloud_sdk.py +0 -0
  22. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_credentials_async.py +0 -0
  23. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_credentials_base.py +0 -0
  24. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_default.py +0 -0
  25. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_default_async.py +0 -0
  26. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_exponential_backoff.py +0 -0
  27. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_helpers.py +0 -0
  28. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_jwt_async.py +0 -0
  29. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_oauth2client.py +0 -0
  30. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_refresh_worker.py +0 -0
  31. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/_service_account_info.py +0 -0
  32. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/aio/__init__.py +0 -0
  33. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/aio/_helpers.py +0 -0
  34. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/aio/credentials.py +0 -0
  35. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/aio/transport/__init__.py +0 -0
  36. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/aio/transport/aiohttp.py +0 -0
  37. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/aio/transport/mtls.py +0 -0
  38. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/aio/transport/sessions.py +0 -0
  39. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/api_key.py +0 -0
  40. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/app_engine.py +0 -0
  41. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/aws.py +0 -0
  42. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/compute_engine/__init__.py +0 -0
  43. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/compute_engine/_metadata.py +0 -0
  44. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/compute_engine/_mtls.py +0 -0
  45. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/compute_engine/credentials.py +0 -0
  46. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/crypt/__init__.py +0 -0
  47. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/crypt/_cryptography_rsa.py +0 -0
  48. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/crypt/_helpers.py +0 -0
  49. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/crypt/_python_rsa.py +0 -0
  50. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/crypt/base.py +0 -0
  51. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/crypt/es.py +0 -0
  52. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/crypt/es256.py +0 -0
  53. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/crypt/rsa.py +0 -0
  54. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/downscoped.py +0 -0
  55. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/exceptions.py +0 -0
  56. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/external_account_authorized_user.py +0 -0
  57. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/iam.py +0 -0
  58. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/identity_pool.py +0 -0
  59. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/impersonated_credentials.py +0 -0
  60. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/metrics.py +0 -0
  61. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/pluggable.py +0 -0
  62. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/py.typed +0 -0
  63. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/__init__.py +0 -0
  64. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/_aiohttp_requests.py +0 -0
  65. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/_custom_tls_signer.py +0 -0
  66. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/_http_client.py +0 -0
  67. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/_mtls_helper.py +0 -0
  68. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/_requests_base.py +0 -0
  69. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/grpc.py +0 -0
  70. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/mtls.py +0 -0
  71. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/requests.py +0 -0
  72. {google_auth-2.62.2 → google_auth-2.63.1}/google/auth/transport/urllib3.py +0 -0
  73. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/__init__.py +0 -0
  74. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/_client.py +0 -0
  75. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/_client_async.py +0 -0
  76. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/_credentials_async.py +0 -0
  77. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/_id_token_async.py +0 -0
  78. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/_reauth_async.py +0 -0
  79. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/_service_account_async.py +0 -0
  80. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/challenges.py +0 -0
  81. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/credentials.py +0 -0
  82. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/gdch_credentials.py +0 -0
  83. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/id_token.py +0 -0
  84. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/py.typed +0 -0
  85. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/reauth.py +0 -0
  86. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/service_account.py +0 -0
  87. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/sts.py +0 -0
  88. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/utils.py +0 -0
  89. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/webauthn_handler.py +0 -0
  90. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/webauthn_handler_factory.py +0 -0
  91. {google_auth-2.62.2 → google_auth-2.63.1}/google/oauth2/webauthn_types.py +0 -0
  92. {google_auth-2.62.2 → google_auth-2.63.1}/google_auth.egg-info/SOURCES.txt +0 -0
  93. {google_auth-2.62.2 → google_auth-2.63.1}/google_auth.egg-info/dependency_links.txt +0 -0
  94. {google_auth-2.62.2 → google_auth-2.63.1}/google_auth.egg-info/requires.txt +0 -0
  95. {google_auth-2.62.2 → google_auth-2.63.1}/google_auth.egg-info/top_level.txt +0 -0
  96. {google_auth-2.62.2 → google_auth-2.63.1}/setup.cfg +0 -0
  97. {google_auth-2.62.2 → google_auth-2.63.1}/setup.py +0 -0
  98. {google_auth-2.62.2 → google_auth-2.63.1}/tests/__init__.py +0 -0
  99. {google_auth-2.62.2 → google_auth-2.63.1}/tests/aio/test__helpers.py +0 -0
  100. {google_auth-2.62.2 → google_auth-2.63.1}/tests/compute_engine/__init__.py +0 -0
  101. {google_auth-2.62.2 → google_auth-2.63.1}/tests/compute_engine/data/smbios_product_name +0 -0
  102. {google_auth-2.62.2 → google_auth-2.63.1}/tests/compute_engine/data/smbios_product_name_non_google +0 -0
  103. {google_auth-2.62.2 → google_auth-2.63.1}/tests/compute_engine/test__metadata.py +0 -0
  104. {google_auth-2.62.2 → google_auth-2.63.1}/tests/compute_engine/test__mtls.py +0 -0
  105. {google_auth-2.62.2 → google_auth-2.63.1}/tests/crypt/__init__.py +0 -0
  106. {google_auth-2.62.2 → google_auth-2.63.1}/tests/crypt/test__cryptography_rsa.py +0 -0
  107. {google_auth-2.62.2 → google_auth-2.63.1}/tests/crypt/test__python_rsa.py +0 -0
  108. {google_auth-2.62.2 → google_auth-2.63.1}/tests/crypt/test_crypt.py +0 -0
  109. {google_auth-2.62.2 → google_auth-2.63.1}/tests/crypt/test_es.py +0 -0
  110. {google_auth-2.62.2 → google_auth-2.63.1}/tests/crypt/test_es256.py +0 -0
  111. {google_auth-2.62.2 → google_auth-2.63.1}/tests/crypt/test_rsa.py +0 -0
  112. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/authorized_user.json +0 -0
  113. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/authorized_user_cloud_sdk.json +0 -0
  114. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/authorized_user_cloud_sdk_with_quota_project_id.json +0 -0
  115. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/authorized_user_with_rapt_token.json +0 -0
  116. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/client_secrets.json +0 -0
  117. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/context_aware_metadata.json +0 -0
  118. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/enterprise_cert_invalid.json +0 -0
  119. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/enterprise_cert_valid.json +0 -0
  120. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/enterprise_cert_valid_provider.json +0 -0
  121. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/es256_privatekey.pem +0 -0
  122. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/es256_public_cert.pem +0 -0
  123. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/es256_publickey.pem +0 -0
  124. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/es256_service_account.json +0 -0
  125. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/es384_privatekey.pem +0 -0
  126. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/es384_public_cert.pem +0 -0
  127. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/es384_publickey.pem +0 -0
  128. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/es384_service_account.json +0 -0
  129. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/external_account_authorized_user.json +0 -0
  130. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/external_account_authorized_user_non_gdu.json +0 -0
  131. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/external_subject_token.json +0 -0
  132. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/external_subject_token.txt +0 -0
  133. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/gdch_service_account.json +0 -0
  134. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/impersonated_service_account_authorized_user_source.json +0 -0
  135. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/impersonated_service_account_external_account_authorized_user_source.json +0 -0
  136. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/impersonated_service_account_service_account_source.json +0 -0
  137. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/impersonated_service_account_with_quota_project.json +0 -0
  138. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/old_oauth_credentials_py3.pickle +0 -0
  139. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/other_cert.pem +0 -0
  140. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/pem_from_pkcs12.pem +0 -0
  141. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/privatekey.p12 +0 -0
  142. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/privatekey.pem +0 -0
  143. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/privatekey.pub +0 -0
  144. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/public_cert.pem +0 -0
  145. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/service_account.json +0 -0
  146. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/service_account_non_gdu.json +0 -0
  147. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/trust_chain_with_leaf.pem +0 -0
  148. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/trust_chain_without_leaf.pem +0 -0
  149. {google_auth-2.62.2 → google_auth-2.63.1}/tests/data/trust_chain_wrong_order.pem +0 -0
  150. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/__init__.py +0 -0
  151. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test__client.py +0 -0
  152. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_challenges.py +0 -0
  153. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_credentials.py +0 -0
  154. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_gdch_credentials.py +0 -0
  155. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_id_token.py +0 -0
  156. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_reauth.py +0 -0
  157. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_service_account.py +0 -0
  158. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_sts.py +0 -0
  159. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_utils.py +0 -0
  160. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_webauthn_handler.py +0 -0
  161. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_webauthn_handler_factory.py +0 -0
  162. {google_auth-2.62.2 → google_auth-2.63.1}/tests/oauth2/test_webauthn_types.py +0 -0
  163. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test__cache.py +0 -0
  164. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test__cloud_sdk.py +0 -0
  165. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test__default.py +0 -0
  166. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test__exponential_backoff.py +0 -0
  167. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test__helpers.py +0 -0
  168. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test__oauth2client.py +0 -0
  169. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test__refresh_worker.py +0 -0
  170. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test__service_account_info.py +0 -0
  171. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_agent_identity_utils.py +0 -0
  172. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_api_key.py +0 -0
  173. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_app_engine.py +0 -0
  174. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_aws.py +0 -0
  175. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_credentials_async.py +0 -0
  176. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_downscoped.py +0 -0
  177. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_exceptions.py +0 -0
  178. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_external_account_authorized_user.py +0 -0
  179. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_iam.py +0 -0
  180. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_identity_pool.py +0 -0
  181. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_impersonated_credentials.py +0 -0
  182. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_metrics.py +0 -0
  183. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_packaging.py +0 -0
  184. {google_auth-2.62.2 → google_auth-2.63.1}/tests/test_pluggable.py +0 -0
  185. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/__init__.py +0 -0
  186. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/aio/conftest.py +0 -0
  187. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/aio/test_aiohttp.py +0 -0
  188. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/aio/test_mtls.py +0 -0
  189. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/aio/test_sessions.py +0 -0
  190. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/aio/test_sessions_mtls.py +0 -0
  191. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/aioresponses_compat.py +0 -0
  192. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/compliance.py +0 -0
  193. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/test__custom_tls_signer.py +0 -0
  194. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/test__http_client.py +0 -0
  195. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/test__mtls_helper.py +0 -0
  196. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/test_aio_mtls_helper.py +0 -0
  197. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/test_grpc.py +0 -0
  198. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/test_mtls.py +0 -0
  199. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/test_requests.py +0 -0
  200. {google_auth-2.62.2 → google_auth-2.63.1}/tests/transport/test_urllib3.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-auth
3
- Version: 2.62.2
3
+ Version: 2.63.1
4
4
  Summary: Google Authentication Library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-auth
6
6
  Author: Google Cloud Platform
@@ -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 encoded_locations:
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, the 'x-allowed-locations' header is added
139
- or updated. Otherwise, the header is removed to ensure no stale
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 rab_data.encoded_locations and (
148
- rab_data.expiry is not None and _helpers.utcnow() < rab_data.expiry
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 the universe domain is supported.
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:
@@ -75,6 +75,17 @@ if es is not None: # pragma: NO COVER
75
75
  _ALGORITHM_TO_VERIFIER_CLASS["ES384"] = es.EsVerifier # type: ignore
76
76
 
77
77
 
78
+ def _validate_universe_domain(universe_domain):
79
+ """Raises if the universe domain passed to ``with_universe_domain`` is empty.
80
+
81
+ Raises:
82
+ google.auth.exceptions.InvalidValue: If the universe domain is None,
83
+ empty, or whitespace-only.
84
+ """
85
+ if not universe_domain or not universe_domain.strip():
86
+ raise exceptions.InvalidValue("Universe domain cannot be empty.")
87
+
88
+
78
89
  def encode(signer, payload, header=None, key_id=None):
79
90
  """Make a signed JWT.
80
91
 
@@ -333,6 +344,7 @@ def decode(token, certs=None, verify=True, audience=None, clock_skew_in_seconds=
333
344
  class Credentials(
334
345
  google.auth.credentials.Signing,
335
346
  google.auth.credentials.CredentialsWithQuotaProject,
347
+ google.auth.credentials.CredentialsWithUniverseDomain,
336
348
  google.auth.credentials.CredentialsWithRegionalAccessBoundary,
337
349
  ):
338
350
  """Credentials that use a JWT as the bearer token.
@@ -393,6 +405,7 @@ class Credentials(
393
405
  additional_claims=None,
394
406
  token_lifetime=_DEFAULT_TOKEN_LIFETIME_SECS,
395
407
  quota_project_id=None,
408
+ universe_domain=google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN,
396
409
  ):
397
410
  """
398
411
  Args:
@@ -407,6 +420,8 @@ class Credentials(
407
420
  which the token is valid. Defaults to 1 hour.
408
421
  quota_project_id (Optional[str]): The project ID used for quota
409
422
  and billing.
423
+ universe_domain (Optional[str]): The universe domain. The default
424
+ universe domain is googleapis.com.
410
425
  """
411
426
  super(Credentials, self).__init__()
412
427
  self._signer = signer
@@ -415,6 +430,9 @@ class Credentials(
415
430
  self._audience = audience
416
431
  self._token_lifetime = token_lifetime
417
432
  self._quota_project_id = quota_project_id
433
+ self._universe_domain = (
434
+ universe_domain or google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN
435
+ )
418
436
 
419
437
  if additional_claims is None:
420
438
  additional_claims = {}
@@ -439,6 +457,10 @@ class Credentials(
439
457
  """
440
458
  kwargs.setdefault("subject", info["client_email"])
441
459
  kwargs.setdefault("issuer", info["client_email"])
460
+ if not kwargs.get("universe_domain"):
461
+ kwargs["universe_domain"] = info.get(
462
+ "universe_domain", google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN
463
+ )
442
464
  return cls(signer, **kwargs)
443
465
 
444
466
  @classmethod
@@ -506,11 +528,26 @@ class Credentials(
506
528
  """
507
529
  kwargs.setdefault("issuer", credentials.signer_email)
508
530
  kwargs.setdefault("subject", credentials.signer_email)
531
+ if not kwargs.get("universe_domain"):
532
+ kwargs["universe_domain"] = getattr(
533
+ credentials,
534
+ "universe_domain",
535
+ google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN,
536
+ )
509
537
  jwt_creds = cls(credentials.signer, audience=audience, **kwargs)
510
538
 
511
- if isinstance(
512
- credentials,
513
- google.auth.credentials.CredentialsWithRegionalAccessBoundary,
539
+ # Regional Access Boundary (RAB) only applies to the default universe
540
+ # domain. Reuse the source credentials' cached RAB state only when the
541
+ # new credentials stay in the default universe; otherwise start with
542
+ # empty RAB state so a googleapis.com boundary is never sent to another
543
+ # universe.
544
+ if (
545
+ isinstance(
546
+ credentials,
547
+ google.auth.credentials.CredentialsWithRegionalAccessBoundary,
548
+ )
549
+ and jwt_creds.universe_domain
550
+ == google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN
514
551
  ):
515
552
  credentials._copy_regional_access_boundary_manager(jwt_creds)
516
553
 
@@ -544,7 +581,9 @@ class Credentials(
544
581
  subject=subject if subject is not None else self._subject,
545
582
  audience=audience if audience is not None else self._audience,
546
583
  additional_claims=new_additional_claims,
584
+ token_lifetime=self._token_lifetime,
547
585
  quota_project_id=self._quota_project_id,
586
+ universe_domain=self._universe_domain,
548
587
  )
549
588
  self._copy_regional_access_boundary_manager(cred)
550
589
  return cred
@@ -557,11 +596,32 @@ class Credentials(
557
596
  subject=self._subject,
558
597
  audience=self._audience,
559
598
  additional_claims=self._additional_claims,
599
+ token_lifetime=self._token_lifetime,
560
600
  quota_project_id=quota_project_id,
601
+ universe_domain=self._universe_domain,
561
602
  )
562
603
  self._copy_regional_access_boundary_manager(cred)
563
604
  return cred
564
605
 
606
+ @_helpers.copy_docstring(google.auth.credentials.CredentialsWithUniverseDomain)
607
+ def with_universe_domain(self, universe_domain):
608
+ _validate_universe_domain(universe_domain)
609
+ cred = self.__class__(
610
+ self._signer,
611
+ issuer=self._issuer,
612
+ subject=self._subject,
613
+ audience=self._audience,
614
+ additional_claims=self._additional_claims,
615
+ token_lifetime=self._token_lifetime,
616
+ quota_project_id=self._quota_project_id,
617
+ universe_domain=universe_domain,
618
+ )
619
+ # RAB state is only valid for the default universe domain, so don't
620
+ # carry cached RAB data over when switching to another universe.
621
+ if cred.universe_domain == google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN:
622
+ self._copy_regional_access_boundary_manager(cred)
623
+ return cred
624
+
565
625
  def _make_jwt(self):
566
626
  """Make a signed JWT.
567
627
 
@@ -637,7 +697,9 @@ class Credentials(
637
697
 
638
698
 
639
699
  class OnDemandCredentials(
640
- google.auth.credentials.Signing, google.auth.credentials.CredentialsWithQuotaProject
700
+ google.auth.credentials.Signing,
701
+ google.auth.credentials.CredentialsWithQuotaProject,
702
+ google.auth.credentials.CredentialsWithUniverseDomain,
641
703
  ):
642
704
  """On-demand JWT credentials.
643
705
 
@@ -665,6 +727,7 @@ class OnDemandCredentials(
665
727
  token_lifetime=_DEFAULT_TOKEN_LIFETIME_SECS,
666
728
  max_cache_size=_DEFAULT_MAX_CACHE_SIZE,
667
729
  quota_project_id=None,
730
+ universe_domain=google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN,
668
731
  ):
669
732
  """
670
733
  Args:
@@ -679,6 +742,8 @@ class OnDemandCredentials(
679
742
  cache. Tokens are cached using :class:`google.auth._cache.LRUCache`.
680
743
  quota_project_id (Optional[str]): The project ID used for quota
681
744
  and billing.
745
+ universe_domain (Optional[str]): The universe domain. The default
746
+ universe domain is googleapis.com.
682
747
 
683
748
  """
684
749
  super(OnDemandCredentials, self).__init__()
@@ -687,6 +752,9 @@ class OnDemandCredentials(
687
752
  self._subject = subject
688
753
  self._token_lifetime = token_lifetime
689
754
  self._quota_project_id = quota_project_id
755
+ self._universe_domain = (
756
+ universe_domain or google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN
757
+ )
690
758
 
691
759
  if additional_claims is None:
692
760
  additional_claims = {}
@@ -712,6 +780,10 @@ class OnDemandCredentials(
712
780
  """
713
781
  kwargs.setdefault("subject", info["client_email"])
714
782
  kwargs.setdefault("issuer", info["client_email"])
783
+ if not kwargs.get("universe_domain"):
784
+ kwargs["universe_domain"] = info.get(
785
+ "universe_domain", google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN
786
+ )
715
787
  return cls(signer, **kwargs)
716
788
 
717
789
  @classmethod
@@ -775,6 +847,12 @@ class OnDemandCredentials(
775
847
  """
776
848
  kwargs.setdefault("issuer", credentials.signer_email)
777
849
  kwargs.setdefault("subject", credentials.signer_email)
850
+ if not kwargs.get("universe_domain"):
851
+ kwargs["universe_domain"] = getattr(
852
+ credentials,
853
+ "universe_domain",
854
+ google.auth.credentials.DEFAULT_UNIVERSE_DOMAIN,
855
+ )
778
856
  return cls(credentials.signer, **kwargs)
779
857
 
780
858
  def with_claims(self, issuer=None, subject=None, additional_claims=None):
@@ -800,8 +878,10 @@ class OnDemandCredentials(
800
878
  issuer=issuer if issuer is not None else self._issuer,
801
879
  subject=subject if subject is not None else self._subject,
802
880
  additional_claims=new_additional_claims,
881
+ token_lifetime=self._token_lifetime,
803
882
  max_cache_size=self._cache.maxsize,
804
883
  quota_project_id=self._quota_project_id,
884
+ universe_domain=self._universe_domain,
805
885
  )
806
886
 
807
887
  @_helpers.copy_docstring(google.auth.credentials.CredentialsWithQuotaProject)
@@ -811,8 +891,24 @@ class OnDemandCredentials(
811
891
  issuer=self._issuer,
812
892
  subject=self._subject,
813
893
  additional_claims=self._additional_claims,
894
+ token_lifetime=self._token_lifetime,
814
895
  max_cache_size=self._cache.maxsize,
815
896
  quota_project_id=quota_project_id,
897
+ universe_domain=self._universe_domain,
898
+ )
899
+
900
+ @_helpers.copy_docstring(google.auth.credentials.CredentialsWithUniverseDomain)
901
+ def with_universe_domain(self, universe_domain):
902
+ _validate_universe_domain(universe_domain)
903
+ return self.__class__(
904
+ self._signer,
905
+ issuer=self._issuer,
906
+ subject=self._subject,
907
+ additional_claims=self._additional_claims,
908
+ token_lifetime=self._token_lifetime,
909
+ max_cache_size=self._cache.maxsize,
910
+ quota_project_id=self._quota_project_id,
911
+ universe_domain=universe_domain,
816
912
  )
817
913
 
818
914
  @property
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "2.62.2"
15
+ __version__ = "2.63.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-auth
3
- Version: 2.62.2
3
+ Version: 2.63.1
4
4
  Summary: Google Authentication Library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-auth
6
6
  Author: Google Cloud Platform
@@ -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()