diff --git a/.changeset/worker-egress-hardening-1767.md b/.changeset/worker-egress-hardening-1767.md new file mode 100644 index 00000000..d4ee7345 --- /dev/null +++ b/.changeset/worker-egress-hardening-1767.md @@ -0,0 +1,5 @@ +--- +"secureflow": patch +--- + +feat(helm): [NSoC_2026] tighten worker pod egress rules and document required endpoints in deployment guide (#1767) diff --git a/README.md b/README.md index b5adabdc..6a9e053f 100644 --- a/README.md +++ b/README.md @@ -513,6 +513,7 @@ The architecture follows a modern Next.js full-stack approach with real-time Git For more in-depth details about the architecture, developer API, and security practices of SecureFlow, check out: - **[Local Development Setup](./docs/setup.md)**: Step-by-step guide to acquiring every credential (Prisma/PostgreSQL, Groq, GitHub App, GitHub OAuth/NextAuth, Redis) needed to run SecureFlow locally. +- **[Kubernetes Deployment & Egress Hardening](./docs/deployment.md)**: Production deployment architecture, zero-trust network policies, and egress rule whitelisting for backend worker pods. - **[System Blueprint](./docs/blueprint.md)**: Explains the application blueprint, core capabilities, style guidelines, visual tokens, and heist-themed copywriting dictionary. - **[API Reference](./docs/api.md)**: Provides exhaustive details on HTTP endpoints, authentication, rate limits, error formats, and system types. - **[AI Security & Prompt Injection Defense](./docs/security/prompt-injection.md)**: Documents the threat vector, policy isolation boundaries, pre-filtering layers, and UI indicators used to protect against LLM prompt injection attacks. diff --git a/docs/deployment.md b/docs/deployment.md new file mode 100644 index 00000000..38381fe9 --- /dev/null +++ b/docs/deployment.md @@ -0,0 +1,196 @@ +# SecureFlow Deployment & Egress Hardening Guide + +This guide documents production deployment architecture, security hardening practices, and the required network egress rules for running **SecureFlow** in enterprise Kubernetes environments. + +--- + +## 1. Architecture & Network Topology + +SecureFlow orchestrates multiple decoupled services in a production Kubernetes cluster: + +- **App Server (`app`)**: Next.js App Router providing web dashboard, REST APIs, and webhook ingress. +- **Backend Queue Workers (`worker`)**: Asynchronous worker pool processing static AST security analysis, SBOM generation, container vulnerability checks, LLM reasoning, and GitHub status synchronization. +- **Database Migrations (`migration`)**: Helm lifecycle hook running Prisma schema migrations. +- **Data Retention (`retention`)**: Kubernetes CronJob purging expired scan logs and telemetry. +- **Data Persistence**: PostgreSQL (in-cluster StatefulSet or managed RDS/Neon) and Redis (in-cluster StatefulSet or managed ElastiCache). + +``` + ┌──────────────────────┐ + │ Ingress / TLS │ + └──────────┬───────────┘ + │ + ┌───────────▼───────────┐ + │ App Pods (Next.js) │ + └─────┬───────────┬─────┘ + │ │ + Enqueues│ │Audit Logs + ▼ ▼ + ┌─────────────────────┐ ┌─────────────────────┐ + │ Redis Queue / DB │ │ PostgreSQL DB │ + └──────────▲──────────┘ └──────────▲──────────┘ + │ │ + │Dequeues Jobs │Persists Findings + │ │ + ┌─────┴───────────────────────────┴─────┐ + │ Worker Pods (BullMQ) │ + │ (Hardened Egress NetworkPolicy) │ + └───────────────────┬───────────────────┘ + │ + Default Deny Egress Except Whitelisted Endpoints + │ + ┌───────────────────────┼───────────────────────┐ + │ (TCP 443) │ (TCP 443) │ (UDP/TCP 53) + ▼ ▼ ▼ +┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ +│ LLM Providers │ │ Container / OCI │ │ Cluster DNS │ +│ (Groq, OpenAI) │ │ Registries (GHCR)│ │ (CoreDNS) │ +└──────────────────┘ └──────────────────┘ └──────────────────┘ +``` + +--- + +## 2. Worker Egress Hardening & Default-Deny Policy + +In standard Kubernetes installations, pod egress traffic is unrestricted by default (`allow-all`). If a container dependency or scanning job is exploited, unrestricted egress presents severe risks: +- Malicious exfiltration of source code or scanned repository secrets. +- Communication with Command and Control (C2) servers. +- Probing internal cluster services and cloud provider instance metadata endpoints (`169.254.169.254`). + +To eliminate these attack vectors, SecureFlow implements a **Zero-Trust Default-Deny Egress NetworkPolicy** for worker pods (`*-worker-egress`): +- All outbound traffic to public IP addresses and external networks is blocked by default. +- Worker pods can only communicate with internal cluster DNS and explicitly whitelisted API destinations. +- Cloud metadata endpoints (`169.254.169.254/32`, `168.63.129.16/32`) and private RFC 1918 subnets (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`) are strictly blocked and cannot be allowed via public egress blocks. + +--- + +## 3. Required Egress Traffic Rules Reference + +When deploying SecureFlow with `networkPolicy.enabled: true`, operators must configure the following egress rules depending on enabled features: + +| Target Destination | Purpose | Protocol & Port | Helm Configuration Parameter | Destination CIDR Notes | +| :--- | :--- | :--- | :--- | :--- | +| **Cluster DNS** (`kube-dns` / `CoreDNS`) | Resolves domain names for internal and external endpoints | UDP & TCP `53` | `networkPolicy.workerEgress.dns` | Targets `kube-system` namespace with label `k8s-app: kube-dns` (or your CNI DNS labels). | +| **In-Cluster PostgreSQL** | Internal database state & audit logs | TCP `5432` | `postgresql.enabled: true` | Automatically permitted to same-release PostgreSQL StatefulSet. | +| **In-Cluster Redis** | Asynchronous job queues | TCP `6379` | `redis.enabled: true` | Automatically permitted to same-release Redis StatefulSet. | +| **LLM Inference Providers** | The Professor AI security engine (Groq, OpenAI) | TCP `443` | `workerEgress.whitelistedEndpoints` | Groq `api.groq.com` (Cloudflare CDN CIDRs) or OpenAI `api.openai.com`. | +| **Container Registries** | Container image layer scanning and SBOM generation | TCP `443`, `8443` | `workerEgress.whitelistedEndpoints` | GitHub Container Registry `ghcr.io`, Docker Hub `registry-1.docker.io`, AWS ECR, Quay. | +| **GitHub API & VCS** | Webhook verification, commit checks, PR diffs | TCP `443` | `workerEgress.whitelistedEndpoints` | Public CIDRs from official [GitHub Meta API](https://api.github.com/meta). | +| **Managed Cloud DB (VPC)** | AWS RDS, Neon, Cloud SQL | TCP `5432` | `workerEgress.extraEgressRules` | Private database subnet CIDR within the VPC. | +| **Managed Cloud Cache (VPC)** | AWS ElastiCache, Upstash | TCP `6379` / `6380` | `workerEgress.extraEgressRules` | Private cache subnet CIDR within the VPC. | +| **Outbound Webhooks** | High-severity finding notifications (Slack, Discord) | TCP `443` | `workerEgress.whitelistedEndpoints` | Notification gateway IP ranges. | + +--- + +## 4. Production Helm Configuration Example + +Create a hardened `production-values.yaml`: + +```yaml +# Helm values for hardened production deployment +app: + replicaCount: 3 + resources: + limits: + cpu: 2000m + memory: 2048Mi + requests: + cpu: 500m + memory: 1024Mi + +worker: + replicaCount: 4 + concurrency: 10 + resources: + limits: + cpu: 2000m + memory: 2048Mi + requests: + cpu: 500m + memory: 1024Mi + +# External managed infrastructure +postgresql: + enabled: false + external: + host: "postgres.internal.vpc.local" + port: 5432 + database: "secureflow_prod" + username: "secureflow_user" + +redis: + enabled: false + external: + url: "rediss://:auth@redis.internal.vpc.local:6379/0" + +# Tightened NetworkPolicy configurations (#1767) +networkPolicy: + enabled: true + workerEgress: + whitelistedEndpoints: + - name: llm-providers + description: "Groq / OpenAI API endpoints for AI security analysis" + cidrs: + - "104.18.0.0/20" # Cloudflare range for api.groq.com + ports: [443] + + - name: container-registries + description: "Container registries for SBOM and vulnerability inspection" + cidrs: + - "140.82.112.0/20" # GitHub CIDR for ghcr.io + ports: [443] + + - name: github-api + description: "GitHub API and raw blob fetching for PR diffs" + cidrs: + - "140.82.112.0/20" + ports: [443] + + # Allow worker access to private VPC database and cache subnets + extraEgressRules: + - to: + - ipBlock: + cidr: "10.0.10.0/24" + ports: + - protocol: TCP + port: 5432 + - protocol: TCP + port: 6379 + + dns: + namespace: kube-system + podLabels: + k8s-app: kube-dns + ports: [53] +``` + +Deploy or upgrade the Helm release: + +```bash +helm upgrade --install secureflow ./helm/secureflow -f production-values.yaml +``` + +--- + +## 5. Verification & Diagnostics + +1. **Verify NetworkPolicies are applied**: + ```bash + kubectl get networkpolicy -l "app.kubernetes.io/instance=secureflow" + ``` + +2. **Inspect worker egress rules**: + ```bash + kubectl describe networkpolicy -worker-egress + ``` + +3. **Verify blocked egress from worker pods**: + ```bash + # Connection to unauthorized external IP or cloud metadata service should time out: + kubectl exec -it deployment/-worker -- curl --connect-timeout 3 http://169.254.169.254/latest/meta-data/ + ``` + +4. **Verify permitted egress to whitelisted endpoints**: + ```bash + # Connection to whitelisted provider endpoint should succeed: + kubectl exec -it deployment/-worker -- curl --connect-timeout 5 https://api.groq.com/openai/v1/models + ``` diff --git a/helm/secureflow/README.md b/helm/secureflow/README.md index 9beab17b..95612add 100644 --- a/helm/secureflow/README.md +++ b/helm/secureflow/README.md @@ -22,19 +22,53 @@ This chart provisions and orchestrates the complete SecureFlow topology: ## Quickstart -### Worker egress isolation +### Worker egress isolation & hardening (#1755, #1767) -`networkPolicy.enabled: true` now isolates worker **outbound** traffic as well -as protecting PostgreSQL/Redis ingress. External egress is denied by default. -Workers retain TCP access to same-release PostgreSQL/Redis pods when those -components are enabled, and UDP/TCP DNS access to the selected DNS pods: +When `networkPolicy.enabled: true` is set, the chart enforces a **default-deny** egress policy for backend worker pods (`*-worker-egress`), blocking all outbound external connections unless explicitly whitelisted. + +By default, worker pods retain outbound access only to: +1. **Cluster DNS**: UDP/TCP port `53` to the configured DNS namespace and pod selector (`kube-system` / `k8s-app: kube-dns`). +2. **In-Cluster PostgreSQL**: TCP port `5432` (automatically permitted when `postgresql.enabled: true`). +3. **In-Cluster Redis**: TCP port `6379` (automatically permitted when `redis.enabled: true`). + +All other outbound traffic — including arbitrary internet destinations, cloud instance metadata services (`169.254.169.254/32`, `168.63.129.16/32`), and internal private subnets (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`) — is strictly dropped by the CNI. + +To allow workers to perform vulnerability scans, query LLMs, inspect container images, and communicate with external services, operators must configure explicitly whitelisted endpoints via `networkPolicy.workerEgress.whitelistedEndpoints`: ```yaml networkPolicy: enabled: true workerEgress: - externalCIDRs: ["1.1.1.1/32"] # Example only; replace with actual provider/webhook IP ranges. - externalPorts: [443] + # Explicitly whitelisted external API endpoints + whitelistedEndpoints: + - name: llm-providers + description: "Inference endpoints for AI vulnerability explanations (Groq, OpenAI)" + cidrs: + - "104.18.0.0/20" # Example: Cloudflare CDN CIDR for api.groq.com + ports: [443] + + - name: container-registries + description: "Registries for image layer extraction and SBOM generation (GHCR, Docker Hub)" + cidrs: + - "140.82.112.0/20" # Example: GitHub CIDR for ghcr.io + ports: [443] + + - name: github-api + description: "GitHub REST API and raw file diff downloads" + cidrs: + - "140.82.112.0/20" + ports: [443] + + # Additional custom Kubernetes egress rules (e.g. for external VPC databases or proxies) + extraEgressRules: + - to: + - ipBlock: + cidr: "10.0.10.0/24" # Private VPC database subnet + ports: + - protocol: TCP + port: 5432 + + # Cluster DNS service configuration dns: namespace: kube-system podLabels: @@ -42,29 +76,28 @@ networkPolicy: ports: [53] ``` -Use the smallest stable destination ranges for GitHub, LLM providers and outbound -webhooks. This is an IP allowlist, not an FQDN allowlist: DNS changes require an -operator update. Only canonical IPv4 CIDRs are supported; IPv6 external traffic -remains denied. Private, loopback, link-local, shared-address, reserved and known -metadata ranges cannot be allowed directly. Broader CIDRs automatically exclude -contained protected ranges, including `169.254.0.0/16`, `100.64.0.0/10` and Azure's -`168.63.129.16/32`. Avoid `0.0.0.0/0`: although protected ranges are excluded, it -permits every other public destination on the configured ports. - -Enable this only after configuring the actual dependencies. External databases -and Redis are **not** automatically allowed; deployments using them need an -operator-reviewed, narrowly scoped additional policy. Publicly addressed cluster -services also need explicit review of the allowlist. The chart does not discover -cluster address ranges or provider IPs. Adjust DNS selectors/ports for your DNS -deployment; NodeLocal/host-network DNS may require a CNI-specific policy. - -Enforcement requires a NetworkPolicy-capable CNI. Kubernetes policies are -additive: another policy selecting workers can widen access, so audit the -combined policy set. NAT/service translation and node/host-network behavior vary -by CNI; verify allowed provider calls and blocked metadata/private destinations -in your staging cluster before rollout. Rendered-chart tests verify configuration -and selectors, not live packet enforcement. See the upstream -[NetworkPolicy documentation](https://kubernetes.io/docs/concepts/services-networking/network-policies/). +### Required Egress Traffic Rules Reference + +The following table summarizes the egress traffic destinations required by SecureFlow worker pods for standard and enterprise operations: + +| Destination / Service | Purpose | Protocol / Port | Configuration Parameter | Notes | +| :--- | :--- | :--- | :--- | :--- | +| **Cluster DNS** (`CoreDNS` / `kube-dns`) | Hostname resolution for external and internal services | UDP/TCP `53` | `networkPolicy.workerEgress.dns` | Must match your Kubernetes distribution's DNS namespace and pod labels (e.g., `coredns` in EKS/k3s). | +| **In-Cluster PostgreSQL** | Audit logs, policies, findings | TCP `5432` | `postgresql.enabled: true` | Automatically permitted to same-release PostgreSQL StatefulSet. | +| **In-Cluster Redis** | Asynchronous scan queues & state | TCP `6379` | `redis.enabled: true` | Automatically permitted to same-release Redis StatefulSet. | +| **External Managed PostgreSQL** | AWS RDS, Neon, Google Cloud SQL | TCP `5432` | `networkPolicy.workerEgress.extraEgressRules` | Required when `postgresql.enabled: false`. Scope CIDR to your private database subnet. | +| **External Managed Redis** | AWS ElastiCache, Upstash, Redis Cloud | TCP `6379` / `6380` (TLS) | `networkPolicy.workerEgress.extraEgressRules` | Required when `redis.enabled: false`. Scope CIDR to your private cache subnet. | +| **LLM Inference Providers** | The Professor AI security engine (Groq, OpenAI, Anthropic) | TCP `443` | `workerEgress.whitelistedEndpoints` | Whitelist provider IP ranges (e.g. Cloudflare IP blocks for Groq `api.groq.com`). | +| **Container Image Registries** | Container image layer scanning and SBOM generation (GHCR, Docker Hub, ECR) | TCP `443` | `workerEgress.whitelistedEndpoints` | Whitelist registry IP ranges (e.g. GitHub IP meta for `ghcr.io`, Docker Hub IPs). | +| **GitHub API & Git Content** | Webhook verification, PR diffs, commit checks, security alerts | TCP `443` | `workerEgress.whitelistedEndpoints` | Whitelist ranges from [GitHub Meta API](https://api.github.com/meta) (`api`, `git`, `web`). | +| **Outbound Webhooks** | High-severity finding notifications (Slack, Discord, custom SIEM) | TCP `443` | `workerEgress.whitelistedEndpoints` | Whitelist notification gateway IPs when webhook alerts are enabled. | + +> **Security Note:** Kubernetes `NetworkPolicy` operates on Layer 3 / Layer 4 (IP addresses and CIDR blocks), not DNS domain names (FQDNs). +> - Always specify the narrowest stable public IPv4 CIDRs available. +> - The chart's template compiler automatically validates CIDR formats and **strictly rejects** attempts to whitelist private (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`) or cloud metadata (`169.254.169.254/32`, `168.63.129.16/32`) addresses in `whitelistedEndpoints`. +> - If your organization utilizes dynamic IP endpoints or requires domain-level (FQDN) filtering, deploy an egress proxy (e.g., Envoy, Squid) or a CNI with L7 egress policy support (e.g., Cilium `CiliumNetworkPolicy`, Calico GlobalNetworkPolicy). + +Enforcement requires a NetworkPolicy-capable CNI (e.g., Calico, Cilium, AWS VPC CNI with network policies enabled, Azure NPM). Kubernetes policies are additive: audit any cluster-wide default policies to ensure worker isolation is not unintentionally weakened. Rendered-chart tests verify configuration syntax, schema conformance, and selector contracts. See upstream [Kubernetes NetworkPolicy documentation](https://kubernetes.io/docs/concepts/services-networking/network-policies/). ### 1. Add and inspect the chart @@ -172,6 +205,37 @@ redis: enabled: false external: url: "rediss://:your-redis-password@redis.internal.yourdomain.com:6379/0" + +# Enforce least-privilege network policies & worker egress hardening (#1767) +networkPolicy: + enabled: true + workerEgress: + whitelistedEndpoints: + - name: llm-providers + description: "Groq / OpenAI inference API endpoints for AI scanning" + cidrs: + - "104.18.0.0/20" + ports: [443] + - name: container-registries + description: "Container registries for vulnerability and SBOM analysis (GHCR, Docker Hub)" + cidrs: + - "140.82.112.0/20" + ports: [443] + - name: github-api + description: "GitHub API and raw blob fetching for PR analysis" + cidrs: + - "140.82.112.0/20" + ports: [443] + # Allow worker egress to private VPC managed database and Redis subnets + extraEgressRules: + - to: + - ipBlock: + cidr: "10.0.10.0/24" # Private VPC subnet for external PostgreSQL and Redis + ports: + - protocol: TCP + port: 5432 + - protocol: TCP + port: 6379 ``` Apply the deployment: @@ -227,7 +291,14 @@ is scraped once. The Service type and port come from `app.service.*`. | `ingress.className` | Ingress controller class name | `nginx` | | `secrets.existingSecret` | Name of pre-created secret for credentials | `""` | | `secrets.authSecret` | Authentication secret for NextAuth session JWTs (required if `existingSecret` is empty) | `""` | -| `networkPolicy.enabled` | Enable Kubernetes NetworkPolicies to enforce least-privilege ingress to postgresql and redis | `false` | +| `networkPolicy.enabled` | Enable Kubernetes NetworkPolicies to enforce least-privilege ingress to postgresql/redis and default-deny worker egress | `false` | +| `networkPolicy.workerEgress.whitelistedEndpoints` | Explicitly whitelisted external API endpoints with `name`, `cidrs`, `ports`, and optional `description` | `[]` | +| `networkPolicy.workerEgress.extraEgressRules` | Additional custom Kubernetes NetworkPolicy egress rule definitions | `[]` | +| `networkPolicy.workerEgress.externalCIDRs` | Public IPv4 CIDRs allowed for external worker egress (legacy flat format) | `[]` | +| `networkPolicy.workerEgress.externalPorts` | TCP destination ports permitted for `externalCIDRs` | `[443]` | +| `networkPolicy.workerEgress.dns.namespace` | Namespace of the cluster DNS service | `kube-system` | +| `networkPolicy.workerEgress.dns.podLabels` | Pod selector labels for the cluster DNS service | `k8s-app: kube-dns` | +| `networkPolicy.workerEgress.dns.ports` | Ports permitted for DNS resolution queries (UDP and TCP) | `[53]` | | `postgresql.enabled` | Deploy in-cluster PostgreSQL StatefulSet | `true` | | `postgresql.podDisruptionBudget.enabled` | Enable PodDisruptionBudget for PostgreSQL | `false` | | `postgresql.external.host` | Hostname of external PostgreSQL instance | `""` | diff --git a/helm/secureflow/templates/networkpolicy.yaml b/helm/secureflow/templates/networkpolicy.yaml index e7390ecc..a9435c8e 100644 --- a/helm/secureflow/templates/networkpolicy.yaml +++ b/helm/secureflow/templates/networkpolicy.yaml @@ -114,6 +114,19 @@ spec: port: {{ if eq $component "postgresql" }}5432{{ else }}6379{{ end }} {{- end }} {{- end }} + {{- range .Values.networkPolicy.workerEgress.whitelistedEndpoints }} + {{- $ports := .ports | default (list 443) }} + {{- range .cidrs }} + - to: + - ipBlock: + {{- include "secureflow.publicEgressBlock" . | nindent 12 }} + ports: + {{- range $ports }} + - protocol: TCP + port: {{ . }} + {{- end }} + {{- end }} + {{- end }} {{- range .Values.networkPolicy.workerEgress.externalCIDRs }} - to: - ipBlock: @@ -124,4 +137,7 @@ spec: port: {{ . }} {{- end }} {{- end }} + {{- with .Values.networkPolicy.workerEgress.extraEgressRules }} + {{- toYaml . | nindent 4 }} + {{- end }} {{- end }} diff --git a/helm/secureflow/values.schema.json b/helm/secureflow/values.schema.json index 6e3bb214..5ead2726 100644 --- a/helm/secureflow/values.schema.json +++ b/helm/secureflow/values.schema.json @@ -1552,6 +1552,57 @@ "maximum": 65535 } }, + "whitelistedEndpoints": { + "type": "array", + "description": "Explicitly whitelisted external API endpoints (e.g., LLM providers, container registries).", + "items": { + "type": "object", + "required": [ + "name", + "cidrs" + ], + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "minLength": 1, + "description": "Logical identifier for the whitelisted API endpoint (e.g., llm-providers, container-registries)." + }, + "description": { + "type": "string", + "description": "Human-readable description of the API endpoint service and purpose." + }, + "cidrs": { + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "string", + "pattern": "^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}/([0-9]|[12][0-9]|3[0-2])$" + }, + "description": "List of public IPv4 CIDR blocks for this API endpoint." + }, + "ports": { + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "integer", + "minimum": 1, + "maximum": 65535 + }, + "description": "Destination TCP ports for this endpoint (defaults to [443])." + } + } + } + }, + "extraEgressRules": { + "type": "array", + "description": "Additional custom Kubernetes NetworkPolicy egress rule objects.", + "items": { + "type": "object" + } + }, "dns": { "type": "object", "additionalProperties": false, diff --git a/helm/secureflow/values.yaml b/helm/secureflow/values.yaml index b0c13dca..e525c3d4 100644 --- a/helm/secureflow/values.yaml +++ b/helm/secureflow/values.yaml @@ -570,11 +570,32 @@ limitRange: # ---------------------------------------------------------------------------- networkPolicy: # Enable NetworkPolicy to restrict ingress to postgresql and redis pods - # strictly to app, worker, migration-job, and retention-cronjob pods. + # strictly to app, worker, migration-job, and retention-cronjob pods, + # and restrict worker egress to DNS, same-release DB/Redis, and explicitly + # whitelisted external API endpoints. enabled: false # When enabled, workers allow only DNS, same-release in-cluster DB/Redis, # and these explicit public IPv4 destinations. Empty = no external egress. workerEgress: + # Explicitly whitelisted external API endpoints (e.g., LLM providers, container registries). + # Each entry defines a logical API service with its destination IPv4 CIDRs and ports. + whitelistedEndpoints: [] + # Example production configuration: + # - name: llm-providers + # description: Groq / OpenAI API endpoints for AI security analysis + # cidrs: + # - "104.18.0.0/20" + # ports: [443] + # - name: container-registries + # description: Container image registries for SBOM and vulnerability inspection (e.g., GHCR, Docker Hub) + # cidrs: + # - "140.82.112.0/20" + # ports: [443] + + # Additional custom Kubernetes NetworkPolicy egress rule objects (e.g. for external DBs or proxies). + extraEgressRules: [] + + # Flat list of public IPv4 CIDRs (retained for backward compatibility). externalCIDRs: [] externalPorts: [443] dns: diff --git a/scripts/test-helm-chart.sh b/scripts/test-helm-chart.sh index f5fd0d1f..eb0ad40a 100644 --- a/scripts/test-helm-chart.sh +++ b/scripts/test-helm-chart.sh @@ -119,6 +119,40 @@ for setting in 'externalPorts[0]=0' 'externalPorts[0]=65536' 'externalPorts[0]=h exit 1 fi done + +# Explicitly whitelisted external API endpoints contract (#1767). +whitelisted="$("$helm_bin" template check "$chart_dir" \ + --show-only templates/networkpolicy.yaml \ + --set secrets.authSecret=local-test-only --set networkPolicy.enabled=true \ + --set 'networkPolicy.workerEgress.whitelistedEndpoints[0].name=llm-providers' \ + --set 'networkPolicy.workerEgress.whitelistedEndpoints[0].cidrs[0]=104.18.0.0/20' \ + --set 'networkPolicy.workerEgress.whitelistedEndpoints[0].ports[0]=443' \ + --set 'networkPolicy.workerEgress.whitelistedEndpoints[1].name=container-registries' \ + --set 'networkPolicy.workerEgress.whitelistedEndpoints[1].cidrs[0]=140.82.112.0/20' \ + --set 'networkPolicy.workerEgress.whitelistedEndpoints[1].ports[0]=8443')" +grep -Fq 'cidr: "104.18.0.0/20"' <<< "$whitelisted" +grep -Fq 'cidr: "140.82.112.0/20"' <<< "$whitelisted" +grep -Fq 'port: 443' <<< "$whitelisted" +grep -Fq 'port: 8443' <<< "$whitelisted" + +for bad_cidr in 169.254.169.254/32 10.0.0.0/8 192.168.1.0/24; do + if "$helm_bin" template check "$chart_dir" \ + --set secrets.authSecret=local-test-only --set networkPolicy.enabled=true \ + --set 'networkPolicy.workerEgress.whitelistedEndpoints[0].name=test-provider' \ + --set "networkPolicy.workerEgress.whitelistedEndpoints[0].cidrs[0]=$bad_cidr" >/dev/null 2>&1; then + echo "Accepted unsafe CIDR in worker whitelistedEndpoints: $bad_cidr" >&2 + exit 1 + fi +done + +for setting in 'whitelistedEndpoints[0].ports[0]=0' 'whitelistedEndpoints[0].ports[0]=65536' 'whitelistedEndpoints[0].cidrs=null'; do + if "$helm_bin" template check "$chart_dir" \ + --set secrets.authSecret=local-test-only \ + --set "networkPolicy.workerEgress.$setting" >/dev/null 2>&1; then + echo "Accepted invalid whitelistedEndpoints setting: $setting" >&2 + exit 1 + fi +done for release in check alternate; do args=(--set secrets.authSecret=local-test-only --set nameOverride=custom-name --set worker.podDisruptionBudget.enabled=true) worker="$("$helm_bin" template "$release" "$chart_dir" "${args[@]}" --show-only templates/worker-deployment.yaml)"