Skip to content

Allow setting metadata environment variable GCE_METADATA_HOST alone #15180

@salrashid123

Description

@salrashid123

If users want to set a custom metadata server endpoint, you have to use both

GCE_METADATA_IP and GCE_METADATA_HOST.

The IP based env var is used here to ping the address of the server.

Using GCE_METADATA_IP seems to be unique to google-auth-python while other gcp sdk libraries allows you to override with just GCE_METADATA_HOST.

The usecase is if anyone wants to run a custom endpoint or local metadata emulator you'd have to know this specific environment variable just for python.


The suggestion is if a user set GCE_METADATA_HOST, just use whats there.

For backwards compatibility, if the user sets both GCE_METADATA_HOST and GCE_METADATA_IP, the behavior is the same as now.

i think one simplistic way to get to that is to alter _metadata.py as such

if os.getenv(environment_vars.GCE_METADATA_HOST, None) is not None and os.getenv(environment_vars.GCE_METADATA_IP,None) is None:
    _METADATA_IP_ROOT = "http://{}".format(_GCE_METADATA_HOST)
else:
    _METADATA_IP_ROOT = "http://{}".format(
        os.getenv(environment_vars.GCE_METADATA_IP, "169.254.169.254")
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions