Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript
26.6 KB
Raw Blame
# ─── L0: Default deny all traffic ─────────────────────────────────────────────
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: deny-all-control-plane
  namespace: control-plane
  labels:
    clerum.io/policy-type: default-deny
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress
---
# ─── L1: DNS egress (all pods) ────────────────────────────────────────────────
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-dns-egress-control-plane
  namespace: control-plane
  labels:
    clerum.io/policy-type: infrastructure
spec:
  podSelector: {}
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 53
      protocol: UDP
    - port: 53
      protocol: TCP
    to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: kube-system
---
# ─── L1: K8s API egress (operators: HCC, WRC, control-api) ──────────────────
# HCC and WRC manage CRDs/pods across namespaces via the K8s API server.
# Unlike runtime namespaces (mcp-server, mcp-host, rpc-proxy, sandbox-recipes)
# where HCC self-manages this policy via KUBERNETES_SERVICE_HOST, HCC does NOT
# reconcile its own namespace — so this policy must be declared statically here.
# The CIDR below is a placeholder (DO cluster). Each overlay MUST patch it with
# the target cluster's actual K8s API IP:
#   kubectl get svc kubernetes -o jsonpath='{.spec.clusterIP}'
# GCP overlay: deploy/overlays/gcp/patches/k8s-api-ip.yaml
#
# NOTE: NetworkPolicy enforcement may not be enabled on all clusters. If the
# cluster's CNI doesn't enforce policies, this rule is decorative. Verify with:
#   gcloud container clusters describe <name> --format="value(addonsConfig.networkPolicyConfig.disabled)"
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-k8s-api-egress-control-plane
  namespace: control-plane
  labels:
    clerum.io/policy-type: infrastructure
spec:
  podSelector:
    matchExpressions:
    - key: app
      operator: In
      values: [host-context-controller, workflow-recipes, control-api, trace-maintenance-worker]
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 443
      protocol: TCP
    to:
    - ipBlock:
        cidr: 10.109.0.1/32
---
# ─── L2: control-api ↔ control-postgres (database) ───────────────────────────
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-api-to-postgres
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchExpressions:
    - key: app
      operator: In
      values: [control-api, trace-maintenance-worker]
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 5432
      protocol: TCP
    to:
    - podSelector:
        matchLabels:
          app: control-postgres
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-postgres-from-control-api
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-postgres
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchExpressions:
        - key: app
          operator: In
          values: [control-api, trace-maintenance-worker]
    ports:
    - port: 5432
      protocol: TCP
---
# ─── gfs: gfsc (gfs namespace) → control-postgres (permission store) ──────────
# gfsc re-checks the permission store on every op and fails closed (503) if it
# is unreachable; its /readyz pings Postgres. This is CROSS-namespace (gfsc lives
# in `gfs`), so the from-rule needs namespaceSelector + podSelector. gfsc's own
# egress allow is created by HCC's gfsReconciler; this is the matching ingress on
# the control-postgres side. Without it deny-all-control-plane blocks TCP:5432
# and gfsc CrashLoops on a /readyz startup-probe timeout.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-postgres-from-gfs-controller
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-postgres
  policyTypes:
  - Ingress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: gfs
      podSelector:
        matchLabels:
          app: gfs-controller
    ports:
    - port: 5432
      protocol: TCP
---
# ─── gfs: control-api → gfsc (gfs namespace) data plane ──────────────────────
# control-api reverse-proxies operator (routes/gfs/proxy.ts) AND end-user
# Session-JWT (routes/external/gfs.ts proxyReadToGfsc) reads to gfsc over HTTP
# on :8087. This is CROSS-namespace (gfsc lives in `gfs`), so the to-rule needs
# namespaceSelector + podSelector. gfsc's matching ingress (gfsc-ingress, from
# control-api) is created by HCC's gfsReconciler. Without this egress,
# deny-all-control-plane blocks TCP:8087 and every control-api→gfsc fetch fails
# ("fetch failed" → 500 on /gfs/proxy/* and /external/gfs/{resolve,children,proxy}).
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-api-to-gfsc
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-api
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 8087
      protocol: TCP
    to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: gfs
      podSelector:
        matchLabels:
          app: gfs-controller
---
# ─── Phase 4/5 DB-first: workflow-recipes ↔ control-postgres ──────────────────
# WRC opens a sticky Postgres session for: pg_advisory_lock leader election,
# LISTEN workflow_run_update, schedule worker polls, archive cron, run processor.
# Without these NPs, the deny-all-control-plane policy blocks TCP:5432 and the
# WRC logs show "LISTEN attach failed — connection timeout" on every reconnect.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: workflow-recipes-to-postgres
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: workflow-recipes
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 5432
      protocol: TCP
    to:
    - podSelector:
        matchLabels:
          app: control-postgres
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-postgres-from-workflow-recipes
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-postgres
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: workflow-recipes
    ports:
    - port: 5432
      protocol: TCP
