|
| 1 | +# Agentrax — Tenant Network Isolation |
| 2 | + |
| 3 | +This document explains the two-tier network policy model shipped with Agentrax |
| 4 | +and how platform operators apply it to tenant namespaces. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +Agentrax uses Kubernetes `NetworkPolicy` to enforce a **zero-trust perimeter** |
| 9 | +around all agent pods. This prevents a compromised or misbehaving agent in one |
| 10 | +tenant from reaching another tenant's services, the operator control plane, or |
| 11 | +arbitrary internet destinations. |
| 12 | + |
| 13 | +Two policies are maintained: |
| 14 | + |
| 15 | +| Policy File | Namespace | Purpose | |
| 16 | +| ----------------------------- | -------------------------- | -------------------------------------------------------------------------- | |
| 17 | +| `allow-metrics-traffic.yaml` | `agentrax-system` | Allows Prometheus to scrape the operator `/metrics` endpoint | |
| 18 | +| `tenant-agent-isolation.yaml` | Every `tenant-*` namespace | Isolates agent pods — restricts all ingress/egress to the minimum required | |
| 19 | + |
| 20 | +## How the Label Selector Works |
| 21 | + |
| 22 | +The `tenant-agent-isolation` policy uses `podSelector.matchLabels`: |
| 23 | + |
| 24 | +```yaml |
| 25 | +podSelector: |
| 26 | + matchLabels: |
| 27 | + agentrax.io/agent: "true" |
| 28 | +``` |
| 29 | +
|
| 30 | +The `AgentDeployment` reconciler (`internal/controller/agentdeployment_controller.go`) |
| 31 | +stamps this label onto every agent `Deployment`'s pod template via `agentLabels()`. |
| 32 | +No manual labelling is needed — all agent pods are automatically covered. |
| 33 | + |
| 34 | +## Traffic Model |
| 35 | + |
| 36 | +``` |
| 37 | +┌─────────────────────────────────────────────────────┐ |
| 38 | +│ tenant-finance namespace │ |
| 39 | +│ │ |
| 40 | +│ [Agent Pod] agentrax.io/agent=true │ |
| 41 | +│ │ │ |
| 42 | +│ ├─ Ingress ← port 8080 ← [Prometheus] │ |
| 43 | +│ │ (monitoring namespace only) │ |
| 44 | +│ │ │ |
| 45 | +│ ├─ Egress → port 6443 → [kube-apiserver] │ |
| 46 | +│ ├─ Egress → port 53 → [CoreDNS] │ |
| 47 | +│ │ │ |
| 48 | +│ └─ ALL OTHER TRAFFIC: BLOCKED │ |
| 49 | +└─────────────────────────────────────────────────────┘ |
| 50 | +``` |
| 51 | +
|
| 52 | +## Applying the Policy to Tenant Namespaces |
| 53 | +
|
| 54 | +The `tenant-agent-isolation.yaml` NetworkPolicy must be applied to each tenant |
| 55 | +namespace. The policy is **not** automatically applied by the operator — it is |
| 56 | +applied once by a platform admin when provisioning a tenant namespace. |
| 57 | +
|
| 58 | +### Apply Manually |
| 59 | +
|
| 60 | +```bash |
| 61 | +# Apply to a specific tenant namespace: |
| 62 | +kubectl apply -n tenant-finance \ |
| 63 | + -f config/network-policy/tenant-agent-isolation.yaml |
| 64 | +
|
| 65 | +kubectl apply -n tenant-marketing \ |
| 66 | + -f config/network-policy/tenant-agent-isolation.yaml |
| 67 | +``` |
| 68 | + |
| 69 | +### Apply via Kustomize (Development) |
| 70 | + |
| 71 | +The default Kustomize overlay applies both network policies to the `agentrax-system` |
| 72 | +namespace for development/testing. The `tenant-agent-isolation` policy in this |
| 73 | +context validates the manifest schema; in production it must be applied per tenant |
| 74 | +namespace as above. |
| 75 | + |
| 76 | +```bash |
| 77 | +kubectl apply -k config/default/ |
| 78 | +``` |
| 79 | + |
| 80 | +### Apply via Helm (Recommended for Production) |
| 81 | + |
| 82 | +When installing via Helm, set `networkPolicy.enabled: true` (Phase 1 Helm |
| 83 | +integration — coming in a future release): |
| 84 | + |
| 85 | +```bash |
| 86 | +helm upgrade --install agentrax charts/agentrax/ \ |
| 87 | + --set networkPolicy.enabled=true |
| 88 | +``` |
| 89 | + |
| 90 | +## Labelling the Prometheus Namespace |
| 91 | + |
| 92 | +The ingress rule allows traffic from namespaces labelled `monitoring: enabled`. |
| 93 | +Apply this label to the namespace where Prometheus Operator / kube-prometheus-stack |
| 94 | +is installed: |
| 95 | + |
| 96 | +```bash |
| 97 | +kubectl label namespace monitoring monitoring=enabled |
| 98 | +# Or, if using the default kube-prometheus-stack namespace name: |
| 99 | +kubectl label namespace monitoring monitoring=enabled |
| 100 | +``` |
| 101 | + |
| 102 | +## Required CNI Support |
| 103 | + |
| 104 | +This NetworkPolicy relies on a Container Network Interface (CNI) plugin that |
| 105 | +**enforces** `NetworkPolicy` objects. Verify your CNI supports this: |
| 106 | + |
| 107 | +| Environment | Supported CNI | |
| 108 | +| ---------------- | ----------------------------- | |
| 109 | +| Kind (local dev) | Kindnet (default) ✅ | |
| 110 | +| Azure AKS | Azure CNI or Calico ✅ | |
| 111 | +| AWS EKS | VPC CNI + Calico or Cilium ✅ | |
| 112 | +| GKE | Dataplane V2 (Cilium) ✅ | |
| 113 | + |
| 114 | +> **Note**: Flannel does **not** enforce NetworkPolicy by default. Use Calico or |
| 115 | +> Cilium as a replacement CNI if Flannel is your cluster default. |
| 116 | +
|
| 117 | +## Verifying the Policy |
| 118 | + |
| 119 | +After applying, verify that the policy is active and that an agent pod has |
| 120 | +the correct label: |
| 121 | + |
| 122 | +```bash |
| 123 | +# Confirm agent pod has the isolation label: |
| 124 | +kubectl get pods -n tenant-finance -L agentrax.io/agent |
| 125 | + |
| 126 | +# Confirm the NetworkPolicy is present: |
| 127 | +kubectl get networkpolicy -n tenant-finance |
| 128 | + |
| 129 | +# Test that cross-tenant traffic is blocked (from within an agent pod): |
| 130 | +kubectl exec -n tenant-finance <agent-pod> -- \ |
| 131 | + curl --connect-timeout 2 http://<service-in-tenant-marketing> |
| 132 | +# Expected: connection timed out (blocked) |
| 133 | + |
| 134 | +# Test that Kubernetes API access is allowed: |
| 135 | +kubectl exec -n tenant-finance <agent-pod> -- \ |
| 136 | + curl -k https://kubernetes.default.svc:443/healthz |
| 137 | +# Expected: "ok" |
| 138 | +``` |
0 commit comments