Skip to content

Commit e611c05

Browse files
committed
Adding more agw backend tests and return errors as part of status
Signed-off-by: Markus Kobler <[email protected]>
1 parent bbb7330 commit e611c05

23 files changed

+764
-77
lines changed

pkg/agentgateway/plugins/backend_policies.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ func translateBackendPolicyToAgw(
9393
}
9494

9595
if backend.MCP.Authentication != nil {
96-
pol := translateBackendMCPAuthentication(ctx, policy, policyTarget)
96+
pol, err := translateBackendMCPAuthentication(ctx, policy, policyTarget)
97+
if err != nil {
98+
logger.Error("error processing backend mcp auth", "err", err)
99+
errs = append(errs, err)
100+
}
97101
agwPolicies = append(agwPolicies, pol...)
98102
}
99103
}
@@ -283,14 +287,14 @@ func translateBackendMCPAuthorization(policy *agentgateway.AgentgatewayPolicy, t
283287
return []AgwPolicy{{Policy: mcpPolicy}}
284288
}
285289

286-
func translateBackendMCPAuthentication(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, target *api.PolicyTarget) []AgwPolicy {
290+
func translateBackendMCPAuthentication(ctx PolicyCtx, policy *agentgateway.AgentgatewayPolicy, target *api.PolicyTarget) ([]AgwPolicy, error) {
287291
backend := policy.Spec.Backend
288292
if backend == nil || backend.MCP == nil || backend.MCP.Authentication == nil {
289-
return nil
293+
return nil, nil
290294
}
291295
authnPolicy := backend.MCP.Authentication
292296
if authnPolicy == nil {
293-
return nil
297+
return nil, nil
294298
}
295299

296300
idp := api.BackendPolicySpec_McpAuthentication_AUTH0
@@ -301,9 +305,10 @@ func translateBackendMCPAuthentication(ctx PolicyCtx, policy *agentgateway.Agent
301305
translatedInlineJwks, err := resolveRemoteJWKSInline(ctx, authnPolicy.JWKS.JwksUri)
302306
if err != nil {
303307
logger.Error("failed resolving jwks", "jwks_uri", authnPolicy.JWKS.JwksUri, "error", err)
304-
return nil
308+
return nil, err
305309
}
306310

311+
var errs []error
307312
var extraResourceMetadata map[string]*structpb.Value
308313
for k, v := range authnPolicy.ResourceMetadata {
309314
if extraResourceMetadata == nil {
@@ -313,6 +318,7 @@ func translateBackendMCPAuthentication(ctx PolicyCtx, policy *agentgateway.Agent
313318
pbVal, err := structpb.NewValue(v)
314319
if err != nil {
315320
logger.Error("error converting resource metadata", "key", k, "error", err)
321+
errs = append(errs, err)
316322
continue
317323
}
318324

@@ -345,7 +351,7 @@ func translateBackendMCPAuthentication(ctx PolicyCtx, policy *agentgateway.Agent
345351
"policy", policy.Name,
346352
"agentgateway_policy", mcpAuthnPolicy.Name)
347353

348-
return []AgwPolicy{{Policy: mcpAuthnPolicy}}
354+
return []AgwPolicy{{Policy: mcpAuthnPolicy}}, errors.Join(errs...)
349355
}
350356

351357
// translateBackendAI processes AI configuration and creates corresponding Agw policies
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: agentgateway.dev/v1alpha1
2+
kind: AgentgatewayBackend
3+
metadata:
4+
namespace: default
5+
name: openai-backend
6+
spec:
7+
ai:
8+
provider:
9+
openai:
10+
model: gpt-4
11+
policies:
12+
auth:
13+
secretRef:
14+
name: missing-secret
15+
---
16+
# Output
17+
output: []
18+
status:
19+
conditions:
20+
- lastTransitionTime: fake
21+
message: failed to translate backend secret default/missing-secret not found
22+
reason: TranslationError
23+
status: "False"
24+
type: Accepted

pkg/kgateway/agentgatewaysyncer/backend/testdata/backend/backend-secret.yaml renamed to pkg/kgateway/agentgatewaysyncer/backend/testdata/backend/ai-auth-secret-ref.yaml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apiVersion: agentgateway.dev/v1alpha1
22
kind: AgentgatewayBackend
33
metadata:
4-
name: anthropic-backend
54
namespace: default
5+
name: anthropic-backend
66
spec:
77
ai:
88
provider:
@@ -23,25 +23,21 @@ data:
2323
---
2424
# Output
2525
output:
26-
- gateway:
27-
Name: ""
28-
Namespace: ""
29-
resource:
30-
backend:
31-
ai:
32-
providerGroups:
33-
- providers:
34-
- anthropic:
35-
model: claude-4-5-sonnet
36-
name: backend
37-
inlinePolicies:
38-
- auth:
39-
key:
40-
secret: test
41-
key: default/anthropic-backend
42-
name:
43-
name: anthropic-backend
44-
namespace: default
26+
- backend:
27+
ai:
28+
providerGroups:
29+
- providers:
30+
- anthropic:
31+
model: claude-4-5-sonnet
32+
name: backend
33+
inlinePolicies:
34+
- auth:
35+
key:
36+
secret: test
37+
key: default/anthropic-backend
38+
name:
39+
name: anthropic-backend
40+
namespace: default
4541
status:
4642
conditions:
4743
- lastTransitionTime: fake
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
apiVersion: agentgateway.dev/v1alpha1
2+
kind: AgentgatewayBackend
3+
metadata:
4+
namespace: default
5+
name: ai-priority-with-secret
6+
spec:
7+
ai:
8+
groups:
9+
- providers:
10+
- name: openai-secure
11+
openai:
12+
model: gpt-4o
13+
policies:
14+
auth:
15+
secretRef:
16+
name: openai-secret
17+
- name: anthropic-secure
18+
anthropic:
19+
model: claude-3-5-sonnet
20+
policies:
21+
auth:
22+
secretRef:
23+
name: anthropic-secret
24+
---
25+
apiVersion: v1
26+
kind: Secret
27+
metadata:
28+
name: openai-secret
29+
namespace: default
30+
data:
31+
Authorization: QmVhcmVyIHRlc3Q=
32+
---
33+
apiVersion: v1
34+
kind: Secret
35+
metadata:
36+
name: anthropic-secret
37+
namespace: default
38+
data:
39+
Authorization: QmVhcmVyIHRlc3Q=
40+
---
41+
# Output
42+
output:
43+
- backend:
44+
ai:
45+
providerGroups:
46+
- providers:
47+
- inlinePolicies:
48+
- auth:
49+
key:
50+
secret: test
51+
name: openai-secure
52+
openai:
53+
model: gpt-4o
54+
- anthropic:
55+
model: claude-3-5-sonnet
56+
inlinePolicies:
57+
- auth:
58+
key:
59+
secret: test
60+
name: anthropic-secure
61+
key: default/ai-priority-with-secret
62+
name:
63+
name: ai-priority-with-secret
64+
namespace: default
65+
status:
66+
conditions:
67+
- lastTransitionTime: fake
68+
message: Backend successfully accepted
69+
reason: Accepted
70+
status: "True"
71+
type: Accepted
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
apiVersion: agentgateway.dev/v1alpha1
2+
kind: AgentgatewayBackend
3+
metadata:
4+
namespace: default
5+
name: multi-providers
6+
spec:
7+
ai:
8+
groups:
9+
- providers:
10+
- name: openai
11+
openai:
12+
model: gpt-4o
13+
- name: anthropic
14+
anthropic:
15+
model: claude-3-5-sonnet
16+
- name: gemini
17+
gemini:
18+
model: gemini-1.5-pro
19+
- name: vertex
20+
vertexai:
21+
model: gemini-pro
22+
region: us-west1
23+
projectId: my-gcp-project
24+
- name: bedrock
25+
bedrock:
26+
model: anthropic.claude-3-sonnet-20240229-v1:0
27+
region: us-east-1
28+
---
29+
# Output
30+
output:
31+
- backend:
32+
ai:
33+
providerGroups:
34+
- providers:
35+
- name: openai
36+
openai:
37+
model: gpt-4o
38+
- anthropic:
39+
model: claude-3-5-sonnet
40+
name: anthropic
41+
- gemini:
42+
model: gemini-1.5-pro
43+
name: gemini
44+
- name: vertex
45+
vertex:
46+
model: gemini-pro
47+
projectId: my-gcp-project
48+
region: us-west1
49+
- bedrock:
50+
model: anthropic.claude-3-sonnet-20240229-v1:0
51+
region: us-east-1
52+
name: bedrock
53+
key: default/multi-providers
54+
name:
55+
name: multi-providers
56+
namespace: default
57+
status:
58+
conditions:
59+
- lastTransitionTime: fake
60+
message: Backend successfully accepted
61+
reason: Accepted
62+
status: "True"
63+
type: Accepted
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: agentgateway.dev/v1alpha1
2+
kind: AgentgatewayBackend
3+
metadata:
4+
namespace: default
5+
name: anthropic-backend
6+
spec:
7+
ai:
8+
provider:
9+
anthropic:
10+
model: claude-4-5-sonnet
11+
policies:
12+
ai:
13+
promptGuard:
14+
request:
15+
- webhook:
16+
backendRef:
17+
name: invalid-request-ref
18+
port: 123
19+
response:
20+
- webhook:
21+
backendRef:
22+
name: invalid-response-ref
23+
port: 456
24+
---
25+
# Output
26+
output: []
27+
status:
28+
conditions:
29+
- lastTransitionTime: fake
30+
message: |-
31+
failed to translate backend failed to build webhook: unable to find the Service default/invalid-request-ref
32+
failed to build webhook: unable to find the Service default/invalid-response-ref
33+
reason: TranslationError
34+
status: "False"
35+
type: Accepted

pkg/kgateway/agentgatewaysyncer/backend/testdata/backend/backend-secret-not-found.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: agentgateway.dev/v1alpha1
2+
kind: AgentgatewayBackend
3+
metadata:
4+
namespace: default
5+
name: dynamic-backend-with-auth
6+
spec:
7+
dynamicForwardProxy: {}
8+
policies:
9+
auth:
10+
key: sk-test-token
11+
---
12+
# Output
13+
output:
14+
- backend:
15+
dynamic: {}
16+
inlinePolicies:
17+
- auth:
18+
key:
19+
secret: sk-test-token
20+
key: default/dynamic-backend-with-auth
21+
name:
22+
name: dynamic-backend-with-auth
23+
namespace: default
24+
status:
25+
conditions:
26+
- lastTransitionTime: fake
27+
message: Backend successfully accepted
28+
reason: Accepted
29+
status: "True"
30+
type: Accepted

0 commit comments

Comments
 (0)