---
# ─── L2: control-api ingress from profiles + internal services ────────────────
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-api-ingress
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-api
  policyTypes:
  - Ingress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: profiles
      podSelector:
        matchLabels:
          app: profile-control-funnel
    - podSelector:
        matchLabels:
          app: control-api-rpc-gateway
    - podSelector:
        matchLabels:
          app: control-ui
    - podSelector:
        matchLabels:
          app: nginx-workflow-approval-gateway
    # UAR §12 + D11: provisioners (WRC + HCC) call control-api:8090
    # directly for approval-token issuance. mcp-host pods do NOT — they
    # always traverse the approval gateway above.
    - podSelector:
        matchLabels:
          app: workflow-recipes
    - podSelector:
        matchLabels:
          app: host-context-controller
    # webhook-proxy → control-api for the webhook registry endpoint
    # (/api/v1/internal/webhook/registry/...). Authenticated with the
    # `webhook-proxy` internal-service token.
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: webhook-ingress
      podSelector:
        matchLabels:
          app: webhook-proxy
    # workflow-approval-request-reader → control-api for the Figure D
    # cross-bot can-approve consulta endpoint
    # (/api/v1/internal/workflow-approval-reader/approvals/:id/can-approve).
    # Authenticated with the `workflow-approval-reader` internal-service token.
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: channels
      podSelector:
        matchLabels:
          app.kubernetes.io/name: workflow-approval-request-reader
    # Path B — background-OAuth workloads in sandbox-recipes reach the broker
    # route POST /api/v1/recipe-oauth/token. Restricted to opted-in workloads
    # via the matching egress NP `wf-<recipe>-oauth-broker-egress` that WRC
    # emits per recipe; the route's own `requireBrokerToken` middleware
    # (strict aud=oauth-broker, sub=recipe binding) is the real auth gate.
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: sandbox-recipes
      podSelector:
        matchLabels:
          clerum.io/oauth-broker-client: "true"
    ports:
    - port: 8090
      protocol: TCP
---
# ─── L2: control-ui ingress from the cloudflared tunnel + egress to control-api
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-ui-network
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-ui
  policyTypes:
  - Ingress
  - Egress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: ingress
      podSelector:
        matchLabels:
          app: cloudflared
    ports:
    - port: 3000
      protocol: TCP
  egress:
  - ports:
    - port: 8090
      protocol: TCP
    to:
    - podSelector:
        matchLabels:
          app: control-api
---
# ─── L2: control-api → external OAuth (Google token validation) ───────────────
# OAuth/OIDC endpoints can resolve to dynamic public IPs. This policy allows
# public internet only. The ipBlock.except list below is not a hardcoded provider
# allowlist; it excludes private, metadata, link-local, loopback, documentation,
# benchmarking, multicast, and reserved ranges.
# Scope is rule-level: control-api still reaches Postgres, WRC,
# member-registration-service, and workspace-files-controller through separate
# internal policies.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-api-external-egress
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-api
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 443
      protocol: TCP
    to:
    - ipBlock:
        cidr: 0.0.0.0/0
        except: []
---
# Mirror of control-api-external-egress for WRC: needed so workflow-recipes can
# reach registry.evenfire.ai (anycast hostname, app-layer pinning). The
# ipBlock.except list excludes non-public/reserved ranges; it is not a hardcoded
# provider IP list.
# Scope is rule-level: WRC still reaches Postgres, the K8s API, sandbox-recipes,
# and control-api through separate internal policies.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: workflow-recipes-external-egress
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: workflow-recipes
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 443
      protocol: TCP
    to:
    - ipBlock:
        cidr: 0.0.0.0/0
        except: []
---
# ─── L2 (existing): control-api-rpc-gateway ──────────────────────────────────
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-api-rpc-gateway
  namespace: control-plane
spec:
  podSelector:
    matchLabels:
      app: control-api-rpc-gateway
  policyTypes:
  - Ingress
  - Egress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: rpc-proxy
      podSelector:
        matchLabels:
          app: rpc-proxy
    - podSelector:
        matchLabels:
          app: codex-llm-proxy
    - podSelector:
        matchLabels:
          app: grok-llm-proxy
    ports:
    - port: 8090
      protocol: TCP
  egress:
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: control-plane
      podSelector:
        matchLabels:
          app: control-api
    ports:
    - port: 8090
      protocol: TCP
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: kube-system
      podSelector:
        matchLabels:
          k8s-app: kube-dns
    ports:
    - port: 53
      protocol: UDP
    - port: 53
      protocol: TCP
