diff --git a/.github/workflows/helm-validate.yaml b/.github/workflows/helm-validate.yaml index bb90573..0e1dd90 100644 --- a/.github/workflows/helm-validate.yaml +++ b/.github/workflows/helm-validate.yaml @@ -33,3 +33,6 @@ jobs: - name: Template with example overrides run: helm template openops chart -f chart/values.overrides-example.yaml + + - name: Template with MCP enabled + run: helm template openops chart -f chart/values.mcp-example.yaml diff --git a/AGENTS.md b/AGENTS.md index e93d736..0f543f1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,8 @@ - `/chart/values.ci.yaml`: Resource-constrained overlay for CI environments. - `/chart/values.dev.yaml`: Development overlay for local development environments. - `/chart/values.production.yaml`: Production overlay with externalized dependencies and cloud settings. -- `/chart/templates/`: Kubernetes manifests rendered by Helm (43 files). Includes deployments/statefulsets, services, configmaps (`configmap-*.yaml`), secrets (`secret-env.yaml`, `external-secret.yaml`), service accounts, PodDisruptionBudgets, HorizontalPodAutoscalers, NetworkPolicy, LimitRange, ServiceMonitor for Prometheus, and Helm tests. Shared template helpers live in `_helpers.tpl` (561 lines with 49+ helper functions). Postgres and Redis use StatefulSets with volumeClaimTemplates for stable storage and safe rollouts. +- `/chart/values.mcp-example.yaml`: Overlay enabling the opt-in MCP server for external agents; rendered by `helm-validate.yaml` so the enabled path stays valid. +- `/chart/templates/`: Kubernetes manifests rendered by Helm (48 files). Includes deployments/statefulsets, services, configmaps (`configmap-*.yaml`), secrets (`secret-env.yaml`, `external-secret.yaml`), service accounts, PodDisruptionBudgets, HorizontalPodAutoscalers, NetworkPolicy, LimitRange, ServiceMonitor for Prometheus, and Helm tests. Shared template helpers live in `_helpers.tpl` (561 lines with 49+ helper functions). Postgres and Redis use StatefulSets with volumeClaimTemplates for stable storage and safe rollouts. - `/chart/templates/NOTES.txt`: Helm installation notes displayed after deployment with important warnings and next steps. - `/chart/.helmignore`: Excludes development and repository files from packaged charts to reduce size and prevent leaking unnecessary files. - `/LICENSE`: Apache 2.0 license for this Helm chart repository. @@ -24,14 +25,15 @@ ## Production features - **Security-first design**: Security contexts enabled by default (runAsNonRoot, drop ALL capabilities, seccomp RuntimeDefault profile). -- **Service accounts**: Dedicated service accounts for each component (app, engine, tables, analytics, nginx, postgres, redis) with configurable annotations for AWS IAM roles (IRSA), GCP Workload Identity, or Azure Managed Identity. +- **Service accounts**: Dedicated service accounts for each component (app, worker, mcp, tables, analytics, nginx, postgres, redis) with configurable annotations for AWS IAM roles (IRSA), GCP Workload Identity, or Azure Managed Identity. - **External Secrets Operator**: Built-in support for AWS Secrets Manager, HashiCorp Vault, GCP Secret Manager, and Azure Key Vault integration. -- **PodDisruptionBudgets (PDBs)**: Configured for `app`, `engine`, `nginx`, `analytics` and `tables` — note that `tables` is stateful (PVC, ReadWriteOnce), while the Postgres and Redis StatefulSets have no PDB. All default to `maxUnavailable: 1` so voluntary disruptions (node drains, upgrades) can always proceed. Each component also accepts `minAvailable` when `maxUnavailable` is unset, but avoid it where a component runs a single replica: `minAvailable: 1` then evaluates to `disruptionsAllowed: 0` and blocks every drain. `analytics` and `tables` default to one replica. -- **HorizontalPodAutoscalers (HPAs)**: Optional autoscaling for app, engine, analytics, and nginx based on CPU/memory metrics. +- **PodDisruptionBudgets (PDBs)**: Configured for `app`, `worker`, `mcp`, `nginx`, `analytics` and `tables` — note that `tables` is stateful (PVC, ReadWriteOnce), while the Postgres and Redis StatefulSets have no PDB. All default to `maxUnavailable: 1` so voluntary disruptions (node drains, upgrades) can always proceed. Each component also accepts `minAvailable` when `maxUnavailable` is unset, but avoid it where a component runs a single replica: `minAvailable: 1` then evaluates to `disruptionsAllowed: 0` and blocks every drain. `analytics` and `tables` default to one replica. +- **HorizontalPodAutoscalers (HPAs)**: Optional autoscaling for app, worker, mcp, analytics, and nginx based on CPU/memory metrics. - **NetworkPolicy**: Optional network segmentation to restrict pod-to-pod communication and enforce least-privilege networking with explicit allow rules. - **LimitRange**: Optional namespace-level resource defaults and constraints to prevent resource exhaustion. - **ServiceMonitor**: Prometheus Operator integration for scraping application metrics from `/metrics` endpoints. - **Helm tests**: Post-installation connectivity tests to validate deployment health. +- **MCP server (opt-in)**: `mcp.enabled` deploys `openops-mcp` behind nginx at `/mcp` and derives the API's OAuth env from `global.publicUrl`. The MCP pod renders only `mcp.env`. `OPS_OAUTH_RS_CLIENT_SECRET` is deliberately not a default `openopsEnvSecrets` key: External Secrets fails the whole sync on a missing property, so the key, `mcp.env` secret collection, nginx routes and NetworkPolicy are all gated on `mcp.enabled`, and `openops.validateMcp` fails the render if the key is undeclared, too short, or `global.publicUrl` is not https. - **Validation helpers**: Runtime validation of required secrets (OPS_ENCRYPTION_KEY, OPS_JWT_SECRET, etc.) with helpful error messages at render time. ## Release workflow diff --git a/README.md b/README.md index d5b856f..e09be38 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OpenOps Helm Chart -This repository contains the Helm chart that deploys the OpenOps application stack (nginx, app server, engine, tables, analytics, Postgres, Redis) onto a Kubernetes cluster. +This repository contains the Helm chart that deploys the OpenOps application stack (nginx, app server, worker, tables, analytics, Postgres, Redis) onto a Kubernetes cluster. ## Repository layout - `chart/Chart.yaml`: Chart metadata for the `openops` release. @@ -9,7 +9,8 @@ This repository contains the Helm chart that deploys the OpenOps application sta - `chart/values.ci.yaml`: Resource-constrained overlay for CI environments. - `chart/values.dev.yaml`: Development overlay for local development environments. - `chart/values.production.yaml`: Production overlay with externalized dependencies and cloud settings. -- `chart/templates/`: Kubernetes manifests templated by Helm (43 files including deployments, statefulsets, services, configmaps, secrets, external secrets, PVCs, ingress, service accounts, PodDisruptionBudgets, HorizontalPodAutoscalers, NetworkPolicy, LimitRange, ServiceMonitor, Helm tests, and helpers). +- `chart/values.mcp-example.yaml`: Overlay enabling the MCP server for external agents; rendered in CI. +- `chart/templates/`: Kubernetes manifests templated by Helm (48 files including deployments, statefulsets, services, configmaps, secrets, external secrets, PVCs, ingress, service accounts, PodDisruptionBudgets, HorizontalPodAutoscalers, NetworkPolicy, LimitRange, ServiceMonitor, Helm tests, and helpers). - `chart/.helmignore`: Excludes development and repository files from packaged charts. - `LICENSE`: Apache 2.0 license for this Helm chart. - `docs/`: Deployment guides for AWS EKS, EKS Fargate, and other platforms. @@ -17,7 +18,8 @@ This repository contains the Helm chart that deploys the OpenOps application sta ## Components - **nginx**: Reverse proxy and load balancer exposed via `LoadBalancer`. - **openops-app**: Main application server. -- **openops-engine**: Task execution engine. +- **openops-worker**: Workflow execution worker. +- **openops-mcp** (opt-in): MCP server that lets external agents such as Claude Code or Codex operate OpenOps over OAuth. - **openops-tables**: Data tables service (Baserow). - **openops-analytics**: Analytics dashboard (Superset). - **postgres**: PostgreSQL database. @@ -111,12 +113,16 @@ The chart includes several example overlay files to help you get started: **`values.production.yaml`** - Production-ready overlay - Demonstrates externalized PostgreSQL and Redis (AWS RDS, ElastiCache, etc.) -- Increased replica counts for high availability (app: 3, engine: 3, nginx: 2) +- Increased replica counts for high availability (app: 3, worker: 3, nginx: 2) - Production-grade resource allocations (2-4Gi memory per service) - Cloud-specific storage classes (gp3, premium-rwo, managed-csi) - LoadBalancer annotations for AWS/GCP/Azure - Security hardening examples +**`values.mcp-example.yaml`** - MCP server enabled +- Shows the minimum to turn on the MCP server: `mcp.enabled`, an https `global.publicUrl`, and `OPS_OAUTH_RS_CLIENT_SECRET` +- Rendered by the validation workflow so the opt-in path stays green + ### Creating custom overlays **Staging environment example:** @@ -312,6 +318,36 @@ kubectl create secret tls openops-tls \ -n openops ``` +## MCP server for external agents + +External agents such as Claude Code or Codex connect to OpenOps through the `openops-mcp` service, which is disabled by default. When enabled it sits behind nginx at `/mcp` and authenticates agents with OAuth issued by the OpenOps API. The chart derives the API-side settings (`OPS_OAUTH_ENABLED`, `OPS_OAUTH_ISSUER_URL`, `OPS_MCP_RESOURCE_URL`) from `mcp.enabled` and `global.publicUrl`, so the two sides cannot drift. + +Prerequisites: +- `global.publicUrl` must be `https://...` (plain `http` is only accepted for `localhost`), so enable TLS first. +- `OPS_OAUTH_RS_CLIENT_SECRET` must be declared under `openopsEnvSecrets` with a random value of at least 32 characters (`openssl rand -hex 32`). It is shared between the API and the MCP pod. When an external secret manager supplies the value, declare the key as `""`; with `externalSecrets.infraSecretName` set, the chart reads it from the infra secret (the Terraform-generated one on Azure), otherwise from the single remote secret. External Secrets fails the whole sync when a requested property is missing, which is why the chart does not declare this key by default. +- Pull access to the MCP image. Until the first public release the default `mcp.repository` is the private registry `openopsprivate.azurecr.io`; point `mcp.repository`/`mcp.tag` at an image your cluster can pull, or grant the cluster's node identity pull rights on that registry. + +Minimal override: +```yaml +global: + publicUrl: "https://example.openops.com" + +openopsEnvSecrets: + OPS_OAUTH_RS_CLIENT_SECRET: "" + +mcp: + enabled: true + tag: "" +``` + +The MCP pod is stateless and receives only its own environment (`mcp.env`), never the shared `openopsEnv`/`openopsEnvSecrets` layers. It has no health endpoint, so probes use the unauthenticated OAuth metadata route `/.well-known/oauth-protected-resource/mcp`. With `networkPolicy.enabled`, only nginx may reach it and it may only reach the app, DNS, and port 443. + +Connect an agent: +```bash +claude mcp add --transport http openops https://example.openops.com/mcp +``` +The first tool call opens a browser to approve the connection under Settings -> Connected apps. + ## Dependencies The deployments include health checks and readiness probes so dependent services wait until their prerequisites are available. @@ -446,7 +482,7 @@ app: memory: "4Gi" cpu: "2000m" -engine: +worker: replicas: 3 tables: @@ -460,7 +496,7 @@ nginx: ``` **Important scaling considerations:** -- **app** and **engine** are stateless and can be scaled horizontally without restrictions. +- **app** and **worker** are stateless and can be scaled horizontally without restrictions. - **tables** uses file-based storage (SQLite for media) and requires `ReadWriteOnce` PVC; limit to 2-3 replicas or migrate to object storage. - **analytics** can be scaled but shares session state; consider sticky sessions or external session storage for >2 replicas. - **postgres** and **redis** bundled deployments are single-replica; use external managed services for HA. @@ -481,14 +517,14 @@ app: **Resource tuning guidelines:** - **app**: Memory-intensive for large workflows; start with 1-2Gi, scale to 4Gi+ under load. -- **engine**: CPU-intensive for code execution; allocate 500m-1000m CPU per replica. +- **worker**: CPU-intensive for code execution; allocate 500m-1000m CPU per replica. - **tables**: Initial migrations require 1-2Gi memory; steady-state can run on 512Mi-1Gi. - **analytics**: Dashboard rendering is memory-heavy; allocate 2Gi+ for production. - **postgres**: Size based on dataset; 512Mi-1Gi for dev, 2Gi+ for production. - **redis**: Typically light; 256Mi-512Mi sufficient for most workloads. ### Autoscaling -The chart includes optional HorizontalPodAutoscaler (HPA) resources for app, engine, analytics, and nginx. Enable them in your values: +The chart includes optional HorizontalPodAutoscaler (HPA) resources for app, worker, analytics, and nginx. Enable them in your values: ```yaml hpa: @@ -499,7 +535,7 @@ hpa: maxReplicas: 10 targetCPUUtilizationPercentage: 70 targetMemoryUtilizationPercentage: 80 - engine: + worker: enabled: true minReplicas: 2 maxReplicas: 8 @@ -649,7 +685,7 @@ networkPolicy: The default policy enforces: - Nginx accepts traffic from LoadBalancer/Ingress and routes to app/analytics/tables -- App, engine, and analytics can access Postgres and Redis +- App, worker, and analytics can access Postgres and Redis - All components can query DNS and access external HTTPS endpoints - Postgres and Redis only accept connections from authorized components - All other traffic is denied by default (zero-trust networking) @@ -723,10 +759,10 @@ serviceAccount: create: true annotations: eks.amazonaws.com/role-arn: "arn:aws:iam::ACCOUNT:role/openops-app" - engine: + worker: create: true annotations: - eks.amazonaws.com/role-arn: "arn:aws:iam::ACCOUNT:role/openops-engine" + eks.amazonaws.com/role-arn: "arn:aws:iam::ACCOUNT:role/openops-worker" # For GCP Workload Identity analytics: create: true @@ -792,7 +828,7 @@ app: memory: "2Gi" cpu: "1000m" -engine: +worker: replicas: 3 tables: @@ -819,7 +855,7 @@ app: podDisruptionBudget: enabled: true maxUnavailable: 1 -engine: +worker: podDisruptionBudget: enabled: true maxUnavailable: 1 @@ -877,7 +913,7 @@ serviceMonitor: The ServiceMonitor automatically discovers and scrapes metrics from: - `openops-app` on `/metrics` -- `openops-engine` on `/metrics` +- `openops-worker` on `/metrics` - `openops-analytics` on `/metrics` - `postgres` on `:9187/metrics` (if postgres-exporter sidecar is enabled) - `redis` on `:9121/metrics` (if redis-exporter sidecar is enabled) diff --git a/chart/.gitignore b/chart/.gitignore index 11b5665..7895c09 100644 --- a/chart/.gitignore +++ b/chart/.gitignore @@ -2,3 +2,4 @@ values.*.yaml !values.overrides-example.yaml !values.ci.yaml !values.production.yaml +!values.mcp-example.yaml diff --git a/chart/templates/NOTES.txt b/chart/templates/NOTES.txt index 736f396..88f0933 100644 --- a/chart/templates/NOTES.txt +++ b/chart/templates/NOTES.txt @@ -94,6 +94,14 @@ To get started: Email: {{ .Values.openopsEnv.OPS_OPENOPS_ADMIN_EMAIL }} Password: (from your secure values file) +{{- if .Values.mcp.enabled }} + +4. Connect an external agent to the MCP server: + + claude mcp add --transport http openops {{ include "openops.publicUrl" . }}/mcp + + The first tool call opens a browser to approve the connection under Settings -> Connected apps. +{{- end }} ================================================================================ DOCUMENTATION & SUPPORT diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl index 1c62de6..94b9366 100644 --- a/chart/templates/_helpers.tpl +++ b/chart/templates/_helpers.tpl @@ -156,6 +156,10 @@ Service URLs {{- printf "http://%s:8088" .Values.analytics.name -}} {{- end }} +{{- define "openops.mcpServiceUrl" -}} +{{- printf "http://%s:%v" .Values.mcp.name .Values.mcp.port -}} +{{- end }} + {{/* Check if nginx ingress controller is being used */}} @@ -265,7 +269,9 @@ Expected dict: { "root": $, "env": dict, "secretName": "my-secret" } {{- $infraSecretName = $root.Values.externalSecrets.infraSecretName -}} {{- $appSecretName = $root.Values.externalSecrets.appSecretName -}} {{- end -}} -{{- $infraKeys := list "OPS_POSTGRES_PASSWORD" "OPS_REDIS_URL" "OPS_REDIS_HOST" "OPS_REDIS_PASSWORD" -}} +{{- /* Keys Terraform writes into the infra secret; everything else comes from the app secret. + OPS_OAUTH_RS_CLIENT_SECRET is generated per environment by infra (devops) for the MCP server. */ -}} +{{- $infraKeys := list "OPS_POSTGRES_PASSWORD" "OPS_REDIS_URL" "OPS_REDIS_HOST" "OPS_REDIS_PASSWORD" "OPS_OAUTH_RS_CLIENT_SECRET" -}} {{- range $k := keys $env | sortAlpha -}} {{- $v := index $env $k -}} {{- if eq (include "openops.isSecretKey" (dict "root" $root "key" $k "value" ($v | toString))) "true" }} @@ -413,6 +419,28 @@ Validate that required secrets are configured - ALWAYS ENFORCED {{- fail "ERROR: ANALYTICS_POWERUSER_PASSWORD is required. Use a strong password" -}} {{- end -}} {{- end -}} +{{- include "openops.validateMcp" . -}} +{{- end }} + +{{/* +Validate the MCP / OAuth configuration when the MCP server is enabled. +The key must be declared even when an external secret manager supplies the value, because the +ExternalSecret and the pods' secretKeyRefs are generated from the declared keys. +*/}} +{{- define "openops.validateMcp" -}} +{{- if .Values.mcp.enabled -}} +{{- if not (hasKey .Values.openopsEnvSecrets "OPS_OAUTH_RS_CLIENT_SECRET") -}} +{{- fail "ERROR: mcp.enabled requires openopsEnvSecrets.OPS_OAUTH_RS_CLIENT_SECRET to be declared (openssl rand -hex 32). Declare it as \"\" when the value comes from an external secret manager." -}} +{{- end -}} +{{- $usingExistingSecret := and .Values.secretEnv .Values.secretEnv.existingSecret (not .Values.secretEnv.create) -}} +{{- if and (not $usingExistingSecret) (lt (len .Values.openopsEnvSecrets.OPS_OAUTH_RS_CLIENT_SECRET) 32) -}} +{{- fail "ERROR: OPS_OAUTH_RS_CLIENT_SECRET must be at least 32 characters when mcp.enabled is true. Generate with: openssl rand -hex 32" -}} +{{- end -}} +{{- $url := include "openops.publicUrl" . -}} +{{- if and (not (hasPrefix "https://" $url)) (not (hasPrefix "http://localhost" $url)) -}} +{{- fail (printf "ERROR: mcp.enabled requires an https global.publicUrl (got %s). The MCP server refuses a plain-http OAuth issuer except on localhost." $url) -}} +{{- end -}} +{{- end -}} {{- end }} {{/* diff --git a/chart/templates/configmap-nginx.yaml b/chart/templates/configmap-nginx.yaml index e859abc..478b5f6 100644 --- a/chart/templates/configmap-nginx.yaml +++ b/chart/templates/configmap-nginx.yaml @@ -70,6 +70,54 @@ data: proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } + {{- if .Values.mcp.enabled }} + + # MCP server for external agents. The /mcp prefix must not be stripped: the MCP server + # derives its OAuth resource identifier from it. + location /mcp { + proxy_pass {{ include "openops.mcpServiceUrl" . }}; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # --- MCP streaming-specific settings --- + proxy_buffering off; + proxy_cache off; + chunked_transfer_encoding on; + proxy_read_timeout 300s; # long-running tool calls + } + + # OAuth protected-resource metadata (RFC 9728) served by the MCP server at the origin root. + location /.well-known/oauth-protected-resource { + proxy_pass {{ include "openops.mcpServiceUrl" . }}; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # OAuth authorization-server discovery for the API issuer /api. Without these + # the catch-all serves the frontend's index.html. The API registers both the bare path and + # the "/api"-suffixed variant, and a prefix proxy_pass keeps the suffix, so both resolve. + location /.well-known/oauth-authorization-server { + proxy_pass {{ include "openops.appServiceUrl" . }}/api/.well-known/oauth-authorization-server; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /.well-known/openid-configuration { + proxy_pass {{ include "openops.appServiceUrl" . }}/api/.well-known/openid-configuration; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + {{- end }} + location /openops-analytics { proxy_pass {{ include "openops.analyticsServiceUrl" . }}; proxy_set_header Host $host; diff --git a/chart/templates/deployment-mcp.yaml b/chart/templates/deployment-mcp.yaml new file mode 100644 index 0000000..ef3a220 --- /dev/null +++ b/chart/templates/deployment-mcp.yaml @@ -0,0 +1,82 @@ +{{- if .Values.mcp.enabled }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Values.mcp.name }} + labels: + {{- include "openops.componentLabels" (dict "root" . "component" "mcp") | nindent 4 }} + {{- with .Values.global.commonLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.global.commonAnnotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if not .Values.mcp.autoscaling.enabled }} + replicas: {{ .Values.mcp.replicas }} + {{- end }} + {{- include "openops.deploymentStrategy" . | nindent 2 }} + selector: + matchLabels: + {{- include "openops.componentSelectorLabels" (dict "root" . "component" "mcp") | nindent 6 }} + template: + metadata: + labels: + {{- include "openops.componentSelectorLabels" (dict "root" . "component" "mcp") | nindent 8 }} + {{- with .Values.global.commonLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + annotations: + {{- include "openops.prometheusAnnotations" (dict "root" . "component" "mcp") | nindent 8 }} + {{- with include "openops.secretChecksum" . }} + checksum/secret-env: {{ . }} + {{- end }} + {{- with .Values.global.commonAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "openops.serviceAccountName" (dict "root" . "component" "mcp") }} + {{- include "openops.imagePullSecrets" . | nindent 6 }} + {{- include "openops.podSecurityContext" (dict "root" . "component" "mcp") | nindent 6 }} + {{- include "openops.priorityClassName" . | nindent 6 }} + {{- include "openops.terminationGracePeriodSeconds" . | nindent 6 }} + {{- include "openops.topologySpreadConstraints" (dict "root" . "component" "mcp") | nindent 6 }} + {{- include "openops.affinity" (dict "root" . "component" "mcp") | nindent 6 }} + {{- include "openops.nodeSelector" . | nindent 6 }} + {{- include "openops.tolerations" . | nindent 6 }} + {{- include "openops.initContainers" (dict "root" . "component" "mcp") | nindent 6 }} + containers: + - name: {{ .Values.mcp.name }} + image: "{{ include "openops.imageRepository" (dict "root" . "component" "mcp") }}/{{ .Values.mcp.image }}:{{ .Values.mcp.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- include "openops.containerSecurityContext" (dict "root" .) | nindent 10 }} + # Only the MCP-specific env is rendered here. The shared openopsEnv/openopsEnvSecrets + # layers carry database and admin credentials this pod must never receive. + env: + {{- include "openops.renderEnv" (dict "root" . "env" .Values.mcp.env) | trim | nindent 12 }} + ports: + - containerPort: {{ .Values.mcp.port }} + name: http +{{- with .Values.mcp.resources }} + resources: +{{ toYaml . | nindent 12 }} +{{- end }} + # The server exposes no health route. The OAuth protected-resource metadata answers + # 200 without a token, and the process only listens once its startup fetch of the + # OpenAPI document from the API has succeeded, so this doubles as a readiness signal. + {{- include "openops.startupProbe" (dict "path" "/.well-known/oauth-protected-resource/mcp" "port" .Values.mcp.port) | nindent 10 }} + readinessProbe: + httpGet: + path: /.well-known/oauth-protected-resource/mcp + port: {{ .Values.mcp.port }} + initialDelaySeconds: 5 + periodSeconds: 10 + livenessProbe: + httpGet: + path: /.well-known/oauth-protected-resource/mcp + port: {{ .Values.mcp.port }} + initialDelaySeconds: 30 + periodSeconds: 30 + {{- include "openops.lifecyclePreStop" . | nindent 10 }} +{{- end }} diff --git a/chart/templates/external-secret.yaml b/chart/templates/external-secret.yaml index 2030451..e55f1f7 100644 --- a/chart/templates/external-secret.yaml +++ b/chart/templates/external-secret.yaml @@ -74,5 +74,9 @@ spec: {{- if .Values.worker }}{{- if .Values.worker.env }} {{- range $k, $v := .Values.worker.env }}{{ if not (hasKey $allEnv $k) }}{{ $_ := set $allEnv $k ($v | toString) }}{{ end }}{{ end }} {{- end }}{{- end }} +{{- /* Gated on mcp.enabled: External Secrets fails the whole sync on a missing property */ -}} +{{- if .Values.mcp.enabled }} +{{- range $k, $v := .Values.mcp.env }}{{ if not (hasKey $allEnv $k) }}{{ $_ := set $allEnv $k ($v | toString) }}{{ end }}{{ end }} +{{- end }} {{- include "openops.collectSecretEntries" (dict "root" $ "env" $allEnv "secretName" .Values.externalSecrets.secretName) }} {{- end }} diff --git a/chart/templates/hpa-mcp.yaml b/chart/templates/hpa-mcp.yaml new file mode 100644 index 0000000..496507d --- /dev/null +++ b/chart/templates/hpa-mcp.yaml @@ -0,0 +1,35 @@ +{{- if and .Values.mcp.enabled .Values.mcp.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ .Values.mcp.name }}-hpa + labels: + {{- include "openops.componentLabels" (dict "root" . "component" "mcp") | nindent 4 }} + {{- with .Values.global.commonLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ .Values.mcp.name }} + minReplicas: {{ .Values.mcp.autoscaling.minReplicas }} + maxReplicas: {{ .Values.mcp.autoscaling.maxReplicas }} + metrics: + {{- if .Values.mcp.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.mcp.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.mcp.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.mcp.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/chart/templates/networkpolicy.yaml b/chart/templates/networkpolicy.yaml index 6a4eccf..5f23b64 100644 --- a/chart/templates/networkpolicy.yaml +++ b/chart/templates/networkpolicy.yaml @@ -273,6 +273,55 @@ spec: ports: - protocol: TCP port: 8088 + {{- if .Values.mcp.enabled }} + - to: + - podSelector: + matchLabels: + app.kubernetes.io/component: mcp + ports: + - protocol: TCP + port: {{ .Values.mcp.port }} + {{- end }} + - to: + - namespaceSelector: {} + ports: + - protocol: TCP + port: 53 + - protocol: UDP + port: 53 +{{- if .Values.mcp.enabled }} +--- +# Network policy for mcp: reachable only from nginx; talks to the app (API + OAuth token +# exchange), DNS, and 443 for optional log shipping. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: {{ .Values.mcp.name }}-netpol + labels: + {{- include "openops.componentLabels" (dict "root" . "component" "mcp") | nindent 4 }} +spec: + podSelector: + matchLabels: + {{- include "openops.componentSelectorLabels" (dict "root" . "component" "mcp") | nindent 6 }} + policyTypes: + - Ingress + - Egress + ingress: + - from: + - podSelector: + matchLabels: + app.kubernetes.io/component: nginx + ports: + - protocol: TCP + port: {{ .Values.mcp.port }} + egress: + - to: + - podSelector: + matchLabels: + app.kubernetes.io/component: app + ports: + - protocol: TCP + port: 80 - to: - namespaceSelector: {} ports: @@ -280,6 +329,12 @@ spec: port: 53 - protocol: UDP port: 53 + - to: + - namespaceSelector: {} + ports: + - protocol: TCP + port: 443 +{{- end }} --- # Network policy for postgres apiVersion: networking.k8s.io/v1 diff --git a/chart/templates/pdb-mcp.yaml b/chart/templates/pdb-mcp.yaml new file mode 100644 index 0000000..359de5a --- /dev/null +++ b/chart/templates/pdb-mcp.yaml @@ -0,0 +1,20 @@ +{{- if and .Values.mcp.enabled .Values.mcp.podDisruptionBudget.enabled }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ .Values.mcp.name }}-pdb + labels: + {{- include "openops.componentLabels" (dict "root" . "component" "mcp") | nindent 4 }} + {{- with .Values.global.commonLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if not (kindIs "invalid" .Values.mcp.podDisruptionBudget.maxUnavailable) }} + maxUnavailable: {{ .Values.mcp.podDisruptionBudget.maxUnavailable }} + {{- else }} + minAvailable: {{ .Values.mcp.podDisruptionBudget.minAvailable | default 1 }} + {{- end }} + selector: + matchLabels: + {{- include "openops.componentSelectorLabels" (dict "root" . "component" "mcp") | nindent 6 }} +{{- end }} diff --git a/chart/templates/secret-env.yaml b/chart/templates/secret-env.yaml index 926b7a2..f6eefb2 100644 --- a/chart/templates/secret-env.yaml +++ b/chart/templates/secret-env.yaml @@ -11,6 +11,9 @@ {{- if and $create (not $existingSecret) -}} {{- $autoSecretData := dict -}} {{- $envSources := list .Values.openopsEnvSecrets .Values.openopsEnv .Values.worker.env .Values.tables.env .Values.analytics.env .Values.postgres.env -}} +{{- if .Values.mcp.enabled }} +{{- $envSources = append $envSources .Values.mcp.env -}} +{{- end }} {{- range $env := $envSources }} {{- if $env }} {{- range $k, $v := $env }} diff --git a/chart/templates/service-mcp.yaml b/chart/templates/service-mcp.yaml new file mode 100644 index 0000000..e39cec9 --- /dev/null +++ b/chart/templates/service-mcp.yaml @@ -0,0 +1,17 @@ +{{- if .Values.mcp.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.mcp.name }} + labels: + {{- include "openops.componentLabels" (dict "root" . "component" "mcp") | nindent 4 }} +spec: + type: ClusterIP + ports: + - port: {{ .Values.mcp.port }} + targetPort: {{ .Values.mcp.port }} + protocol: TCP + name: http + selector: + {{- include "openops.componentSelectorLabels" (dict "root" . "component" "mcp") | nindent 4 }} +{{- end }} diff --git a/chart/templates/serviceaccount-mcp.yaml b/chart/templates/serviceaccount-mcp.yaml new file mode 100644 index 0000000..b7a1343 --- /dev/null +++ b/chart/templates/serviceaccount-mcp.yaml @@ -0,0 +1,15 @@ +{{- if and .Values.mcp.enabled .Values.mcp.serviceAccount.create }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "openops.serviceAccountName" (dict "root" . "component" "mcp") }} + labels: + {{- include "openops.componentLabels" (dict "root" . "component" "mcp") | nindent 4 }} + {{- with .Values.global.commonLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.mcp.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/chart/values.ci.yaml b/chart/values.ci.yaml index 3f82918..e5a40e2 100644 --- a/chart/values.ci.yaml +++ b/chart/values.ci.yaml @@ -53,6 +53,21 @@ worker: cpu: "300m" memory: "768Mi" +# MCP stays disabled in CI: the default image is in a private registry the kind cluster +# cannot pull from. Rendering with MCP enabled is covered by values.mcp-example.yaml. +mcp: + enabled: false + replicas: 1 + podDisruptionBudget: + enabled: false + resources: + requests: + cpu: "50m" + memory: "128Mi" + limits: + cpu: "200m" + memory: "256Mi" + analytics: replicas: 1 podDisruptionBudget: diff --git a/chart/values.mcp-example.yaml b/chart/values.mcp-example.yaml new file mode 100644 index 0000000..07f6922 --- /dev/null +++ b/chart/values.mcp-example.yaml @@ -0,0 +1,28 @@ +# Example overlay enabling the MCP server for external agents. +# Used by CI to validate rendering with MCP on; copy the relevant keys into your own overrides. +# Make sure to regenerate passwords and secrets. + +global: + publicUrl: "https://openops.example.com" # must be https (or http://localhost) + +openopsEnv: + OPS_OPENOPS_ADMIN_EMAIL: openops@example.com + +openopsEnvSecrets: + OPS_OPENOPS_ADMIN_PASSWORD: 9wqhK7jehmxAQlre + OPS_ENCRYPTION_KEY: 7de996f020438444dc2c79e9b843805d + OPS_JWT_SECRET: M72yCOp9riLjIDws + OPS_POSTGRES_PASSWORD: WZKUM0tSvFC6VWai + OPS_ANALYTICS_ADMIN_PASSWORD: 7YO7YEVRaECPQimI + ANALYTICS_POWERUSER_PASSWORD: v5vIvwhdBDWwx4el + # Shared between the API (resource-server credentials) and the MCP pod. openssl rand -hex 32 + OPS_OAUTH_RS_CLIENT_SECRET: 4c1f0f6a2c3b4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6 + +mcp: + enabled: true + +ingress: + enabled: true + ingressClassName: nginx + tlsConfig: + enabled: true diff --git a/chart/values.schema.json b/chart/values.schema.json index 0a1df5a..6531304 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -75,6 +75,39 @@ } } }, + "mcp": { + "type": "object", + "required": ["enabled", "name", "image", "tag", "port", "replicas"], + "properties": { + "enabled": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "image": { + "type": "string" + }, + "repository": { + "type": "string", + "description": "Override global image.repository for mcp (empty = use global)" + }, + "tag": { + "type": "string", + "minLength": 1, + "description": "MCP image tag; versioned independently of global.version" + }, + "port": { + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "replicas": { + "type": "integer", + "minimum": 0 + } + } + }, "tables": { "type": "object", "required": ["name", "image", "tag", "replicas"], diff --git a/chart/values.yaml b/chart/values.yaml index a2a70d5..67366ff 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -110,6 +110,12 @@ openopsEnv: OPS_WORKER_URL: '{{ include "openops.workerServiceUrl" . }}' OPS_EXECUTION_MODE: SANDBOX_CODE_ONLY + # OAuth for external agents (MCP). Derived from mcp.enabled and global.publicUrl so the API + # and the MCP pod always agree on issuer and resource. See the "mcp" section below. + OPS_OAUTH_ENABLED: '{{ .Values.mcp.enabled }}' + OPS_OAUTH_ISSUER_URL: '{{ include "openops.publicUrl" . }}/api' + OPS_MCP_RESOURCE_URL: '{{ include "openops.publicUrl" . }}/mcp' + # Queue OPS_QUEUE_MODE: REDIS OPS_REDIS_URL: '{{ include "openops.redisUrl" . }}' @@ -167,6 +173,10 @@ openopsEnvSecrets: OPS_LANGFUSE_PUBLIC_KEY: "" OPS_LANGFUSE_SECRET_KEY: "" OPS_SSO_FRONTEGG_PUBLIC_KEY: "" + # When mcp.enabled is true, declare OPS_OAUTH_RS_CLIENT_SECRET here (openssl rand -hex 32). + # It is intentionally not a default: External Secrets fails the whole sync when a requested + # property is missing, so adding it unconditionally would break installs that keep MCP off. + # OPS_OAUTH_RS_CLIENT_SECRET: "" secretEnv: create: true @@ -253,6 +263,62 @@ worker: OPS_BASE_CODE_DIRECTORY: /tmp/codes OPS_SERVER_API_URL: '{{ printf "%s/api/" (include "openops.appServiceUrl" .) }}' +# MCP server for external agents (Claude Code, Codex, ...). Opt-in: serves /mcp +# through nginx and authenticates agents with OAuth issued by the OpenOps API. Enabling it +# requires an https global.publicUrl (or localhost) and OPS_OAUTH_RS_CLIENT_SECRET in +# openopsEnvSecrets (at least 32 characters, shared with the API). +mcp: + enabled: false + name: openops-mcp + image: openops-mcp + # Main-branch builds live in the private registry until the first public release; the + # public image will be openops.azurecr.io/openops-mcp:. Pulling from the private + # registry needs pull access on the cluster (imagePullSecrets or a registry role). + repository: "openopsprivate.azurecr.io" + tag: "8e7c930f" # Independently versioned (8-char commit sha or release version), not global.version + port: 3020 + replicas: 2 # Stateless; any replica serves any request + resources: + requests: + memory: "256Mi" + cpu: "100m" + limits: + memory: "512Mi" + cpu: "500m" + # Pod Disruption Budget - ENABLED BY DEFAULT + podDisruptionBudget: + enabled: true + maxUnavailable: 1 + # Horizontal Pod Autoscaler + autoscaling: + enabled: false + minReplicas: 2 + maxReplicas: 10 + targetCPUUtilizationPercentage: 80 + targetMemoryUtilizationPercentage: 80 + # Init containers (optional) + initContainers: [] + # Service Account + serviceAccount: + create: true + name: "" + annotations: {} + # No "metrics" map: the server exposes no /metrics endpoint. Add one (enabled/port/path) + # and a ServiceMonitor block once it does; the Prometheus annotations helper skips + # components without it. + # Only these variables reach the MCP pod; openopsEnv/openopsEnvSecrets are not injected. + # Values referencing .Values.openopsEnvSecrets.* are sourced from the shared Secret. + env: + MCP_HTTP_PORT: '{{ .Values.mcp.port }}' + OPENOPS_API_URL: '{{ include "openops.appServiceUrl" . }}/api' + OPENOPS_MCP_PROFILE: agent + OPENOPS_MCP_ISSUER: '{{ .Values.openopsEnv.OPS_OAUTH_ISSUER_URL }}' + OPENOPS_MCP_RESOURCE_URL: '{{ .Values.openopsEnv.OPS_MCP_RESOURCE_URL }}' + OPENOPS_MCP_CLIENT_SECRET: '{{ .Values.openopsEnvSecrets.OPS_OAUTH_RS_CLIENT_SECRET }}' + LOG_LEVEL: '{{ .Values.openopsEnv.OPS_LOG_LEVEL }}' + ENVIRONMENT: '{{ .Values.openopsEnv.OPS_ENVIRONMENT_NAME }}' + LOGZIO_TOKEN: '{{ .Values.openopsEnvSecrets.OPS_LOGZIO_TOKEN }}' + tables: name: openops-tables image: openops-tables