mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-21 06:09:07 +02:00
[proxy,management] Serve Bedrock model discovery from the control plane
A Bedrock provider could never answer a discovery request. The router
routed GET /inference-profiles to the record's upstream, which has to be
bedrock-runtime.<region> for InvokeModel to work, and that host does not
implement the operation — AWS answers <UnknownOperationException/>.
ListInferenceProfiles lives on the control plane at bedrock.<region>.
Give the route a discovery host, taken from the catalog's declaration
with the region read back out of the configured upstream, and send the
listing — and only the listing — there. Inference is untouched, and a
proxied or self-hosted Bedrock endpoint gets no discovery host at all
rather than a guessed one, since inventing a host would send the
operator's credential somewhere they never configured.
Two things had to follow for the listing to be usable once it arrives.
The response filter only understood OpenAI's {data:[{id:…}]}, so a
Bedrock listing was forwarded whole — offering every profile in the
account whatever the policy said. It now recognises the
inferenceProfileSummaries envelope, and matches a listing id against the
record's models after stripping the region prefix and version suffix, so
the two spellings of one model line up.
The policy bound had the same problem from the other side: it intersected
by exact string, so a record registering the raw profile id while a
guardrail names the catalog key intersected to nothing and would have
bounded a working provider's listing down to empty. routeClaimsModel
already normalises the candidate for this reason; the bound now agrees
with it.
The live discovery e2e flips from asserting the 404 to asserting a real
filtered listing. The mock upstream cannot cover any of this: it answers
/inference-profiles on the same listener as everything else, so a
mock-based test passes whichever host the request went to.
This commit is contained in:
@@ -171,7 +171,7 @@ func (c *Client) discoveryURL(entry catalog.Provider, req Request) (string, erro
|
||||
// A provider record carries no region field: the region lives
|
||||
// inside the upstream host the operator already configured, so
|
||||
// read it back out rather than asking them for it twice.
|
||||
region = regionFromUpstream(entry, req.UpstreamURL)
|
||||
region = RegionFromUpstream(entry, req.UpstreamURL)
|
||||
}
|
||||
if region == "" {
|
||||
return "", fmt.Errorf("%s discovery needs a region, and none could be read from the provider upstream", entry.Name)
|
||||
@@ -186,13 +186,13 @@ func (c *Client) discoveryURL(entry catalog.Provider, req Request) (string, erro
|
||||
return target.String(), nil
|
||||
}
|
||||
|
||||
// regionFromUpstream recovers the region an operator embedded in the provider
|
||||
// RegionFromUpstream recovers the region an operator embedded in the provider
|
||||
// upstream, by matching it against the catalog's own host template. Bedrock's
|
||||
// template is "bedrock-runtime.<region>.amazonaws.com" and Vertex's is
|
||||
// "<region>-aiplatform.googleapis.com", so the region is whatever sits between
|
||||
// the fixed halves. Returns empty when the upstream does not match the
|
||||
// template, which is the case for a custom or proxied endpoint.
|
||||
func regionFromUpstream(entry catalog.Provider, upstreamURL string) string {
|
||||
func RegionFromUpstream(entry catalog.Provider, upstreamURL string) string {
|
||||
prefix, suffix, found := strings.Cut(entry.DefaultHost, catalog.RegionPlaceholder)
|
||||
if !found {
|
||||
return ""
|
||||
|
||||
@@ -315,7 +315,7 @@ func TestRegionFromUpstream(t *testing.T) {
|
||||
{"vertex global host has no region segment", vertex, "https://aiplatform.googleapis.com", ""},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert.Equal(t, tc.want, regionFromUpstream(tc.entry, tc.upstream))
|
||||
assert.Equal(t, tc.want, RegionFromUpstream(tc.entry, tc.upstream))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/netbirdio/netbird/management/internals/modules/agentnetwork/catalog"
|
||||
"github.com/netbirdio/netbird/management/internals/modules/agentnetwork/modeldiscovery"
|
||||
"github.com/netbirdio/netbird/management/internals/modules/agentnetwork/types"
|
||||
rpservice "github.com/netbirdio/netbird/management/internals/modules/reverseproxy/service"
|
||||
"github.com/netbirdio/netbird/management/internals/modules/reverseproxy/sessionkey"
|
||||
@@ -380,6 +381,9 @@ type routerProviderRoute struct {
|
||||
// proxy dials this provider's upstream. For self-hosted / internal gateways
|
||||
// behind a private or self-signed certificate.
|
||||
SkipTLSVerify bool `json:"skip_tls_verify,omitempty"`
|
||||
// DiscoveryHost, when set, is the host serving this provider's model
|
||||
// listing, for a vendor that does not serve it from the inference host.
|
||||
DiscoveryHost string `json:"discovery_host,omitempty"`
|
||||
}
|
||||
|
||||
// indexProviderGroups walks the enabled policies and returns, per
|
||||
@@ -447,6 +451,9 @@ func buildRouterConfigJSON(providers []*types.Provider, groupIndex map[string][]
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("router config for provider %s: %w", p.ID, err)
|
||||
}
|
||||
// Lookup rather than assume: an unknown provider id yields the zero
|
||||
// entry, which declares no discovery and so contributes nothing.
|
||||
catalogEntry, _ := catalog.Lookup(p.ProviderID)
|
||||
headerName, headerValue, gcpSAKeyB64, err := providerAuthHeader(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -466,6 +473,7 @@ func buildRouterConfigJSON(providers []*types.Provider, groupIndex map[string][]
|
||||
Bedrock: catalog.IsBedrockPathStyle(p.ProviderID),
|
||||
GCPServiceAccountKeyB64: gcpSAKeyB64,
|
||||
SkipTLSVerify: p.SkipTLSVerification,
|
||||
DiscoveryHost: discoveryHost(catalogEntry, p.UpstreamURL),
|
||||
})
|
||||
}
|
||||
out, err := json.Marshal(cfg)
|
||||
@@ -475,6 +483,33 @@ func buildRouterConfigJSON(providers []*types.Provider, groupIndex map[string][]
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// discoveryHost returns the host serving this provider's model listing when it
|
||||
// differs from the inference host, and empty when the two are the same — which
|
||||
// is true of every vendor but Bedrock, whose ListInferenceProfiles is a control
|
||||
// plane operation on bedrock.<region> while InvokeModel must go to
|
||||
// bedrock-runtime.<region>. One provider record therefore needs two hosts.
|
||||
//
|
||||
// The catalog declares the listing host; the region is recovered from the
|
||||
// upstream the operator configured, since a provider record carries no region
|
||||
// field. An upstream matching no catalog template yields empty rather than a
|
||||
// guess: a proxied or self-hosted Bedrock endpoint may serve both from one
|
||||
// place, and inventing a host would send the credential somewhere the operator
|
||||
// never configured.
|
||||
func discoveryHost(entry catalog.Provider, upstreamURL string) string {
|
||||
if entry.Discovery == nil || entry.Discovery.Host == "" {
|
||||
return ""
|
||||
}
|
||||
host := entry.Discovery.Host
|
||||
if !strings.Contains(host, catalog.RegionPlaceholder) {
|
||||
return host
|
||||
}
|
||||
region := modeldiscovery.RegionFromUpstream(entry, upstreamURL)
|
||||
if region == "" {
|
||||
return ""
|
||||
}
|
||||
return strings.ReplaceAll(host, catalog.RegionPlaceholder, region)
|
||||
}
|
||||
|
||||
// providerVendor returns the parser surface ("openai", "anthropic", …)
|
||||
// the provider speaks, sourced from its catalog entry's ParserID. The
|
||||
// router uses it to keep a request the parser tagged with a vendor on a
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/netbirdio/netbird/management/internals/modules/agentnetwork/catalog"
|
||||
"github.com/netbirdio/netbird/management/internals/modules/agentnetwork/types"
|
||||
rpservice "github.com/netbirdio/netbird/management/internals/modules/reverseproxy/service"
|
||||
"github.com/netbirdio/netbird/management/server/store"
|
||||
@@ -1245,3 +1246,57 @@ func TestSynthesizeServices_EmptyAPIKey_FailsClosed(t *testing.T) {
|
||||
require.Error(t, err, "synthesis must refuse a provider with no api key")
|
||||
assert.Contains(t, err.Error(), "no api key", "error must surface the missing credential")
|
||||
}
|
||||
|
||||
// TestDiscoveryHost pins which providers get a separate listing host. Getting
|
||||
// this wrong in either direction is costly: a missing host leaves Bedrock
|
||||
// discovery 404ing at AWS, and a host on the wrong provider would send that
|
||||
// provider's listing — and its credential — somewhere the operator never
|
||||
// configured.
|
||||
func TestDiscoveryHost(t *testing.T) {
|
||||
entry := func(id string) catalog.Provider {
|
||||
p, ok := catalog.Lookup(id)
|
||||
require.True(t, ok, "catalog entry %s must exist", id)
|
||||
return p
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
entry catalog.Provider
|
||||
upstream string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
// ListInferenceProfiles is a control-plane operation; the runtime
|
||||
// host answers <UnknownOperationException/> for it.
|
||||
name: "bedrock splits the listing off the runtime host",
|
||||
entry: entry("bedrock_api"), upstream: "https://bedrock-runtime.eu-central-1.amazonaws.com",
|
||||
want: "bedrock.eu-central-1.amazonaws.com",
|
||||
},
|
||||
{
|
||||
name: "bedrock in another region",
|
||||
entry: entry("bedrock_api"), upstream: "https://bedrock-runtime.us-west-2.amazonaws.com",
|
||||
want: "bedrock.us-west-2.amazonaws.com",
|
||||
},
|
||||
{
|
||||
// A proxied Bedrock endpoint may well serve both from one place,
|
||||
// and there is no region to read back out of it.
|
||||
name: "proxied bedrock upstream yields no discovery host",
|
||||
entry: entry("bedrock_api"), upstream: "https://bedrock.internal.example.com",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "openai serves its listing from the same host",
|
||||
entry: entry("openai_api"), upstream: "https://api.openai.com",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "vertex serves its listing from the same host",
|
||||
entry: entry("vertex_ai_api"), upstream: "https://us-east5-aiplatform.googleapis.com",
|
||||
want: "",
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert.Equal(t, tc.want, discoveryHost(tc.entry, tc.upstream))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user