190 lines
5.2 KiB
YAML
190 lines
5.2 KiB
YAML
---
|
|
# NetworkPolicies for neuron-prod
|
|
# Default-deny all ingress and egress, then explicitly allow only what's needed.
|
|
# Enforced by k3s's built-in NetworkPolicy controller.
|
|
|
|
# ── Baseline: deny all traffic in namespace ───────────────────────────────────
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: default-deny-all
|
|
namespace: neuron-prod
|
|
spec:
|
|
podSelector: {}
|
|
policyTypes:
|
|
- Ingress
|
|
- Egress
|
|
---
|
|
# ── neuron-mcp: accept traffic from Traefik (kube-system) only ───────────────
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: allow-mcp-ingress
|
|
namespace: neuron-prod
|
|
spec:
|
|
podSelector:
|
|
matchLabels:
|
|
app: neuron-mcp
|
|
policyTypes:
|
|
- Ingress
|
|
ingress:
|
|
- from:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: kube-system
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: neuron-prod
|
|
---
|
|
# ── neuron-rest: accept from mcp, kube-system (Traefik), monitoring (Alloy) ──
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: allow-rest-ingress
|
|
namespace: neuron-prod
|
|
spec:
|
|
podSelector:
|
|
matchLabels:
|
|
app: neuron-rest
|
|
policyTypes:
|
|
- Ingress
|
|
ingress:
|
|
- from:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: kube-system
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: neuron-prod
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: monitoring
|
|
---
|
|
# ── neuron-marketing: accept from Traefik only ───────────────────────────────
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: allow-marketing-ingress
|
|
namespace: neuron-prod
|
|
spec:
|
|
podSelector:
|
|
matchLabels:
|
|
app: neuron-marketing
|
|
policyTypes:
|
|
- Ingress
|
|
ingress:
|
|
- from:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: kube-system
|
|
---
|
|
# ── neuron-daemon: accept from neuron-prod namespace (dharma, mcp, etc.) ─────
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: allow-daemon-ingress
|
|
namespace: neuron-prod
|
|
spec:
|
|
podSelector:
|
|
matchLabels:
|
|
app: neuron-daemon
|
|
policyTypes:
|
|
- Ingress
|
|
ingress:
|
|
- from:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: neuron-prod
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: kube-system
|
|
---
|
|
# ── engram-server: accept from dharma and neuron-prod namespace ──────────────
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: allow-engram-ingress
|
|
namespace: neuron-prod
|
|
spec:
|
|
podSelector:
|
|
matchLabels:
|
|
app: engram-server
|
|
policyTypes:
|
|
- Ingress
|
|
ingress:
|
|
- from:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: neuron-prod
|
|
---
|
|
# ── dharma: accept from Traefik (kube-system) and neuron-prod namespace ──────
|
|
# The dharma pod was healthy and the IngressRoute was correct, but cross-
|
|
# namespace ingress from kube-system (Traefik) was denied by default-deny-all,
|
|
# so every external request landed at Traefik and bounced back as 502. This
|
|
# allow rule mirrors `allow-mcp-ingress` and brings dharma into line with the
|
|
# other neuron-prod services.
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: allow-dharma-ingress
|
|
namespace: neuron-prod
|
|
spec:
|
|
podSelector:
|
|
matchLabels:
|
|
app: dharma
|
|
policyTypes:
|
|
- Ingress
|
|
ingress:
|
|
- from:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: kube-system
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: neuron-prod
|
|
---
|
|
# ── Egress: all prod pods may reach platform (postgres/redis), vault,
|
|
# monitoring (alloy OTLP), kube-dns, and the internet (external APIs) ─
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: allow-prod-egress
|
|
namespace: neuron-prod
|
|
spec:
|
|
podSelector: {}
|
|
policyTypes:
|
|
- Egress
|
|
egress:
|
|
# Kubernetes DNS
|
|
- ports:
|
|
- port: 53
|
|
protocol: UDP
|
|
- port: 53
|
|
protocol: TCP
|
|
# platform namespace (Postgres, Redis, accounts service)
|
|
- to:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: platform
|
|
# vault namespace
|
|
- to:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: vault
|
|
# monitoring namespace (Alloy OTLP)
|
|
- to:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: monitoring
|
|
# intra-namespace (mcp ↔ rest ↔ license)
|
|
- to:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: neuron-prod
|
|
# external internet (Stripe, OAuth providers, Cloudflare, etc.)
|
|
- ports:
|
|
- port: 443
|
|
protocol: TCP
|
|
- port: 80
|
|
protocol: TCP
|