---
# ─── L2: nginx-workflow-approval-gateway ──────────────────────────────────────
# Allows workflow mcp-host pods (sandbox-recipes) to call the bounded
# approval/auth/usage/tracing endpoints exposed by this nginx gateway, which
# proxies to control-api:8090.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: nginx-workflow-approval-gateway
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: nginx-workflow-approval-gateway
  policyTypes:
  - Ingress
  - Egress
  ingress:
  - from:
    # Recipe-hosted mcp-host pods in sandbox-recipes.
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: sandbox-recipes
      podSelector:
        matchLabels:
          clerum.io/component: workflow-mcp-host
    # Shared mcp-host pods provisioned by HCC.
    # Required complement to the egress rule in
    # deploy/base/mcp-host/networkpolicies.yaml; without this ingress the
    # /workflow-approvals/request, /:id/status, /:id/cancel, /workflow-auth/refresh,
    # /workflow-auth/reissue runtime calls would be blocked when NP enforcement
    # is enabled.
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: mcp-host
      podSelector:
        matchLabels:
          clerum.io/managed-by: host-context-controller
    ports:
    - port: 8092
      protocol: TCP
  egress:
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: control-plane
      podSelector:
        matchLabels:
          app: control-api
    ports:
    - port: 8090
      protocol: TCP
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: kube-system
      podSelector:
        matchLabels:
          k8s-app: kube-dns
    ports:
    - port: 53
      protocol: UDP
    - port: 53
      protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: host-context-controller-api-direct
  namespace: control-plane
spec:
  podSelector:
    matchLabels:
      app: host-context-controller
  policyTypes:
  - Ingress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: control-plane
      podSelector:
        matchLabels:
          app: host-context-controller-api-gateway
    ports:
    - port: 8081
      protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: host-context-controller-api-gateway
  namespace: control-plane
spec:
  podSelector:
    matchLabels:
      app: host-context-controller-api-gateway
  policyTypes:
  - Ingress
  - Egress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: mcp-host
      podSelector:
        matchLabels:
          clerum.io/managed-by: host-context-controller
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: mcp-server
      podSelector:
        matchLabels:
          app: mcp-proxy
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: rpc-proxy
      podSelector:
        matchLabels:
          app: rpc-proxy
    ports:
    - port: 8081
      protocol: TCP
  egress:
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: control-plane
      podSelector:
        matchLabels:
          app: host-context-controller
    ports:
    - port: 8081
      protocol: TCP
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: kube-system
      podSelector:
        matchLabels:
          k8s-app: kube-dns
    ports:
    - port: 53
      protocol: UDP
    - port: 53
      protocol: TCP
---
# Allow control-api to reach WRC for artifact download proxy and recipe
# operations. Both services are in control-plane but deny-all blocks
# intra-namespace traffic by default.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-api-to-wrc
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-api
  policyTypes:
    - Egress
  egress:
    - to:
        - podSelector:
            matchLabels:
              app: workflow-recipes
      ports:
        - port: 8082
          protocol: TCP
---
# Allow control-api catalog/health admin calls to the Codex LLM proxy.
# deny-all-control-plane blocks intra-namespace traffic; proxy ingress already
# admits control-api:8081, but control-api egress must match.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-api-to-codex-llm-proxy
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-api
  policyTypes:
    - Egress
  egress:
    - to:
        - podSelector:
            matchLabels:
              app: codex-llm-proxy
      ports:
        - port: 8081
          protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-api-to-grok-llm-proxy
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: control-api
  policyTypes:
    - Egress
  egress:
    - to:
        - podSelector:
            matchLabels:
              app: grok-llm-proxy
      ports:
        - port: 8081
          protocol: TCP
---
# Ingress side: allow control-api to reach WRC
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: wrc-from-control-api
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: workflow-recipes
  policyTypes:
    - Ingress
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: control-api
      ports:
        - port: 8082
          protocol: TCP
---
# Allow workflow coordinators and SDK-enabled workflow mcp-hosts
# (sandbox-recipes) to reach WRC. Coordinators report status/configure models;
# mcp-hosts redeem one signed prompt target credential per attempt. Per-recipe egress NPs are
# created dynamically by WRC in sandbox-recipes; this static NP opens
# the ingress side in control-plane (WRC cannot self-modify its own ns).
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-coordinator-to-wrc-ingress
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: workflow-recipes
  policyTypes:
    - Ingress
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: sandbox-recipes
          podSelector:
            matchLabels:
              clerum.io/component: workflow-coordinator
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: sandbox-recipes
          podSelector:
            matchLabels:
              clerum.io/component: workflow-mcp-host
      ports:
        - port: 8082
          protocol: TCP
