Cloud Harness provides automatic network policy management to control traffic flow between applications and external networks. Network policies enforce zero-trust networking principles by default and can be configured per application.
Network policies in Kubernetes define how pods can communicate with each other and with external networks. Cloud Harness automatically generates NetworkPolicy resources based on application configuration, providing security boundaries while maintaining necessary communication paths.
By default, when network policies are enabled for an application:
- Same-namespace traffic: Always allowed in both directions — all pods in the same namespace can always communicate freely
- DNS: Always allowed (port 53 TCP/UDP) for egress
- Cross-namespace / external traffic: Blocked by default
ingress: true: TheIngresspolicyType is omitted entirely — Kubernetes leaves all incoming traffic unrestrictedegress: true: TheEgresspolicyType is omitted entirely — Kubernetes leaves all outgoing traffic unrestricted- Both
ingress: true+egress: true: No NetworkPolicy is generated at all
Network policies for application pods are opt-in. To enable them, add a network key under harness.deployment in the application's deploy/values.yaml:
harness:
deployment:
auto: true
network:
ingress: false
egress: falseDatabase pods always have a network policy generated automatically when harness.database.auto: true. The default is fully restrictive (same-namespace only). Configuration lives under harness.database.network:
harness:
database:
auto: true
network:
ingress: false # default — same-namespace only
egress: false # default — same-namespace onlyThe same ingress, egress, and allowedNamespaces options available for application deployments apply to databases.
harness:
deployment:
network:
ingress: trueControls traffic arriving at the pod from other namespaces and the external internet. Same-namespace traffic is always allowed regardless of this setting.
When ingress: true + egress: true:
- No NetworkPolicy is created — the pod is fully unrestricted
When ingress: true (and egress: false):
- The
IngresspolicyType is omitted from the NetworkPolicy — Kubernetes treats ingress as fully open - Egress is still restricted to same-namespace pods and DNS
When ingress: false (default):
- The
IngresspolicyType is enforced: only same-namespace pods (and anyallowedNamespaces) can reach this pod
harness:
deployment:
network:
egress: trueControls traffic leaving the pod to other namespaces and the external internet. Same-namespace traffic and DNS are always allowed regardless of this setting.
When egress: true (and ingress: false):
- The
EgresspolicyType is omitted from the NetworkPolicy — Kubernetes treats egress as fully open - Ingress is still restricted to same-namespace pods (and any
allowedNamespaces)
When egress: false (default):
- The
EgresspolicyType is enforced: only same-namespace pods and DNS (port 53) can receive traffic from this pod
Private IP ranges are not explicitly blocked — when egress: true, the policyType is simply absent and all destinations are reachable.
For fine-grained cross-namespace access without fully opening a direction, specific namespaces can be whitelisted:
harness:
deployment:
network:
ingress: false
egress: false
allowedNamespaces:
- monitoring
- loggingWhitelisted namespaces are allowed both as ingress sources and egress destinations, but only for restricted directions (ingress: false / egress: false). If a direction is already open (ingress: true or egress: true), the whitelist has no effect on it.
This is useful for:
- Granting access to a monitoring namespace (e.g. Prometheus scraping metrics)
- Allowing a logging agent in another namespace to receive logs
- Enabling selective cross-namespace service communication without fully opening the policy
Namespaces are matched by the kubernetes.io/metadata.name label, which Kubernetes automatically assigns to all namespaces since version 1.21. On older clusters, or namespaces created before upgrading, this label may need to be added manually:
kubectl label namespace <name> kubernetes.io/metadata.name=<name>Note: For ingress controllers (Traefik, nginx, etc.) prefer
ingress: trueover whitelisting the ingress controller namespace. Ingress controllers proxy external traffic andingress: trueremoves the policyType entirely — no label dependency required.
An internal API that is reachable only by the ingress controller (egress restricted to same-namespace and a monitoring namespace):
harness:
subdomain: api
deployment:
auto: true
name: my-api
network:
ingress: true # ingress controller (Traefik/nginx) runs in a different namespace
egress: false # restrict outgoing traffic
allowedNamespaces:
- monitoring # allow Prometheus to scrape metrics
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512MiThis generates a NetworkPolicy that:
- Omits the
IngresspolicyType — all incoming traffic is unrestricted (suitable for ingress controllers) - Enforces
Egress: only same-namespace pods, DNS, and themonitoringnamespace are reachable - Always allows intra-namespace pod communication
The generated NetworkPolicy with ingress: false, egress: false, and allowedNamespaces: [monitoring]:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: my-api-network-policy
namespace: default
spec:
podSelector:
matchLabels:
app: my-api
policyTypes:
- Ingress # present: ingress is restricted
- Egress # present: egress is restricted
ingress:
# Always: same namespace
- from:
- podSelector: {}
# allowedNamespaces whitelist
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: monitoring
egress:
# Always: same namespace
- to:
- podSelector: {}
# Always: DNS
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
# allowedNamespaces whitelist
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: monitoringWith ingress: true, egress: false — the Ingress policyType is simply absent, so Kubernetes imposes no ingress restrictions:
policyTypes:
- Egress # only egress is restricted
egress:
- to:
- podSelector: {}
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCPWhen network policies are enabled, Cloud Harness implements a zero-trust model:
- Same-namespace free: Pods within the same namespace can always communicate without restriction
- Cross-namespace / external deny by default: Traffic requires explicit opt-in via
ingress/egressflags orallowedNamespaces - Open by omission: Setting
ingress: trueoregress: trueremoves that policyType from the NetworkPolicy entirely, letting Kubernetes leave that direction unrestricted — no extra rules needed - Full open = no policy: When both flags are true, no NetworkPolicy is generated
-
Enable Network Policies: Enable network policies on applications that handle sensitive data or provide critical services
-
Prefer whitelisting over full open: Use
allowedNamespacesfor selective cross-namespace access rather than settingingress: trueoregress: truewhen only specific namespaces need access -
ingress: truefor externally exposed apps: Applications with public endpoints (subdomain/domain) need this to allow traffic from the ingress controller in its own namespace -
egress: truefor apps calling external APIs: Only enable when the application genuinely needs to reach the public internet -
Testing: Test network policies in development environments before deploying to production
Exposes a public endpoint via the Kubernetes Ingress controller (Traefik, nginx, etc. — which typically runs in a different namespace). Use ingress: true to remove the Ingress policyType entirely; do not rely on allowedNamespaces for ingress controllers:
harness:
subdomain: webapp
deployment:
network:
ingress: true # removes Ingress policyType — no namespace label dependency
egress: true # allow calls to external APIsServes requests from the ingress controller and calls external services:
harness:
subdomain: api
deployment:
network:
ingress: true
egress: trueOnly reachable within the namespace, no external connectivity:
harness:
deployment:
network:
ingress: false
egress: falseSame-namespace pods can still communicate freely; all cross-namespace and internet traffic is blocked.
Accepts connections from same namespace only, but also scraped by Prometheus in the monitoring namespace:
harness:
database:
auto: true
network:
allowedNamespaces:
- monitoringA service used by applications in multiple namespaces:
harness:
deployment:
network:
ingress: false
egress: false
allowedNamespaces:
- team-a
- team-bSame-namespace pod-to-pod communication is always allowed when a network policy exists. If it fails:
- Verify that the network policy was actually generated (the
network:key must be present in values) - Check that the CNI plugin on your cluster supports NetworkPolicy
If applications in different namespaces cannot communicate:
- Ensure
ingress: trueis set on the destination app, or the source namespace is inallowedNamespaces - Ensure
egress: trueis set on the source app, or the destination namespace is inallowedNamespaces - Verify both apps are deployed with their network policies active
If external API calls timeout:
- Ensure
egress: trueis configured on the calling application - Verify DNS resolution works (should always be allowed)
- Check that the target IP is not in a private range (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) — these are always blocked
If Traefik, nginx, or another ingress controller cannot reach the application:
- Use
ingress: true, notallowedNamespaces. Ingress controllers run in a separate namespace and proxy external traffic —ingress: trueremoves theIngresspolicyType entirely, which is simpler and has no label dependency. - Avoid patterns like
allowedNamespaces: [traefik]for ingress controllers: this relies on the namespace having thekubernetes.io/metadata.name: traefiklabel, which may not exist on all clusters or may use a different namespace name (e.g.traefik-system). - Verify the application has
subdomainordomainconfigured so that the Ingress resource is created.
If a whitelisted namespace cannot reach the application:
- Verify the namespace has the
kubernetes.io/metadata.namelabel (automatic in Kubernetes 1.21+, may need manual labelling on older clusters or namespaces created before the upgrade):kubectl get namespace <name> --show-labels kubectl label namespace <name> kubernetes.io/metadata.name=<name>
- Check the exact namespace name matches the value in
allowedNamespaces(e.g.traefik-systemvstraefik) - Remember that
allowedNamespacesonly applies to restricted directions: ifingress: truethe whitelist has no effect on ingress (it's already fully open); same for egress
Documentation on network policies and deployment configuration can be found in:
- Applications Configuration - Application values.yaml reference
- Deployment Configuration - Cluster deployment settings
- Kubernetes Network Policies Documentation