mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-24 22:39:09 +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:
@@ -242,10 +242,16 @@ func (m *Middleware) routeModelless(reqPath, surface, method string, userGroups
|
||||
if _, hadPrefix := splitBedrockNamespace(reqPath); hadPrefix {
|
||||
stripBedrockNamespace(out)
|
||||
}
|
||||
// What the caller may actually use bounds what the picker may offer:
|
||||
// every entry outside it is a request the chain will deny a moment
|
||||
// later.
|
||||
if reqPath == modelListingPath && out.Mutations != nil && out.Mutations.RewriteUpstream != nil {
|
||||
if isListingPath(reqPath) && out.Mutations != nil && out.Mutations.RewriteUpstream != nil {
|
||||
// A vendor that serves its listing from somewhere other than its
|
||||
// inference upstream is redirected here, and only for the listing
|
||||
// — every other request still goes to the configured upstream.
|
||||
if route.DiscoveryHost != "" {
|
||||
out.Mutations.RewriteUpstream.Host = route.DiscoveryHost
|
||||
}
|
||||
// What the caller may actually use bounds what the picker may
|
||||
// offer: every entry outside it is a request the chain will deny a
|
||||
// moment later.
|
||||
if models, bounded := discoverableModels(route, userGroups); bounded {
|
||||
out.Mutations.RewriteUpstream.DiscoveryModels = models
|
||||
}
|
||||
@@ -310,6 +316,20 @@ func discoverableModels(route ProviderRoute, userGroups []string) ([]string, boo
|
||||
for _, m := range route.Models {
|
||||
if _, ok := permitted[m]; ok {
|
||||
intersection[m] = struct{}{}
|
||||
continue
|
||||
}
|
||||
// The two sides are not always written the same way. A Bedrock record
|
||||
// may register the raw inference-profile id an operator copied from
|
||||
// AWS while a guardrail allowlist names the catalog key, and comparing
|
||||
// those verbatim finds nothing — which would bound a correctly
|
||||
// configured provider's listing down to empty. routeClaimsModel
|
||||
// already normalises the candidate for exactly this reason, and the
|
||||
// listing bound has to agree with it or the picker disagrees with what
|
||||
// the guardrail will actually allow.
|
||||
if route.Bedrock {
|
||||
if _, ok := permitted[llm.NormalizeBedrockModel(m)]; ok {
|
||||
intersection[m] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sortedModels(intersection), true
|
||||
@@ -472,6 +492,14 @@ const connectionWarmPath = "/api/hello"
|
||||
// alone.
|
||||
const modelListingPath = "/v1/models"
|
||||
|
||||
// isListingPath reports whether reqPath asks for a MODEL LISTING, as opposed
|
||||
// to the other model-less endpoints. Only a listing gets an upstream redirect
|
||||
// and a policy bound: the connection-warming probe carries no model list to
|
||||
// filter, and rewriting its host would send the warm-up to the wrong pool.
|
||||
func isListingPath(reqPath string) bool {
|
||||
return reqPath == modelListingPath || isBedrockModelLessPath(reqPath)
|
||||
}
|
||||
|
||||
// isModelLessPath reports whether reqPath is a known non-inference endpoint
|
||||
// that legitimately carries no model at all: the model listing and the
|
||||
// connection-warming probe. These must route to an upstream rather than
|
||||
|
||||
Reference in New Issue
Block a user