5555def _validate_gce_mds_configured_environment ():
5656 """Validates the GCE metadata server environment configuration for mTLS.
5757
58+ mTLS is only supported when connecting to the default metadata host.
59+ If we are in strict mode (which requires mTLS), ensure that the metadata host
60+ has not been overridden (which means mTLS will fail).
61+
5862 Raises:
5963 google.auth.exceptions.MutualTLSChannelError: if the environment
6064 configuration is invalid for mTLS.
@@ -236,7 +240,8 @@ def get(
236240 HTTP requests.
237241 path (str): The resource to retrieve. For example,
238242 ``'instance/service-accounts/default'``.
239- root (str): The full path to the metadata server root.
243+ root (Optional[str]): The full path to the metadata server root. If not
244+ provided, the default root will be used.
240245 params (Optional[Mapping[str, str]]): A mapping of query parameter
241246 keys to values.
242247 recursive (bool): Whether to do a recursive query of metadata. See
@@ -257,6 +262,10 @@ def get(
257262 Raises:
258263 google.auth.exceptions.TransportError: if an error occurred while
259264 retrieving metadata.
265+ google.auth.exceptions.MutualTLSChannelError: if the environment
266+ configuration is invalid for mTLS (for example, the metadata host
267+ has been overridden in strict mTLS mode).
268+
260269 """
261270 use_mtls = _mtls .should_use_mds_mtls ()
262271 # Prepare the request object for mTLS if needed.
@@ -265,6 +274,10 @@ def get(
265274
266275 if root is None :
267276 root = _get_metadata_root (use_mtls )
277+
278+ # mTLS is only supported when connecting to the default metadata host.
279+ # If we are in strict mode (which requires mTLS), ensure that the metadata host
280+ # has not been overridden (which means mTLS will fail).
268281 _validate_gce_mds_configured_environment ()
269282
270283 base_url = urljoin (root , path )
0 commit comments