diff --git a/README.md b/README.md index c7b126f..f5b86c2 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,7 @@ docker run -p 8001:8001 -p 8002:8002 -p 4317:4317 -p 4318:4318 agentevals helm install agentevals oci://ghcr.io/agentevals-dev/agentevals/helm/agentevals ``` -The chart runs in memory by default. `--set storage.backend=postgres` with a bundled or external Postgres enables the async `/api/runs` pipeline and the Run History view. That storage layer is a preview and its schema may change between minor versions. See [Run History](docs/run-history.md) and the [Kubernetes example](examples/kubernetes/README.md) for a full walkthrough with kagent and an OpenTelemetry Collector. +The chart runs in memory by default. A parent chart can redirect every image with `global.imageRegistry` and add pull secrets with `global.imagePullSecrets`. `--set storage.backend=postgres` with a bundled or external Postgres enables the async `/api/runs` pipeline and the Run History view. That storage layer is a preview and its schema may change between minor versions. See [Run History](docs/run-history.md) and the [Kubernetes example](examples/kubernetes/README.md) for a full walkthrough with kagent and an OpenTelemetry Collector. ## Examples diff --git a/charts/agentevals/Chart.yaml b/charts/agentevals/Chart.yaml index b4db547..2f56646 100644 --- a/charts/agentevals/Chart.yaml +++ b/charts/agentevals/Chart.yaml @@ -1,6 +1,7 @@ apiVersion: v2 name: agentevals -description: agentevals web UI, OTLP HTTP+gRPC receivers, and MCP (Streamable HTTP) +description: agentevals web UI, gRPC API, OTLP HTTP+gRPC receivers, and MCP (Streamable HTTP) type: application -version: 0.7.1 -appVersion: "0.7.1" +# The release workflow sets version and appVersion to the release tag when it publishes the chart. +version: 0.14.1 +appVersion: "0.14.1" diff --git a/charts/agentevals/templates/NOTES.txt b/charts/agentevals/templates/NOTES.txt index 76fab54..956cb20 100644 --- a/charts/agentevals/templates/NOTES.txt +++ b/charts/agentevals/templates/NOTES.txt @@ -1,3 +1,6 @@ +{{- if .Values.grpcApi.only }} +1. gRPC API (agentevals.api.v1alpha1): port {{ .Values.service.grpcApi.port }} (Service port name: grpc-api). It is the only port on the pod network; the web UI, REST API, OTLP receivers and MCP listen on 127.0.0.1 inside the pod. +{{- else }} 1. UI and API are available at port {{ .Values.service.http.port }} (Service port name: http). 2. OTLP HTTP receiver: port {{ .Values.service.otlpHttp.port }} (OTEL_EXPORTER_OTLP_ENDPOINT=http://:{{ .Values.service.otlpHttp.port }}). 3. OTLP gRPC receiver: port {{ .Values.service.otlpGrpc.port }} (OTEL_EXPORTER_OTLP_ENDPOINT=:{{ .Values.service.otlpGrpc.port }}, OTEL_EXPORTER_OTLP_PROTOCOL=grpc). @@ -5,15 +8,30 @@ {{- if .Values.grpcApi.enabled }} 5. gRPC API (agentevals.api.v1alpha1): port {{ .Values.service.grpcApi.port }} (Service port name: grpc-api). Expose it only to trusted callers. {{- end }} +{{- end }} {{- if .Values.ephemeralVolume.enabled }} -{{ ternary 6 5 .Values.grpcApi.enabled }}. An emptyDir is mounted at /tmp with HOME=/tmp/agentevals-home (ephemeral; lost on pod restart). Set ephemeralVolume.enabled=false and readOnlyRootFilesystem=false if you need a writable root without this mount. +{{ if .Values.grpcApi.only }}2{{ else }}{{ ternary 6 5 .Values.grpcApi.enabled }}{{ end }}. An emptyDir is mounted at /tmp with HOME=/tmp/agentevals-home (ephemeral; lost on pod restart). Set ephemeralVolume.enabled=false and readOnlyRootFilesystem=false if you need a writable root without this mount. +{{- end }} +{{- if .Values.grpcApi.auth.enabled }} + +gRPC API callers send a ServiceAccount token for audience "{{ .Values.grpcApi.auth.audience }}" as "authorization: Bearer " metadata. +Allowed ServiceAccounts: {{ join ", " .Values.grpcApi.auth.allowedServiceAccounts }}. Health checks need no token. +{{- if not .Values.grpcApi.only }} +WARNING: authentication covers only the gRPC API. The UI, REST API, OTLP receivers and MCP stay unauthenticated; set grpcApi.only=true to keep them on 127.0.0.1. +{{- end }} {{- end }} Get the Service URL: export POD_NAME=$(kubectl get pods --namespace {{ include "agentevals.namespace" . }} -l "app.kubernetes.io/name={{ include "agentevals.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") kubectl --namespace {{ include "agentevals.namespace" . }} port-forward $POD_NAME {{ .Values.service.http.port }}:{{ .Values.service.http.port }} +{{- if .Values.grpcApi.only }} + +Health check: grpc.health.v1 on :{{ .Values.service.grpcApi.containerPort }} +{{- else }} + Health check: GET http://:{{ .Values.service.http.containerPort }}/api/health +{{- end }} {{- if eq .Values.storage.backend "postgres" }} diff --git a/charts/agentevals/templates/_helpers.tpl b/charts/agentevals/templates/_helpers.tpl index 6672e29..3c9aeb7 100644 --- a/charts/agentevals/templates/_helpers.tpl +++ b/charts/agentevals/templates/_helpers.tpl @@ -24,7 +24,7 @@ {{- end }} {{- define "agentevals.image" -}} -{{- $registry := .Values.image.registry | default .Values.registry -}} +{{- $registry := (.Values.global | default dict).imageRegistry | default .Values.image.registry | default .Values.registry -}} {{- $tag := .Values.image.tag | default .Values.tag | default .Chart.AppVersion -}} {{- if $registry -}} {{- printf "%s/%s:%s" $registry .Values.image.repository $tag -}} @@ -79,7 +79,67 @@ Bundled Postgres image reference (registry/repository/name:tag). */}} {{- define "agentevals.postgresql.image" -}} {{- $pg := .Values.database.postgres.bundled -}} -{{- printf "%s/%s/%s:%s" $pg.image.registry $pg.image.repository $pg.image.name $pg.image.tag -}} +{{- $registry := (.Values.global | default dict).imageRegistry | default $pg.image.registry -}} +{{- printf "%s/%s/%s:%s" $registry $pg.image.repository $pg.image.name $pg.image.tag -}} +{{- end -}} + +{{/* +imagePullSecrets for every pod: imagePullSecrets merged (union) with global.imagePullSecrets. +*/}} +{{- define "agentevals.imagePullSecrets" -}} +{{- with concat (.Values.imagePullSecrets | default list) ((.Values.global | default dict).imagePullSecrets | default list) | uniq -}} +imagePullSecrets: + {{- toYaml . | nindent 2 }} +{{- end -}} +{{- end -}} + +{{/* +imagePullPolicy for a container: its own value, then imagePullPolicy, then global.imagePullPolicy, +then IfNotPresent. +Usage: {{ include "agentevals.imagePullPolicy" (dict "root" $ "local" .Values.image.pullPolicy) }} +*/}} +{{- define "agentevals.imagePullPolicy" -}} +{{- .local | default .root.Values.imagePullPolicy | default ((.root.Values.global | default dict).imagePullPolicy) | default "IfNotPresent" -}} +{{- end -}} + +{{/* +ClusterRole and ClusterRoleBinding name for TokenReviews; cluster scoped, so it carries the namespace. +*/}} +{{- define "agentevals.tokenReviewName" -}} +{{- printf "%s-%s-tokenreview" (include "agentevals.namespace" .) (include "agentevals.fullname" .) -}} +{{- end -}} + +{{/* +Fail the render on a gRPC API setup the server would refuse, or one that grants the TokenReview +permission to the namespace's default ServiceAccount. +*/}} +{{- define "agentevals.validateGrpcApi" -}} +{{- $api := .Values.grpcApi -}} +{{- if and $api.only (not $api.enabled) -}} +{{- fail "grpcApi.only needs grpcApi.enabled=true" -}} +{{- end -}} +{{- if $api.auth.enabled -}} +{{- if not $api.enabled -}} +{{- fail "grpcApi.auth.enabled needs grpcApi.enabled=true" -}} +{{- end -}} +{{- if empty $api.auth.audience -}} +{{- fail "grpcApi.auth.enabled needs grpcApi.auth.audience" -}} +{{- end -}} +{{- if empty $api.auth.allowedServiceAccounts -}} +{{- fail "grpcApi.auth.enabled needs grpcApi.auth.allowedServiceAccounts (namespace/name): any pod can mint a token for any audience, so the audience alone authorizes nothing" -}} +{{- end -}} +{{- range $api.auth.allowedServiceAccounts -}} +{{- if not (regexMatch "^[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?/[a-z0-9]([-a-z0-9.]{0,251}[a-z0-9])?$" (toString .)) -}} +{{- fail (printf "grpcApi.auth.allowedServiceAccounts: %q is not namespace/name" (toString .)) -}} +{{- end -}} +{{- end -}} +{{- if and (not .Values.serviceAccount.create) (empty .Values.serviceAccount.name) -}} +{{- fail "grpcApi.auth.enabled needs serviceAccount.create=true or serviceAccount.name, so the TokenReview permission does not go to the namespace's default ServiceAccount" -}} +{{- end -}} +{{- if and .Values.serviceAccount.create (not .Values.serviceAccount.automount) -}} +{{- fail "grpcApi.auth.enabled needs serviceAccount.automount=true: the server calls the TokenReview API with its ServiceAccount token" -}} +{{- end -}} +{{- end -}} {{- end -}} {{/* diff --git a/charts/agentevals/templates/deployment.yaml b/charts/agentevals/templates/deployment.yaml index 6dfc873..c4da90b 100644 --- a/charts/agentevals/templates/deployment.yaml +++ b/charts/agentevals/templates/deployment.yaml @@ -1,3 +1,4 @@ +{{- include "agentevals.validateGrpcApi" . -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -22,9 +23,8 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} + {{- with include "agentevals.imagePullSecrets" . }} + {{- . | nindent 6 }} {{- end }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} @@ -52,7 +52,7 @@ spec: containers: - name: agentevals image: {{ include "agentevals.image" . | quote }} - imagePullPolicy: {{ .Values.image.pullPolicy | default .Values.imagePullPolicy }} + imagePullPolicy: {{ include "agentevals.imagePullPolicy" (dict "root" $ "local" .Values.image.pullPolicy) }} {{- if .Values.command }} command: {{- toYaml .Values.command | nindent 12 }} @@ -70,6 +70,18 @@ spec: - name: AGENTEVALS_GRPC_REFLECTION value: "true" {{- end }} + {{- if .Values.grpcApi.only }} + - name: AGENTEVALS_API_GRPC_ONLY + value: "true" + {{- end }} + {{- if .Values.grpcApi.auth.enabled }} + - name: AGENTEVALS_API_GRPC_AUTH + value: "kubernetes" + - name: AGENTEVALS_API_GRPC_AUTH_AUDIENCE + value: {{ .Values.grpcApi.auth.audience | quote }} + - name: AGENTEVALS_API_GRPC_AUTH_ALLOWED_SERVICE_ACCOUNTS + value: {{ join "," .Values.grpcApi.auth.allowedServiceAccounts | quote }} + {{- end }} {{- if .Values.ephemeralVolume.enabled }} - name: TMPDIR value: "/tmp" @@ -111,6 +123,7 @@ spec: {{- toYaml . | nindent 12 }} {{- end }} ports: + {{- if not .Values.grpcApi.only }} - name: http containerPort: {{ .Values.service.http.containerPort }} protocol: TCP @@ -123,6 +136,7 @@ spec: - name: mcp containerPort: {{ .Values.service.mcp.containerPort }} protocol: TCP + {{- end }} {{- if .Values.grpcApi.enabled }} - name: grpc-api containerPort: {{ .Values.service.grpcApi.containerPort }} @@ -136,15 +150,21 @@ spec: {{- $_ := set $sc "readOnlyRootFilesystem" false }} {{- end }} {{- toYaml $sc | nindent 12 }} + {{- /* In grpcApi.only mode /api/health listens on 127.0.0.1, out of the kubelet's reach. */}} startupProbe: + {{- if .Values.grpcApi.only }} + grpc: + port: {{ .Values.service.grpcApi.containerPort }} + {{- else }} httpGet: path: /api/health port: http + {{- end }} failureThreshold: 60 periodSeconds: 10 timeoutSeconds: 5 readinessProbe: - {{- if and .Values.grpcApi.enabled .Values.grpcApi.grpcReadinessProbe }} + {{- if and .Values.grpcApi.enabled (or .Values.grpcApi.only .Values.grpcApi.grpcReadinessProbe) }} grpc: port: {{ .Values.service.grpcApi.containerPort }} {{- else }} @@ -155,9 +175,14 @@ spec: initialDelaySeconds: 5 periodSeconds: 10 livenessProbe: + {{- if .Values.grpcApi.only }} + grpc: + port: {{ .Values.service.grpcApi.containerPort }} + {{- else }} httpGet: path: /api/health port: http + {{- end }} initialDelaySeconds: 15 periodSeconds: 20 {{- if or .Values.ephemeralVolume.enabled .Values.extraVolumeMounts }} diff --git a/charts/agentevals/templates/postgresql.yaml b/charts/agentevals/templates/postgresql.yaml index c4e5370..031a265 100644 --- a/charts/agentevals/templates/postgresql.yaml +++ b/charts/agentevals/templates/postgresql.yaml @@ -51,9 +51,8 @@ spec: {{- include "agentevals.selectorLabels" . | nindent 8 }} app.kubernetes.io/component: database spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} + {{- with include "agentevals.imagePullSecrets" . }} + {{- . | nindent 6 }} {{- end }} serviceAccountName: {{ $fullname }} securityContext: @@ -64,7 +63,7 @@ spec: containers: - name: postgresql image: {{ include "agentevals.postgresql.image" . }} - imagePullPolicy: {{ $pg.image.pullPolicy }} + imagePullPolicy: {{ include "agentevals.imagePullPolicy" (dict "root" $ "local" $pg.image.pullPolicy) }} securityContext: allowPrivilegeEscalation: false ports: diff --git a/charts/agentevals/templates/rbac-tokenreview.yaml b/charts/agentevals/templates/rbac-tokenreview.yaml new file mode 100644 index 0000000..733f30c --- /dev/null +++ b/charts/agentevals/templates/rbac-tokenreview.yaml @@ -0,0 +1,27 @@ +{{- if .Values.grpcApi.auth.enabled -}} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "agentevals.tokenReviewName" . }} + labels: + {{- include "agentevals.labels" . | nindent 4 }} +rules: + - apiGroups: ["authentication.k8s.io"] + resources: ["tokenreviews"] + verbs: ["create"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "agentevals.tokenReviewName" . }} + labels: + {{- include "agentevals.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "agentevals.tokenReviewName" . }} +subjects: + - kind: ServiceAccount + name: {{ include "agentevals.serviceAccountName" . }} + namespace: {{ include "agentevals.namespace" . }} +{{- end }} diff --git a/charts/agentevals/templates/service.yaml b/charts/agentevals/templates/service.yaml index f724f4a..d601ead 100644 --- a/charts/agentevals/templates/service.yaml +++ b/charts/agentevals/templates/service.yaml @@ -8,6 +8,7 @@ metadata: spec: type: {{ .Values.service.type }} ports: + {{- if not .Values.grpcApi.only }} - name: http port: {{ .Values.service.http.port }} targetPort: http @@ -24,6 +25,7 @@ spec: port: {{ .Values.service.mcp.port }} targetPort: mcp protocol: TCP + {{- end }} {{- if .Values.grpcApi.enabled }} - name: grpc-api port: {{ .Values.service.grpcApi.port }} diff --git a/charts/agentevals/values.yaml b/charts/agentevals/values.yaml index af95b35..f71e586 100644 --- a/charts/agentevals/values.yaml +++ b/charts/agentevals/values.yaml @@ -2,6 +2,18 @@ # Global # ============================================================================== +# Values a parent chart can share with this one. +global: + # -- Registry for every image of this chart, including the bundled Postgres. + # Takes precedence over registry, image.registry and + # database.postgres.bundled.image.registry. + imageRegistry: "" + # -- Pull secrets for every pod of this chart, merged (union) with + # imagePullSecrets. + imagePullSecrets: [] + # -- Fallback pull policy where neither the image nor imagePullPolicy sets one. + imagePullPolicy: "" + # -- Number of replicas. Keep 1 when agents or a Collector send OTLP to this # release: live sessions are held in the memory of the pod that receives them, # so with more replicas one session's traces and logs end up split across pods. @@ -9,16 +21,18 @@ # replicas (SELECT FOR UPDATE SKIP LOCKED claims), not live sessions. replicaCount: 1 -# -- Global container image registry (prepended to image.repository) +# -- Container image registry (prepended to image.repository). global.imageRegistry +# takes precedence. registry: ghcr.io # -- Global image tag override (defaults to Chart.appVersion) tag: "" -# -- Global image pull policy -imagePullPolicy: IfNotPresent +# -- Image pull policy for every container. Empty falls back to +# global.imagePullPolicy, then IfNotPresent. +imagePullPolicy: "" -# -- Image pull secrets +# -- Image pull secrets, merged with global.imagePullSecrets imagePullSecrets: [] # -- Override the chart name @@ -41,7 +55,7 @@ image: repository: agentevals-dev/agentevals # -- Container image tag (defaults to global tag, then Chart.appVersion) tag: "" - # -- Container image pull policy (defaults to global imagePullPolicy) + # -- Container image pull policy (defaults to imagePullPolicy) pullPolicy: "" # ============================================================================== @@ -159,6 +173,24 @@ grpcApi: # -- Check readiness with the gRPC health service on the gRPC API port instead of HTTP # /api/health grpcReadinessProbe: false + # -- Serve only the gRPC API on the pod network (--api-grpc-only). The web UI and + # REST API, the OTLP receivers and MCP listen on 127.0.0.1 inside the pod, where + # kubectl port-forward still reaches them. The Service exposes only grpc-api and + # every probe uses the gRPC health service. + only: false + auth: + # -- Require a Kubernetes ServiceAccount token on every gRPC API call except + # health checks (--api-grpc-auth kubernetes). Renders a ClusterRole and + # ClusterRoleBinding that let the chart's ServiceAccount create TokenReviews, + # so it needs serviceAccount.create or serviceAccount.name. Covers only the + # gRPC API: combine it with grpcApi.only. + enabled: false + # -- Audience the callers' tokens must be minted for + audience: agentevals + # -- ServiceAccounts allowed to call the API, as namespace/name. Required when + # enabled: any pod can mint a token for any audience, so the audience alone + # authorizes nothing. + allowedServiceAccounts: [] # ============================================================================== # Resources @@ -273,8 +305,8 @@ database: name: postgres # -- Bundled Postgres image tag tag: "18.3-alpine" - # -- Bundled Postgres image pull policy - pullPolicy: IfNotPresent + # -- Bundled Postgres image pull policy (defaults to imagePullPolicy) + pullPolicy: "" # -- PersistentVolumeClaim size for the bundled Postgres data storage: 1Gi # -- StorageClass for the PVC. Defaults to the cluster default when empty. diff --git a/docs/grpc-api.md b/docs/grpc-api.md index 059d13a..f3f9634 100644 --- a/docs/grpc-api.md +++ b/docs/grpc-api.md @@ -59,7 +59,7 @@ Errors use standard gRPC status codes with a `google.rpc.ErrorInfo` detail whose Messages can be up to 16 MiB. Uploaded trace documents are limited to 10 MiB each, as in the REST API. -The Helm chart has the same switches under `grpcApi`: `enabled`, `reflection`, and `grpcReadinessProbe` to check readiness with the gRPC health service. The Service exposes the port as `grpc-api`. +The Helm chart has the same switches under `grpcApi`: `enabled`, `reflection`, `grpcReadinessProbe` to check readiness with the gRPC health service, `only`, and `auth`. The Service exposes the port as `grpc-api`. ### Serving only the gRPC API @@ -71,6 +71,8 @@ uv run agentevals serve --api-grpc-only Check health with `grpc.health.v1` on the gRPC API port; `/api/health` is only reachable from inside the host or pod. `kubectl port-forward` still reaches the web UI, because it connects to the pod's loopback address. +In the Helm chart, `grpcApi.only=true` does the same. The Service then exposes only `grpc-api`, and the startup, readiness and liveness probes use the gRPC health service. + ## Tracing the API server agentevals receives telemetry, so it exports none of its own by default. With `AGENTEVALS_API_TRACES=true` it traces every API call with the OpenTelemetry gRPC instrumentation, using the standard exporter variables: @@ -109,3 +111,19 @@ Callers send a ServiceAccount token minted for the audience as `authorization: B The list is required: any pod can mint a token for any audience, so the audience alone proves nothing. The server refuses to start with an empty list, and never lets a call through when a check fails. A successful check is cached for up to 30 seconds and never past the token's expiry. Health checks need no token. Reflection, when turned on, needs one like every other call: `grpcurl -H "authorization: Bearer $TOKEN" ...`. Authentication covers only the gRPC API. Combine it with `--api-grpc-only` so the REST API, the OTLP receivers and MCP stay on `127.0.0.1`; without it the server prints a warning. + +With the Helm chart: + +```yaml +serviceAccount: + create: true +grpcApi: + only: true + auth: + enabled: true + audience: agentevals + allowedServiceAccounts: + - evals/controller +``` + +The chart then adds a ClusterRole and ClusterRoleBinding that let its ServiceAccount create TokenReviews. It refuses to render with an empty `allowedServiceAccounts`, or without `serviceAccount.create` or `serviceAccount.name`, so the permission never goes to the namespace's `default` ServiceAccount.