fix: Remove content-type header from IDMS GET requests by peter-volkov · Pull Request #1489 · googleapis/google-auth-library-python

@peter-volkov requested review from a team

March 5, 2024 12:43

@peter-volkov @pv-aiuta-com

@peter-volkov peter-volkov changed the title Remove content-type header from IDMS GET requests fix: Remove content-type header from IDMS GET requests

Mar 5, 2024

@parthea parthea added the do not merge

Indicates a pull request not ready for merge, due to either quality or timing.

label

Mar 5, 2024

BigTailWolf

@BigTailWolf

@BigTailWolf

@chalmerlowe

chalmerlowe added a commit that referenced this pull request

Jan 14, 2026
When performing a IMDS request, the code incorrectly adds a content-type
header to the request:

`content-type: application/json` to AWS metadata (IMDS) GET requests.`

Some services at AWS (such as AWS SageMaker Jupyter notebook) have a
stricter than normal metadata server (IMDS, both v1 and v2) when it
comes to handling incoming http requests.

This PR removes the default content-header and replaces it with `None`.

NOTE: initializing headers to `None` (instead of an empty `dict`) when
no session token is present matches the existing behavior in
`_get_metadata_role_name` and allows the transport adapter to handle
default headers cleanly.

This PR updates existing unit tests (`tests/test_aws.py`) to match the
new behavior.

NOTE: closing PR #1489 due to inactivity as we make the push to migrate
this library to the `google-cloud-python` monorepo

For more information about the genesis of this, see the following issue:
https://issuetracker.google.com/issues/328089077