[management,proxy] Add agentgateway integration (#7274)

* [management] Add agentgateway provider catalog entry

Allow Agent Network providers to target an operator-supplied agentgateway proxy while stamping trusted NetBird identity headers.

Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>

* [proxy] Allow trusted Agent Network identity headers

Permit only the built-in identity injector to replace the two reserved agentgateway attribution headers while keeping them blocked for every other middleware.

Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>

* [management,proxy] Add multi-vendor gateway routing

Let one Agent Network route declare multiple parser surfaces while preserving the existing singular vendor wire field.

Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>

* [management] Update router test for model policies

Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>

* [proxy] Cover reserved header policy

Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>

* [management] Add agentgateway model discovery

Use agentgateway's OpenAI-compatible models endpoint and omit wildcard patterns until NetBird can authorize and price them consistently.

Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>

---------

Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>
This commit is contained in:
Daneyon Hansen
2026-09-01 04:03:16 -07:00
committed by GitHub
parent 4749005a50
commit 7a9582db16
13 changed files with 372 additions and 24 deletions

View File

@@ -36,7 +36,10 @@ type ProviderRoute struct {
// request on a same-vendor route so catch-all gateways of a different
// vendor can't swallow it. Empty disables vendor filtering for this
// route.
Vendor string `json:"vendor,omitempty"`
Vendor string `json:"vendor,omitempty"`
// Vendors lists every parser surface a multi-surface gateway accepts.
// Vendor remains supported for existing single-surface configurations.
Vendors []string `json:"vendors,omitempty"`
Models []string `json:"models"`
UpstreamScheme string `json:"upstream_scheme"`
UpstreamHost string `json:"upstream_host"`

View File

@@ -409,7 +409,7 @@ func stripBedrockNamespace(out *middleware.Output) {
// peer, return matchOutcomeUnauthorised so the caller can emit
// the dedicated no_authorised_provider deny code.
// 3. Vendor precedence: when the request carries a detected vendor
// (llm.provider) and at least one candidate is the same vendor,
// (llm.provider) and at least one candidate declares that vendor,
// drop the rest — a vendor-tagged request must never cross to
// another vendor's route (e.g. an Anthropic call landing on an
// OpenAI-compatible gateway that also claims the model).
@@ -432,9 +432,9 @@ func (m *Middleware) matchRoute(model, vendor, reqPath string, userGroups []stri
// Vendor pinning runs BEFORE the group filter so a request the parser
// tagged with a vendor can never cross to another vendor's route — not
// even an authorised one. Narrow to same-vendor routes when any
// model-matched route declares that vendor; setups with no vendor tag on
// any route fall through unchanged. After narrowing, if no same-vendor
// even an authorised one. Narrow to supporting routes when any
// model-matched route declares that vendor; setups with no matching vendor
// declaration fall through unchanged. After narrowing, if no supporting
// route authorises the caller, that's matchOutcomeUnauthorised (no
// cross-vendor fallback).
if vendor != "" {
@@ -805,21 +805,31 @@ func authorisingGroupsCSV(routeGroups, userGroups []string) string {
return strings.Join(out, ",")
}
// matchingVendor returns the subset of routes whose Vendor equals the
// request's detected vendor. Routes with an empty Vendor never match — an
// untagged route can't be asserted to speak the request's surface, so it
// stays out of the vendor-filtered set (but remains eligible via the
// fall-through when no route matches the vendor at all).
// matchingVendor returns the routes that declare the request's detected
// vendor through either the legacy singular field or the multi-vendor field.
// Untagged routes remain eligible only when no route declares the vendor.
func matchingVendor(routes []ProviderRoute, vendor string) []ProviderRoute {
var out []ProviderRoute
for _, r := range routes {
if r.Vendor == vendor {
if routeSupportsVendor(r, vendor) {
out = append(out, r)
}
}
return out
}
func routeSupportsVendor(route ProviderRoute, vendor string) bool {
if route.Vendor == vendor {
return true
}
for _, candidate := range route.Vendors {
if candidate == vendor {
return true
}
}
return false
}
// explicitlyClaiming returns the subset of routes whose Models list
// names the model exactly. Catch-all routes (empty Models) are excluded,
// so callers can prefer a provider that genuinely declares the model over

View File

@@ -412,6 +412,50 @@ func TestRouter_VendorKeepsOpenAIOffAnthropic(t *testing.T) {
assert.Equal(t, "api.openai.com", out.Mutations.RewriteUpstream.Host, "openai vendor must pin to the openai route despite anthropic being declared first")
}
func TestRouter_MultiVendorGatewayAcceptsBothSurfaces(t *testing.T) {
gateway := ProviderRoute{
ID: "agentgateway",
Vendors: []string{"openai", "anthropic"},
Models: nil,
AllowedGroupIDs: []string{defaultTestGroup},
UpstreamScheme: "https",
UpstreamHost: "gateway.example.com",
}
other := ProviderRoute{
ID: "other-vendor",
Vendor: "mistral",
Models: nil,
AllowedGroupIDs: []string{defaultTestGroup},
UpstreamScheme: "https",
UpstreamHost: "mistral.example.com",
}
mw := New(Config{Providers: []ProviderRoute{other, gateway}})
for _, tc := range []struct {
name string
vendor string
model string
path string
}{
{name: "OpenAI", vendor: "openai", model: "gpt-4o-mini", path: "/v1/chat/completions"},
{name: "Anthropic", vendor: "anthropic", model: "claude-sonnet-4-5", path: "/v1/messages"},
} {
t.Run(tc.name, func(t *testing.T) {
out, err := mw.Invoke(context.Background(), newInputVendorModelURL(tc.vendor, tc.model, tc.path))
require.NoError(t, err)
require.NotNil(t, out)
assert.Equal(t, middleware.DecisionAllow, out.Decision,
"supported vendor must route through the multi-surface gateway")
require.NotNil(t, out.Mutations)
require.NotNil(t, out.Mutations.RewriteUpstream)
assert.Equal(t, "gateway.example.com", out.Mutations.RewriteUpstream.Host)
provider, _ := metaValue(t, out.Metadata, middleware.KeyLLMResolvedProviderID)
assert.Equal(t, "agentgateway", provider)
})
}
}
// TestRouter_VendorAbsentFallsBackToModelPath confirms vendor filtering is
// inert when the request carries no detected vendor: routing then relies on
// model/path as before.
@@ -692,6 +736,23 @@ func TestRouter_FactoryRejectsBadJSON(t *testing.T) {
require.Error(t, err, "malformed JSON config must be rejected at chain build time")
}
func TestRouter_FactoryDecodesLegacyAndMultiVendorFields(t *testing.T) {
raw := []byte(`{"providers":[` +
`{"id":"legacy","vendor":"openai","models":[],"upstream_scheme":"https","upstream_host":"openai.example.com","auth_header_name":"Authorization","auth_header_value":"Bearer legacy","allowed_group_ids":["group"]},` +
`{"id":"multi","vendors":["openai","anthropic"],"models":[],"upstream_scheme":"https","upstream_host":"gateway.example.com","auth_header_name":"Authorization","auth_header_value":"Bearer multi","allowed_group_ids":["group"]}` +
`]}`)
resolved, err := Factory{}.New(raw)
require.NoError(t, err)
router, ok := resolved.(*Middleware)
require.True(t, ok, "factory must return the concrete router middleware")
require.Len(t, router.cfg.Providers, 2)
assert.Equal(t, "openai", router.cfg.Providers[0].Vendor,
"the legacy singular field must keep decoding")
assert.Equal(t, []string{"openai", "anthropic"}, router.cfg.Providers[1].Vendors,
"the multi-vendor field must decode both supported surfaces")
}
func TestRouter_FactoryAcceptsEmptyShapes(t *testing.T) {
cases := [][]byte{nil, []byte(""), []byte(" "), []byte("null"), []byte("{}"), []byte("[]")}
for _, raw := range cases {