mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-29 15:59:10 +01:00
[management] Fix what a second review found in the credential check
Four defects and two pieces of wording, from cubic's pass over the branch. A provider that asks the proxy to skip TLS verification was checked with a client that verifies it, so a self-hosted endpoint behind a self-signed certificate was refused for the one reason its operator had already declared they accept. Those records now save unchecked, alongside the other cases this cannot speak for. Sending the credential over a connection management declines to verify was the other way out, and a worse one. A key pasted with surrounding whitespace passed its check and then failed every request: the vendor call trims before building the auth header, the synthesiser substitutes the stored value verbatim. The key is now stored in the form it will be sent, so what was checked is what runs. The proxy-guard test resolved api.openai.com for real before reaching its own transport, and on a runner with no egress that lookup failed as an UnreachableError too — so it passed while never exercising the socket guard it is named for. A DNS timeout said only that the lookup failed. It now says so as a timeout, without borrowing the wording of a connection that was never attempted. The create description promised more than the check delivers: for Bedrock the runtime host is resolved but never contacted, so a public host that does not answer is still stored. It says that now, and names the TLS exemption above. The invalid-upstream message no longer quotes the URL back, which was the one path in this feature that echoed what the operator typed. The live suite's single-vendor scope and its dependence on vendor availability are now stated where the tests are, rather than left to be rediscovered.
This commit is contained in:
@@ -195,7 +195,11 @@ func (c *Client) discoveryURL(ctx context.Context, entry catalog.Provider, req R
|
||||
if host == "" {
|
||||
parsed, err := url.Parse(strings.TrimSpace(req.UpstreamURL))
|
||||
if err != nil || parsed.Host == "" {
|
||||
return "", fmt.Errorf("%w: provider upstream %q is not a usable URL", ErrInvalidRequest, req.UpstreamURL)
|
||||
// The URL is left out of the message on purpose: it reaches the
|
||||
// operator through an endpoint that does not lowercase it, but the
|
||||
// rest of this feature's copy never echoes what they typed, and one
|
||||
// path that does is the one that ends up quoted in a bug report.
|
||||
return "", fmt.Errorf("%w: the provider upstream is not a usable URL", ErrInvalidRequest)
|
||||
}
|
||||
host = parsed.Host
|
||||
}
|
||||
@@ -231,7 +235,7 @@ func (c *Client) discoveryURL(ctx context.Context, entry catalog.Provider, req R
|
||||
func (c *Client) checkUpstreamHost(ctx context.Context, entry catalog.Provider, upstreamURL string) error {
|
||||
parsed, err := url.Parse(strings.TrimSpace(upstreamURL))
|
||||
if err != nil || parsed.Hostname() == "" {
|
||||
return fmt.Errorf("%w: provider upstream %q is not a usable URL", ErrInvalidRequest, upstreamURL)
|
||||
return fmt.Errorf("%w: the provider upstream is not a usable URL", ErrInvalidRequest)
|
||||
}
|
||||
return c.classifyHost(ctx, entry, parsed.Hostname())
|
||||
}
|
||||
|
||||
@@ -573,7 +573,12 @@ func TestFetch_AHostThatWillNotResolveIsUnreachable(t *testing.T) {
|
||||
func TestFetch_AProxyInThePathDoesNotSilentlyDisableTheCheck(t *testing.T) {
|
||||
// A transport that refuses at the socket exactly as the guard does, with a
|
||||
// loopback address standing in for the proxy the dial went to.
|
||||
client := &Client{HTTPClient: &http.Client{
|
||||
// AllowPrivateHosts short-circuits the resolve-stage check only; the
|
||||
// injected transport below is still what the request goes through. Without
|
||||
// it this test resolves api.openai.com for real, and on a runner with no
|
||||
// egress that lookup fails as an UnreachableError too — so it would pass
|
||||
// while never reaching the socket guard it is named for.
|
||||
client := &Client{AllowPrivateHosts: true, HTTPClient: &http.Client{
|
||||
Transport: roundTripFunc(func(*http.Request) (*http.Response, error) {
|
||||
return nil, guardDialAddress("127.0.0.1:38599")
|
||||
}),
|
||||
|
||||
@@ -53,6 +53,13 @@ func (e *UnreachableError) Reason() string {
|
||||
if dns.IsNotFound {
|
||||
return "no such host"
|
||||
}
|
||||
// Named apart from the dial timeout below. A resolver that never
|
||||
// answered and an upstream that never answered send an operator to
|
||||
// different places, and the generic "connection timed out" would
|
||||
// describe a connection that was never attempted.
|
||||
if dns.IsTimeout {
|
||||
return "dns lookup timed out"
|
||||
}
|
||||
return "dns lookup failed"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user