Forum

Notifications
Clear all

I built a network policy that only allows egress to our internal LLM gateway.

4 Posts
4 Users
0 Reactions
111 Views
(@kernel_auditor_rae)
Active Member
Joined: 6 months ago
Posts: 17
Topic starter   [#1451]

The default deployment model for OpenClaw agents assumes bidirectional connectivity to `api.openclaw.security` on TCP/443, which is operationally problematic for environments with stringent egress controls or air-gapped segments. While the official documentation suggests blanket whitelisting of the SaaS endpoint, this effectively creates a persistent tunnel from your infrastructure to an external service—a significant attack surface reduction failure. I've implemented a network policy that restricts all egress from the agent pods to a single internal LLM gateway, forcing all model inference and tool-use requests through a sanctioned internal proxy where additional logging, data loss prevention, and content filtering can be applied.

The policy is expressed as a Kubernetes NetworkPolicy resource, leveraging podSelector and egress rules. The key is to allow DNS resolution (UDP/53 to kube-dns) and then only permit TCP egress to the internal gateway's service IP and port. All other egress is explicitly denied by the policy's default deny-all-egress behavior.

```yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: openclaw-agent-egress
namespace: openclaw-agents
spec:
podSelector:
matchLabels:
app: openclaw-agent
policyTypes:
- Egress
egress:
# Allow DNS resolution for service discovery
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- protocol: UDP
port: 53
# Primary rule: allow egress to the internal LLM gateway service
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: llm-infra
podSelector:
matchLabels:
app: llm-gateway
ports:
- protocol: TCP
port: 8443
```

Reasoning behind the specific blocks:
* **Default Deny Egress:** The policyTypes field includes only Egress, establishing a default deny for all outgoing traffic from the labeled pods. This is the cornerstone of the control.
* **DNS Allowance:** A targeted rule permits UDP/53 to the kube-dns pods. This is a necessary evil for the agent to resolve the internal gateway's service name. In a higher-security setup, you could replace this with static host entries.
* **Gateway Allowance:** The sole permitted TCP flow is to the internal LLM gateway (here, service `llm-gateway.llm-infra.svc.cluster.local:8443`). All tool calls, context submissions, and model queries are forced through this choke point.
* **Implicit Block:** All other traffic—including direct egress to `api.openclaw.security`, any cloud metadata endpoints, or other internal services—is dropped at the kernel network namespace level.

This configuration necessitates that your internal LLM gateway is capable of handling the OpenClaw agent's protocol and proxying requests to the upstream SaaS endpoint (or to an on-prem model cluster). The agent must also be configured via its `OC_LLM_BASE_URL` environment variable to point to this gateway. The security win is substantial: you have reduced the egress profile of a highly privileged process to a single, monitored internal service, mitigating the risk of data exfiltration or command-and-control callbacks via the agent itself.

-- rae


Audit everything, trust no syscall.


   
Quote
(@enthusiast_mike_d)
Eminent Member
Joined: 6 months ago
Posts: 24
 

Oh man, this is a fantastic approach. I've been doing something similar in my homelab by running a local model gateway, but I'm using Docker Compose, not K8s, so my enforcement is just plain old firewall rules on the host.

Your point about it being a tunnel back to the SaaS endpoint is exactly why I started messing with this. One thing I'd add from my tinkering - make sure your internal gateway's failover or error handling doesn't accidentally let traffic bypass your policy. Early on, mine would fall back to trying a direct connection if the gateway was slow, which totally defeated the firewall rule 😅

Would love to see the full NetworkPolicy YAML if you get a chance to post it.


If it's not broken, break it for security.


   
ReplyQuote
(@newb_selfhost_tom)
Eminent Member
Joined: 6 months ago
Posts: 20
 

That failover point is huge, I hadn't even considered that. I'm still trying to wrap my head around this whole internal gateway idea. When you say you're using firewall rules on the host with Docker Compose, do you mean you're just blocking all external ports for that container? Like with iptables? I'm still pretty new at this, and my setup is just docker compose too.

Also, curious, what gateway software are you running internally for this? I've seen Nemoclaw mentioned but I'm not sure if that's the only option or if people are using other proxies.



   
ReplyQuote
(@vendor_skeptic_zara)
Eminent Member
Joined: 6 months ago
Posts: 23
 

"Forcing all model inference and tool-use requests through a sanctioned internal proxy" is the part that interests me. You've constrained the network path, but have you validated the proxy's own threat model? Does your internal gateway have its own vector to external services, or does it just become the new tunnel endpoint? If it's just forwarding to the same SaaS API, you've traded one pipe for another without reducing trust dependencies. What's your actual data sovereignty gain?



   
ReplyQuote