-
Notifications
You must be signed in to change notification settings - Fork 665
Expand file tree
/
Copy pathmodelconfig-with-tls.yaml
More file actions
390 lines (352 loc) · 10.8 KB
/
Copy pathmodelconfig-with-tls.yaml
File metadata and controls
390 lines (352 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# ModelConfig TLS Configuration Examples
#
# This file demonstrates various TLS configuration scenarios for ModelConfig resources
# to enable agents to connect to LLM providers with custom certificates.
#
# See docs/user-guide/modelconfig-tls.md for complete documentation.
---
# Example 1: Internal LiteLLM with Custom CA Certificate (Recommended)
#
# Use Case: LiteLLM gateway running at https://litellm.internal.corp:8080 with
# self-signed certificate. This configuration trusts both system CAs (for public
# services) and your custom CA (for internal services).
#
# This is the recommended configuration for most use cases.
apiVersion: v1
kind: Secret
metadata:
name: litellm-ca-cert
namespace: kagent
type: Opaque
stringData:
# CA certificate in PEM format
# Replace with your actual CA certificate
ca.crt: |
-----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIJAKL0UG+mRkmgMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
BAYTAlVTMQswCQYDVQQIDAJDQTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzENMAsG
A1UECgwETXlPcmcxDzANBgNVBAsMBlByaXZhdGUxDDAKBgNVBAMMA0NBMDAeFw0y
NTAxMDEwMDAwMDBaFw0yNjAxMDEwMDAwMDBaMEUxCzAJBgNVBAYTAlVTMQswCQYD
VQQIDAJDQTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzENMAsGA1UECgwETXlPcmcx
DzANBgNVBAsMBlByaXZhdGUxDDAKBgNVBAMMA0NBMDCCASIwDQYJKoZIhvcNAQEB
BQADggEPADCCAQoCggEBAMkN...
(your certificate content here)
...
-----END CERTIFICATE-----
---
apiVersion: v1
kind: Secret
metadata:
name: litellm-api-key
namespace: kagent
type: Opaque
stringData:
key: sk-litellm-1234567890abcdef # Replace with your actual API key
---
apiVersion: kagent.dev/v1alpha2
kind: ModelConfig
metadata:
name: litellm-internal
namespace: kagent
spec:
# Provider must be set to OpenAI since LiteLLM presents an OpenAI-compatible API
provider: OpenAI
model: gpt-4
# API key for authentication
apiKeySecretRef: litellm-api-key
apiKeySecretKey: key
# OpenAI configuration with custom base URL pointing to LiteLLM
openAI:
baseUrl: https://litellm.internal.corp:8080
# TLS configuration for custom certificate
tls:
# Reference to Secret containing CA certificate
caCertSecretRef: litellm-ca-cert
caCertSecretKey: ca.crt
# Trust both system CAs and custom CA (recommended, default behavior)
# When false (default), system CAs are used for verification (safe behavior)
# This allows connecting to both public services and internal services
disableSystemCAs: false
# Verification is enabled (secure)
disableVerify: false
---
# Example 2: Multiple CA Certificates (Certificate Bundle)
#
# Use Case: Your certificate chain includes both root and intermediate CAs,
# or you need to trust multiple certificate authorities.
apiVersion: v1
kind: Secret
metadata:
name: corporate-ca-bundle
namespace: kagent
type: Opaque
stringData:
# Certificate bundle with multiple CA certificates
# Certificates should be concatenated in PEM format
# Order: intermediate CA(s) first, then root CA
ca-bundle.crt: |
-----BEGIN CERTIFICATE-----
(Intermediate CA certificate)
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
(Root CA certificate)
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
(Optional: additional CA certificates)
-----END CERTIFICATE-----
---
apiVersion: kagent.dev/v1alpha2
kind: ModelConfig
metadata:
name: corporate-llm
namespace: kagent
spec:
provider: OpenAI
model: gpt-4-corporate
apiKeySecretRef: corporate-api-key
apiKeySecretKey: key
openAI:
baseUrl: https://ai-platform.corp.internal:443
tls:
caCertSecretRef: corporate-ca-bundle
caCertSecretKey: ca-bundle.crt # Reference the bundle key
disableSystemCAs: false # Use system CAs (default, safe behavior)
disableVerify: false
---
# Example 3: Custom CA Only (No System CAs)
#
# Use Case: Strict security policy where only corporate/internal CAs should be trusted.
# Public CA certificates are not trusted, improving security posture but limiting
# connectivity to only internal services.
apiVersion: v1
kind: Secret
metadata:
name: strict-ca-cert
namespace: kagent
type: Opaque
stringData:
ca.crt: |
-----BEGIN CERTIFICATE-----
(Corporate CA certificate only)
-----END CERTIFICATE-----
---
apiVersion: kagent.dev/v1alpha2
kind: ModelConfig
metadata:
name: strict-internal-llm
namespace: kagent
spec:
provider: OpenAI
model: gpt-4
apiKeySecretRef: internal-api-key
apiKeySecretKey: key
openAI:
baseUrl: https://secure-llm.corp.internal:443
tls:
caCertSecretRef: strict-ca-cert
caCertSecretKey: ca.crt
# Only trust custom CA, not system CAs
# When true, system CAs are disabled (only custom CA is trusted)
# This prevents connections to public services
disableSystemCAs: true
disableVerify: false
---
# Example 4: Verification Disabled (Development/Testing Only)
#
# ⚠️ WARNING: This configuration disables ALL SSL verification.
# Use ONLY in development or testing environments. NEVER in production.
#
# Use Case: Local development where you want to quickly test without
# managing certificates, or testing against a server with invalid certificates.
apiVersion: kagent.dev/v1alpha2
kind: ModelConfig
metadata:
name: litellm-dev
namespace: kagent-dev
spec:
provider: OpenAI
model: gpt-4
apiKeySecretRef: dev-api-key
apiKeySecretKey: key
openAI:
baseUrl: https://localhost:8080
tls:
# Disable all SSL verification (insecure!)
disableVerify: true
# When disableVerify is true, other TLS fields are ignored
# No Secret is required in this mode
# When this configuration is used, agents will log prominent warnings:
#
# ============================================================
# ⚠️ SSL VERIFICATION DISABLED ⚠️
# ============================================================
# SSL certificate verification is disabled.
# This should ONLY be used in development/testing.
# Production deployments MUST use proper certificates.
# ============================================================
---
# Example 5: Azure OpenAI with Custom Certificate
#
# Use Case: Azure OpenAI service accessed through internal proxy with custom certificate
apiVersion: v1
kind: Secret
metadata:
name: azure-proxy-ca
namespace: kagent
type: Opaque
stringData:
ca.crt: |
-----BEGIN CERTIFICATE-----
(Proxy CA certificate)
-----END CERTIFICATE-----
---
apiVersion: v1
kind: Secret
metadata:
name: azure-api-key
namespace: kagent
type: Opaque
stringData:
key: your-azure-api-key-here
---
apiVersion: kagent.dev/v1alpha2
kind: ModelConfig
metadata:
name: azure-through-proxy
namespace: kagent
spec:
provider: AzureOpenAI
model: gpt-4
apiKeySecretRef: azure-api-key
apiKeySecretKey: key
azureOpenAI:
endpoint: https://your-resource.openai.azure.com/ # Through internal proxy
deploymentId: gpt-4-deployment
apiVersion: "2024-02-15-preview"
tls:
caCertSecretRef: azure-proxy-ca
caCertSecretKey: ca.crt
disableSystemCAs: false # Use system CAs (default, safe behavior)
disableVerify: false
---
# Example 6: Default Configuration (No TLS)
#
# Use Case: Connecting to public LLM providers (OpenAI, Anthropic, etc.) with
# standard publicly-trusted certificates. This is the default behavior.
apiVersion: v1
kind: Secret
metadata:
name: openai-api-key
namespace: kagent
type: Opaque
stringData:
key: sk-openai-1234567890abcdef
---
apiVersion: kagent.dev/v1alpha2
kind: ModelConfig
metadata:
name: openai-public
namespace: kagent
spec:
provider: OpenAI
model: gpt-4
apiKeySecretRef: openai-api-key
apiKeySecretKey: key
# No openAI.baseUrl specified - uses default https://api.openai.com
# No tls configuration - uses system CAs with verification enabled
# This is the simplest and most common configuration
---
# Example 7: Agent Using ModelConfig with TLS
#
# Complete example showing how to create an Agent that uses a ModelConfig
# with TLS configuration.
apiVersion: kagent.dev/v1alpha2
kind: Agent
metadata:
name: internal-assistant
namespace: kagent
spec:
# Framework selection (ADK, LangGraph, or CrewAI)
framework: ADK
# Reference to ModelConfig with TLS configuration
modelConfigName: litellm-internal
# Agent card for A2A protocol
card:
name: internal-assistant
description: AI assistant using internal LiteLLM gateway
# Optional: Agent configuration
config:
systemMessage: "You are a helpful AI assistant."
temperature: 0.7
---
# Example 8: RBAC Configuration for Secret Access
#
# Agents need read access to Secrets containing CA certificates.
# This example shows how to grant appropriate permissions.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: agent-tls-secret-reader
namespace: kagent
rules:
# Grant read access to specific Secrets only
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
resourceNames:
- litellm-ca-cert
- corporate-ca-bundle
- strict-ca-cert
# Add other certificate Secrets as needed
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: agent-tls-secret-reader-binding
namespace: kagent
subjects:
# Bind to default ServiceAccount (or specify custom ServiceAccount)
- kind: ServiceAccount
name: default
namespace: kagent
roleRef:
kind: Role
name: agent-tls-secret-reader
apiGroup: rbac.authorization.k8s.io
---
# Notes and Best Practices
#
# 1. Certificate Format:
# - Must be in PEM format (text-based, base64-encoded)
# - Starts with -----BEGIN CERTIFICATE-----
# - Ends with -----END CERTIFICATE-----
# - No extra whitespace or characters
#
# 2. Secret Management:
# - Store Secrets in the same namespace as ModelConfig
# - Use descriptive names (e.g., "litellm-ca-cert" not "secret1")
# - Rotate certificates before expiration
# - Never commit Secrets to Git (use sealed secrets or external secret management)
#
# 3. Security:
# - Always enable verification (disableVerify: false) in production
# - Use RBAC to limit Secret access to specific service accounts
# - Use namespace isolation for different environments
# - Monitor certificate expiry dates
#
# 4. Testing:
# - Test connectivity after configuration changes
# - Check agent logs for TLS warnings or errors
# - Verify certificate chain with openssl commands
# - Use verification disabled mode only for development/testing
#
# 5. Certificate Updates:
# - Update Secret with new certificate
# - Restart agent pods to pick up changes: kubectl rollout restart deployment/agent-<name>
# - Secrets are mounted as volumes and not automatically reloaded
#
# 6. Troubleshooting:
# - See https://kagent.dev/docs for detailed debugging steps
# - Check agent logs: kubectl logs deployment/agent-<name>
# - Verify Secret is mounted: kubectl exec deployment/agent-<name> -- ls /etc/ssl/certs/custom/corp-ca/
# - Test certificate: kubectl exec deployment/agent-<name> -- openssl x509 -in /etc/ssl/certs/custom/corp-ca/ca.crt -text -noout