Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registry: isCIDRMatch: avoid performing DNS lookups if not needed #48999

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

thaJeztah
Copy link
Member

A colleague found that isCIDRMatch (called indirectly through ParseRepositoryInfo), is performing DNS lookups. These lookups are related to it assuming is being run as part of the docker engine, and has to check whether the registry is marked as "insecure" in daemon config.

A consequence of this was that tests were slow as they were using foo.example.com (and similar) domains.

This is a first set of changes to avoid performing DNS lookups; the core problem lies in newRegistryInfo (which is called as part of the above) always tries to propagate all information, including whether the registry is marked "secure". This information is not used in any way for getting the key to use for storing auth, but requires some additional changes to remove (which I'll do in follow-ups);

moby/registry/config.go

Lines 386 to 405 in 321f9c2

func newIndexInfo(config *serviceConfig, indexName string) (*registry.IndexInfo, error) {
var err error
indexName, err = ValidateIndexName(indexName)
if err != nil {
return nil, err
}
// Return any configured index info, first.
if index, ok := config.IndexConfigs[indexName]; ok {
return index, nil
}
// Construct a non-configured index info.
return &registry.IndexInfo{
Name: indexName,
Mirrors: make([]string, 0),
Secure: config.isSecureIndex(indexName),
Official: false,
}, nil
}

@thaJeztah thaJeztah added this to the 28.0.0 milestone Nov 29, 2024
@thaJeztah thaJeztah self-assigned this Nov 29, 2024
@thaJeztah
Copy link
Member Author

Failure is unrelated; will be fixed by;

Skip all code if there's nothing to match against.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
isCIDRMatch defaulted to trying to resolve a hostname to get its
IP-address(es) before trying if the given host was an IP address
already.

Let's reverse the order so that we can avoid performing a DNS lookup
when it's not needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
registry/config.go Outdated Show resolved Hide resolved
registry/config.go Outdated Show resolved Hide resolved
Comment on lines -38 to -41
if host == "127.0.0.1" {
// I believe in future Go versions this will fail, so let's fix it later
return net.LookupIP(host)
}
Copy link
Member Author

@thaJeztah thaJeztah Dec 2, 2024

Choose a reason for hiding this comment

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

As we're now skipping lookupIP if it's an IP address, this case can be removed; let me update

@thaJeztah
Copy link
Member Author

This one's really flaky recently;

=== FAIL: amd64.integration.container TestWaitRestartedContainer/not-running (5.76s)
    wait_test.go:232: assertion failed: 5 (expectedCode int64) != 137 (waitRes.StatusCode int64)
    --- FAIL: TestWaitRestartedContainer/not-running (5.76s)

Comment on lines +292 to +294
if len(cidrs) == 0 {
return false
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Sadly this currently doesn't help, as we're unconditionally initialising RepoInfo with localhost CIDRs; while that's relevant for some uses of RepoInfo, it's not for others, and I'll look for follow-ups to split those use-cases.

Copy link
Contributor

@robmry robmry left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah requested a review from vvoland December 2, 2024 14:49
@thaJeztah thaJeztah merged commit 612b853 into moby:master Dec 3, 2024
140 checks passed
@thaJeztah thaJeztah deleted the no_dnslookup branch December 3, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants