Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cloudinit/sources/DataSourceEc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class DataSourceEc2(sources.DataSource):
metadata_urls = [
"http://169.254.169.254",
"http://[fd00:ec2::254]",
"http://instance-data.:8773",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ec2 datasource is used by various other clouds besides just ec2 - and unfortunately not all clouds are known, so this change poses a risk.

Copy link
Author

@drzee99 drzee99 Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is confusing. There should be a separate Data Source implementation for each provider. Even if some are same/similar to allow for future changes a cloud provider may implement.

That being said.

It is possible to override the metadata_urls ref: https://cloudinit.readthedocs.io/en/latest/reference/datasources/ec2.html

IMHO the default should be the ones that are provided by the named Data Source (in this case EC2). If this breaks other cloud providers that use the same path, then they should create an config setting for the metadata_url as pr. documentation to add the relevant metadata_urls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be sure that I understand: You are saying that breaking clouds is justified because the code is confusing and there is a workaround that involves manual modifications to the image, right?

Copy link
Author

@drzee99 drzee99 Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DataSource is named DataSourceEC2.py - EC2 is explicitly referring to Amazon Web Services EC2 service (in fact "Amazon EC2" is a registered trademark). Thus it should IMHO adhere to what ever is standard for Amazon EC2 at the current point in time.

It is fair that other clouds have implemented similar things, but they should either have their own data sources OR there should be a generic data source (DataSourceGeneric,py). They should not rely on that Amazon EC2 keeps doing things the same way. What if EC2 changes fundamentally "tomorrow"?

This change in DataSourceEC2.py is not important and I'm happy to back it out.

The important change to resolve the issue is that the check for IP addresses is made earlier in is_resolveable() so we do not unnecessarily go into the "Detect DNS Redirection check" when we don't even have a proper network and just try to query the metadata service (the result from this query is used to setup the network).

]

# The minimum supported metadata_version from the ec2 metadata apis
Expand Down
10 changes: 6 additions & 4 deletions cloudinit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,12 @@ def is_resolvable(url) -> bool:
global _DNS_REDIRECT_IP
parsed_url = parse.urlparse(url)
name = parsed_url.hostname

# Early return for IP addresses - no DNS resolution needed
with suppress(ValueError):
if net.is_ip_address(parsed_url.netloc.strip("[]")):
return True

if _DNS_REDIRECT_IP is None:
badips = set()
badnames = (
Expand All @@ -1319,10 +1325,6 @@ def is_resolvable(url) -> bool:
LOG.debug("detected dns redirection: %s", badresults)

try:
# ip addresses need no resolution
with suppress(ValueError):
if net.is_ip_address(parsed_url.netloc.strip("[]")):
return True
result = socket.getaddrinfo(name, None)
# check first result's sockaddr field
addr = result[0][4][0]
Expand Down