---
# Allow WRC to reach workflow mcp-host pods for /configure + artifacts and
# workflow-artifact-reader pods for pure workflow artifacts. Per-recipe
# ingress NPs in sandbox-recipes are created dynamically; this static NP opens
# the egress side from control-plane.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-wrc-to-sandbox-mcp-host
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: workflow-recipes
  policyTypes:
    - Egress
  egress:
    - to:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: sandbox-recipes
      ports:
        - port: 8080
          protocol: TCP
---
# Allow WRC to mint mcpHost credentials through the control-api issuance lane
# before sandbox mcp-host pods exist, so this egress path must be opened
# explicitly in control-plane.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-wrc-to-control-api
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: workflow-recipes
  policyTypes:
    - Egress
  egress:
    - to:
        - podSelector:
            matchLabels:
              app: control-api
      ports:
        - port: 8090
          protocol: TCP
---
# HCC issues runtime approval tokens by calling the control-api directly with
# InternalControl JWT. Shared host pods never reach control-api directly; they
# go via nginx-workflow-approval-gateway at runtime. This egress is for the HCC
# controller pod itself.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-hcc-to-control-api
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: host-context-controller
  policyTypes:
    - Egress
  egress:
    - to:
        - podSelector:
            matchLabels:
              app: control-api
      ports:
        - port: 8090
          protocol: TCP
---
# Allow control-api to reach per-SharedFileSystem workspace-files-controller pods
# in the mcp-host namespace. Used by the admin shared-filesystems proxy.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: control-api-to-wfc
  namespace: control-plane
  labels:
    clerum.io/policy-type: allow-egress
spec:
  podSelector:
    matchLabels:
      app: control-api
  policyTypes:
    - Egress
  egress:
    - to:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: mcp-host
          podSelector:
            matchLabels:
              app: workspace-files-controller
      ports:
        - port: 8086
          protocol: TCP
---
# Codex LLM proxy: runtime from eligible mcp-host pods, admin from Control API,
# metrics from monitoring. No sibling or namespace-wide ingress.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: codex-llm-proxy-ingress
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: codex-llm-proxy
  policyTypes:
  - Ingress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: mcp-host
      podSelector:
        matchLabels:
          clerum.io/managed-by: host-context-controller
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: sandbox-recipes
      podSelector:
        matchLabels:
          clerum.io/component: workflow-mcp-host
    ports:
    - port: 8080
      protocol: TCP
  - from:
    - podSelector:
        matchLabels:
          app: control-api
    ports:
    - port: 8081
      protocol: TCP
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: monitoring
    ports:
    - port: 9090
      protocol: TCP
---
# Codex LLM proxy egress: DNS is inherited from allow-dns-egress-control-plane.
# This policy adds only the RPC gateway redeem/finalize hop and public HTTPS
# with the canonical private/special-use exclusions. Direct Control API,
# Postgres, Kubernetes API, metadata, HCC/WRC, and sibling hops stay denied.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: codex-llm-proxy-egress
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: codex-llm-proxy
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 8090
      protocol: TCP
    to:
    - podSelector:
        matchLabels:
          app: control-api-rpc-gateway
  - ports:
    - port: 443
      protocol: TCP
    to:
    - ipBlock:
        cidr: 0.0.0.0/0
        # Filled at deploy time by deploy/base/kustomization.yaml replacements
        # from PublicEgressExceptionSet. Keep empty here.
        except: []
---
# Grok LLM proxy: runtime from eligible mcp-host pods, admin from Control API,
# metrics from monitoring. No sibling or namespace-wide ingress.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: grok-llm-proxy-ingress
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: grok-llm-proxy
  policyTypes:
  - Ingress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: mcp-host
      podSelector:
        matchLabels:
          clerum.io/managed-by: host-context-controller
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: sandbox-recipes
      podSelector:
        matchLabels:
          clerum.io/component: workflow-mcp-host
    ports:
    - port: 8080
      protocol: TCP
  - from:
    - podSelector:
        matchLabels:
          app: control-api
    ports:
    - port: 8081
      protocol: TCP
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: monitoring
    ports:
    - port: 9090
      protocol: TCP
---
# Grok LLM proxy egress: DNS is inherited from allow-dns-egress-control-plane.
# This policy adds only the RPC gateway redeem/finalize hop and public HTTPS
# with the canonical private/special-use exclusions. Direct Control API,
# Postgres, Kubernetes API, metadata, HCC/WRC, and sibling hops stay denied.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: grok-llm-proxy-egress
  namespace: control-plane
  labels:
    clerum.io/policy-type: service
spec:
  podSelector:
    matchLabels:
      app: grok-llm-proxy
  policyTypes:
  - Egress
  egress:
  - ports:
    - port: 8090
      protocol: TCP
    to:
    - podSelector:
        matchLabels:
          app: control-api-rpc-gateway
  - ports:
    - port: 443
      protocol: TCP
    to:
    - ipBlock:
        cidr: 0.0.0.0/0
        except: []