Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
{{- if .Values.networkPolicy.enabled }}
{{- $component := "server" -}}
{{/*
What the API may reach, and what may reach it.
Off by default, because a NetworkPolicy on a cluster with no CNI that enforces one is a resource
that silently does nothing, and on a cluster that does enforce one a wrong rule is an outage. A
deployment that turns this on is saying it knows which of the two it has.
Egress allows DNS, the database, the computers, and HTTP and HTTPS to everywhere that is not the
cluster's own private network. THAT LAST ONE IS NOT A CONCESSION, it is what this pod does: sign-in
goes to an identity provider, every conversation goes to Intelligence, and every run goes to a Bot
at an address somebody registered. All three are hostnames rather than CIDRs, and a NetworkPolicy
cannot match a hostname, so there is no narrower rule to write. Leaving it out did not fence the API
off, it stopped the product working, and only in `computers.mode: sandbox` did a rule meant for the
Kubernetes API server quietly cover for it.
The private ranges stay cut out by exception, the way the computers' policy does it, so this is
still a pod that cannot address another pod, a node, or a cloud metadata endpoint.
*/}}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "openbot.componentName" (dict "root" . "component" $component) }}
labels:
{{ include "openbot.componentLabels" (dict "root" . "component" $component) | indent 4 }}
spec:
podSelector:
matchLabels:
{{ include "openbot.componentSelectorLabels" (dict "root" . "component" $component) | indent 6 }}
policyTypes:
- Ingress
- Egress
ingress:
- ports:
- port: {{ .Values.server.service.port }}
protocol: TCP
{{- with .Values.networkPolicy.extraIngress }}
{{ toYaml . | indent 4 }}
{{- end }}
egress:
# DNS, or nothing resolves and every failure looks like the database being down.
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
{{- if .Values.postgresql.enabled }}
- to:
- podSelector:
matchLabels:
app.kubernetes.io/name: postgresql
ports:
- port: 5432
protocol: TCP
{{- end }}
{{- if ne .Values.computers.mode "external" }}
{{- /*
A Bot's computer, which the API has to reach for every browser action.
Easy to forget, because nothing about the API looks like it talks to another pod: the browser is
behind a Service and reads like an outside address. On a cluster that enforces policy, leaving
this out means every Bot action fails and the API looks broken rather than fenced.
*/}}
- to:
- podSelector:
matchLabels:
app.kubernetes.io/component: computer
ports:
- port: 4100
protocol: TCP
{{- end }}
{{- /*
Intelligence, the identity provider, and every Bot: all of them, and all outside the cluster.
Written as an exception list rather than as a destination list because the destinations are
hostnames the deployment configures and a NetworkPolicy matches addresses. The same shape the
computers' policy below already uses, for the same reason.
*/}}
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
# The cluster and everything else on the private network, including the database.
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
# Link-local, which is where every cloud keeps the endpoint that hands out credentials.
- 169.254.0.0/16
ports:
- port: 80
protocol: TCP
- port: 443
protocol: TCP
{{- if eq .Values.computers.mode "sandbox" }}
{{- /*
The Kubernetes API server, which is where a per-Bot computer is asked for.
Its own rule because it sits on the private network the rule above cuts out, so nothing else
here reaches it. The API server answers on a ClusterIP from the service range, and a chart
cannot know that range at template time, so `networkPolicy.kubernetesApiCidr` names it and
the chart refuses to render this policy until something does.
THAT REFUSAL REPLACED A DEFAULT THAT UNDID THE RULE ABOVE. This was written to fall through a
`with` when the value was empty, which left an egress rule holding ports and no peer — and an
egress rule with no `to` matches EVERY destination, so the shipped default permitted 443 and
6443 to all of the `10/8`, `172.16/12`, `192.168/16` and `169.254/16` that the rule directly
above goes to the trouble of excepting. See `openbot.kubernetesApiCidr` in `_helpers.tpl` for
why this refuses rather than rendering nothing or guessing a range.
*/}}
- to:
- ipBlock:
cidr: {{ include "openbot.kubernetesApiCidr" . }}
ports:
- port: 443
protocol: TCP
- port: 6443
protocol: TCP
{{- end }}
{{- with .Values.networkPolicy.extraEgress }}
{{ toYaml . | indent 4 }}
{{- end }}
---
{{- $computer := "computer" -}}
{{/*
What a Bot's computer may reach.
THE ONE POD THAT RUNS A BROWSER AND A SHELL. It opens pages a person named and runs commands a model
chose, which makes it the pod most likely to be doing something nobody intended, and it was the only
one with no policy at all: on a cluster that enforces them it could open a socket to anything in the
namespace, the deployment's own database included. Compose has kept the database off the Bot's
network since the beginning, and this is that same boundary, said in the other deployment's words.
Egress is the open internet minus the cluster's own private space, because browsing is the job. The
private ranges are cut out by exception rather than by listing what is allowed: a Bot has no business
addressing another pod, a node, or a cloud metadata endpoint, and naming the exceptions is the only
way to say that without also saying which websites exist.
Ingress is the API server and nothing else. The gateway is the only thing that may drive it.
*/}}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "openbot.componentName" (dict "root" . "component" $computer) }}
labels:
{{ include "openbot.componentLabels" (dict "root" . "component" $computer) | indent 4 }}
spec:
podSelector:
matchLabels:
{{ include "openbot.componentSelectorLabels" (dict "root" . "component" $computer) | indent 6 }}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
{{ include "openbot.componentSelectorLabels" (dict "root" . "component" "server") | indent 14 }}
ports:
- port: 4100
protocol: TCP
egress:
# DNS, or every address a Bot is asked to open fails as if the site were down.
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
# The cluster and everything else on the private network, including the database.
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
# Link-local, which is where every cloud keeps the endpoint that hands out credentials.
- 169.254.0.0/16
ports:
- port: 80
protocol: TCP
- port: 443
protocol: TCP
{{- with .Values.networkPolicy.computerExtraEgress }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- end }}
{{- if and .Values.networkPolicy.enabled (eq .Values.computers.mode "sandbox") .Values.computers.sandbox.culler.enabled }}
---
{{- $culler := "culler" -}}
{{/* A pod no policy selects keeps the cluster default, so this one needs its own, same as the routines sweep below and the attachments culler after it. */}}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "openbot.componentName" (dict "root" . "component" $culler) }}
labels:
{{ include "openbot.componentLabels" (dict "root" . "component" $culler) | indent 4 }}
spec:
podSelector:
matchLabels:
{{ include "openbot.componentSelectorLabels" (dict "root" . "component" $culler) | indent 6 }}
policyTypes:
- Ingress
- Egress
# No ingress rules, which under an Ingress policyType denies all of it.
ingress: []
egress:
# DNS, or the database hostname does not resolve and the sweep reads as the database being down.
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
{{- if .Values.postgresql.enabled }}
- to:
- podSelector:
matchLabels:
app.kubernetes.io/name: postgresql
ports:
- port: 5432
protocol: TCP
{{- end }}
{{- /*
The Kubernetes API server, which is the only thing this sweep asks anything of besides the
database: it lists Sandboxes and suspends the idle ones.
THE SAME RULE THE SERVER'S POLICY ABOVE CARRIES, AND IT USED TO BE WRONG IN A WORSE WAY HERE.
The comment that stood on this line said an empty `kubernetesApiCidr` permits these ports to
any address "as the server's rule above does", and treated that as a note rather than as the
hole it was. On the server it cancelled an exception list; on this pod, whose only other egress
is DNS and the database, it WAS the whole of the egress — a CronJob holding the database
credential with an unrestricted HTTPS socket, which is the opposite of what a policy on this
pod is for. `openbot.kubernetesApiCidr` now refuses an empty value for both of them.
*/}}
- to:
- ipBlock:
cidr: {{ include "openbot.kubernetesApiCidr" . }}
ports:
- port: 443
protocol: TCP
- port: 6443
protocol: TCP
{{- /* An external database, which extraEgress already had to name; cullerExtraEgress narrows it. */}}
{{- with (default .Values.networkPolicy.extraEgress .Values.networkPolicy.cullerExtraEgress) }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- end }}
{{- if and .Values.networkPolicy.enabled (.Values.routines).enabled }}
---
{{- $routines := "routines" -}}
{{/* Same reason as the culler; this pod holds no token and reaches only the database and the API server. */}}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "openbot.componentName" (dict "root" . "component" $routines) }}
labels:
{{ include "openbot.componentLabels" (dict "root" . "component" $routines) | indent 4 }}
spec:
podSelector:
matchLabels:
{{ include "openbot.componentSelectorLabels" (dict "root" . "component" $routines) | indent 6 }}
policyTypes:
- Ingress
- Egress
# No ingress rules, which under an Ingress policyType denies all of it.
ingress: []
egress:
# DNS, or neither the database nor the server resolves and the sweep reads as both being down.
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
{{- if .Values.postgresql.enabled }}
- to:
- podSelector:
matchLabels:
app.kubernetes.io/name: postgresql
ports:
- port: 5432
protocol: TCP
{{- end }}
{{- /* The API server, where SERVER_INTERNAL_URL points and the only thing this pod calls. */}}
- to:
- podSelector:
matchLabels:
{{ include "openbot.componentSelectorLabels" (dict "root" . "component" "server") | indent 14 }}
ports:
- port: {{ .Values.server.service.port }}
protocol: TCP
{{- /* An external database, for the reason given on the culler's policy above. */}}
{{- with (default .Values.networkPolicy.extraEgress .Values.networkPolicy.routinesExtraEgress) }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- end }}
{{- if and .Values.networkPolicy.enabled (eq (include "openbot.attachmentsCullerEnabled" .) "true") }}
---
{{- $attachmentsCuller := "attachments-culler" -}}
{{/*
What the attachments culler may reach.
Same shape as the routines sweep and the computer culler above: a CronJob nothing else selects, so
without its own policy it would keep the cluster default rather than a fence. It holds the database
credential, which is exactly the shape of pod a NetworkPolicy exists for.
No Kubernetes-API rule, unlike the routines sweep and the computer culler: this pod's spec sets
`automountServiceAccountToken: false` and its script only ever opens the database, so there is
nothing here that would use a token even if one leaked in.
*/}}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "openbot.componentName" (dict "root" . "component" $attachmentsCuller) }}
labels:
{{ include "openbot.componentLabels" (dict "root" . "component" $attachmentsCuller) | indent 4 }}
spec:
podSelector:
matchLabels:
{{ include "openbot.componentSelectorLabels" (dict "root" . "component" $attachmentsCuller) | indent 6 }}
policyTypes:
- Ingress
- Egress
# No ingress rules, which under an Ingress policyType denies all of it.
ingress: []
egress:
# DNS, or the database hostname does not resolve and the sweep reads as the database being down.
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
{{- if .Values.postgresql.enabled }}
- to:
- podSelector:
matchLabels:
app.kubernetes.io/name: postgresql
ports:
- port: 5432
protocol: TCP
{{- end }}
{{- /* An external database, for the reason given on the culler's policy above. */}}
{{- with (default .Values.networkPolicy.extraEgress .Values.networkPolicy.attachmentsCullerExtraEgress) }}
{{ toYaml . | indent 4 }}
{{- end }}
{{- end }}