Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions charts/zelkor-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,22 @@ else inherit {releaseName}-ai-gateway-consumer (zelkor deploy copies it into oth
{{- if and $s $s.data -}}{{- index $s.data "agents" | default "" | sha256sum | trunc 16 -}}{{- end -}}
{{- end -}}
{{- end }}

{{/*
CE-21: "true" when the pod runs without DNS: lockdown is on and something fills its hostAliases
(platform.hostAliases from `zelkor deploy`, or the platform admission policy on K8s >= 1.36).
"inactive" when lockdown is on but neither can: the pod keeps DNS and is marked for
`zelkor verify` (plain Helm / GitOps installs on older clusters must not break). "false" when off.
*/}}
{{- define "zelkor-agent.dnsLockdown" -}}
{{- $on := (((.Values.security).dnsLockdown).enabled) | default false -}}
{{- $aliases := ((.Values.platform).hostAliases) | default list -}}
{{- $map := and (.Capabilities.APIVersions.Has "admissionregistration.k8s.io/v1/MutatingAdmissionPolicy") (include "zelkor-agent.platformReleaseName" .) -}}
{{- if not $on -}}
false
{{- else if or $aliases $map -}}
true
{{- else -}}
inactive
{{- end -}}
{{- end }}
20 changes: 20 additions & 0 deletions charts/zelkor-agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,31 @@ spec:
metadata:
annotations:
checksum/ai-gateway-consumer: {{ include "zelkor-agent.consumerKeyChecksum" . | quote }}
{{- if eq (include "zelkor-agent.dnsLockdown" .) "inactive" }}
# CE-21: lockdown requested, but no host map to fill hostAliases; DNS stays on.
zelkor.io/dns-lockdown: inactive
{{- end }}
labels:
{{- include "zelkor-agent.selectorLabels" . | nindent 8 }}
zelkor.io/workload-type: agent
zelkor.io/datastores: {{ include "zelkor-agent.datastores" . }}
{{- with (include "zelkor-agent.platformReleaseName" .) }}
zelkor.io/platform-release: {{ . | quote }}
{{- end }}
{{- if eq (include "zelkor-agent.dnsLockdown" .) "true" }}
zelkor.io/dns-lockdown: "on"
{{- end }}
spec:
{{- if eq (include "zelkor-agent.dnsLockdown" .) "true" }}
# CE-21: no DNS. Names resolve from /etc/hosts; nothing answers on 127.0.0.1:53.
dnsPolicy: None
dnsConfig:
nameservers: ["127.0.0.1"]
{{- with ((.Values.platform).hostAliases) }}
hostAliases:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- with .Values.global.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
Expand Down
2 changes: 2 additions & 0 deletions charts/zelkor-agent/templates/networkpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ spec:
policyTypes:
- Egress
egress:
{{- if ne (include "zelkor-agent.dnsLockdown" .) "true" }}
- to:
- namespaceSelector:
matchLabels:
Expand All @@ -27,6 +28,7 @@ spec:
port: 53
- protocol: TCP
port: 53
{{- end }}
- to:
- namespaceSelector:
matchLabels:
Expand Down
29 changes: 29 additions & 0 deletions charts/zelkor-agent/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@
"type": "array"
}
}
},
"dnsLockdown": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
}
}
},
Expand Down Expand Up @@ -275,6 +283,27 @@
"pattern": "^[a-z0-9]([a-z0-9-]{0,30}[a-z0-9])?$"
},
"description": "CE-15a-4: platform HTTP API relays this agent may call (needs releaseName)."
},
"hostAliases": {
"type": "array",
"items": {
"type": "object",
"required": [
"ip",
"hostnames"
],
"properties": {
"ip": {
"type": "string"
},
"hostnames": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions charts/zelkor-agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,16 @@ security:
# come from the envoy-gateway-system namespace, so the ingress rule below would drop it.
# `zelkor deploy` fills this on kind clusters; leave empty everywhere else.
hostNetworkGatewayCIDRs: []
# CE-21: the pod gets no DNS (dnsPolicy None, nameserver 127.0.0.1 where nothing answers) and
# reaches platform names through hostAliases. Filled by the platform's admission policy on
# K8s >= 1.36, or by `zelkor deploy` (platform.hostAliases) on older clusters. Turn off only for
# an agent that must resolve names outside the platform (e.g. its own external database).
dnsLockdown:
enabled: true

platform:
# CE-21: [{ip, hostnames: [...]}] from the platform host map. `zelkor deploy` fills it.
hostAliases: []
# Platform Helm release namespace. Empty → this release namespace.
# CLI sets this when `zelkor deploy --namespace` differs from the platform env.
namespace: ""
Expand Down
13 changes: 13 additions & 0 deletions charts/zelkor-platform/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1773,3 +1773,16 @@ Usage: include "zelkor-platform.dataToolEgress" (dict "egressTo" list "component
{{- end -}}
{{- toYaml $rules -}}
{{- end }}

{{/*
CE-21 agent DNS lockdown, nil-safe: `helm upgrade --reuse-values` from a release that predates the
key carries no security.dnsLockdown, and the lockdown must still default on.
*/}}
{{- define "zelkor-platform.dnsLockdownEnabled" -}}
{{- $dl := (.Values.security | default dict).dnsLockdown | default dict -}}
{{- if hasKey $dl "enabled" -}}{{- ternary "true" "false" (eq (toString $dl.enabled) "true") -}}{{- else -}}true{{- end -}}
{{- end }}

{{- define "zelkor-platform.dnsLockdownWriterDeadline" -}}
{{- (((.Values.security | default dict).dnsLockdown | default dict).writerDeadlineSeconds | default 900) | int -}}
{{- end }}
4 changes: 4 additions & 0 deletions charts/zelkor-platform/templates/contract-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ data:
{{- /* CE-15a-4: HTTP APIs relayed as {release}-api-{name}. */}}
HTTP_APIS: {{ join "," $apis | quote }}
{{- end }}
{{- if eq (include "zelkor-platform.dnsLockdownEnabled" .) "true" }}
{{- /* CE-21: agent pods get no DNS; their hostAliases come from this host map. */}}
AGENT_HOSTS_CONFIGMAP: {{ printf "%s-agent-hosts" $full | quote }}
{{- end }}
{{- if .Values.gateway.enabled }}
GATEWAY_NAME: {{ $pr.name | default (printf "%s-gateway" $full) | quote }}
GATEWAY_NAMESPACE: {{ $pr.namespace | default $ns | quote }}
Expand Down
198 changes: 198 additions & 0 deletions charts/zelkor-platform/templates/security/agent-hosts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
{{- include "zelkor-platform.compile" . -}}
{{- /* CE-21: agent pods run without DNS. This writes the host map (one key per hostname, value =
ClusterIP) that fills their hostAliases: the admission policy below on K8s >= 1.36, or
`zelkor deploy` on older clusters. Plain Job, not a hook: Helm must not wait on it. */ -}}
{{- if eq (include "zelkor-platform.dnsLockdownEnabled" .) "true" }}
{{- $fullname := include "zelkor-platform.fullname" . }}
{{- $ns := .Release.Namespace }}
{{- $cm := printf "%s-agent-hosts" $fullname }}
{{- $dataplane := include "zelkor-platform.envoyDataplaneHost" . | trim }}
{{- $dpNs := "" }}
{{- if $dataplane }}{{- $dpNs = index (splitList "." $dataplane) 1 }}{{- end }}
{{- $services := list (printf "%s-ai-gateway" $fullname) (printf "%s-mcp" $fullname) (printf "%s-otlp" $fullname) (printf "%s-postgresql" $fullname) (printf "%s-langfuse" $fullname) (printf "%s-valkey" $fullname) }}
{{- range (.Values.__httpApis | default "[]" | fromJsonArray) }}
{{- $services = append $services (printf "%s-api-%s" $fullname .name) }}
{{- end }}
{{- $required := list }}
{{- if and .Values.aiGateway.enabled .Values.aiGateway.inClusterService.enabled $dataplane }}
{{- $required = append $required (printf "%s-ai-gateway" $fullname) }}
{{- end }}
{{- if and (eq (include "zelkor-platform.mcpMcprouteEnabled" .) "true") $dataplane }}
{{- $required = append $required (printf "%s-mcp" $fullname) }}
{{- end }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ $fullname }}-agent-hosts
namespace: {{ $ns }}
labels:
{{- include "zelkor-platform.labels" (dict "root" . "intent" "security.dnsLockdown") | nindent 4 }}
automountServiceAccountToken: true
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ $fullname }}-agent-hosts
namespace: {{ $ns }}
labels:
{{- include "zelkor-platform.labels" (dict "root" . "intent" "security.dnsLockdown") | nindent 4 }}
rules:
- apiGroups: [""]
resources: [services]
verbs: [get]
- apiGroups: [""]
resources: [configmaps]
verbs: [create]
- apiGroups: [""]
resources: [configmaps]
resourceNames: [{{ $cm | quote }}]
verbs: [get, update]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ $fullname }}-agent-hosts
namespace: {{ $ns }}
labels:
{{- include "zelkor-platform.labels" (dict "root" . "intent" "security.dnsLockdown") | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ $fullname }}-agent-hosts
subjects:
- kind: ServiceAccount
name: {{ $fullname }}-agent-hosts
namespace: {{ $ns }}
{{- if and $dpNs (ne $dpNs $ns) }}
---
# Read the Envoy dataplane Service that the gateway ExternalNames point at.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ $fullname }}-agent-hosts
namespace: {{ $dpNs }}
labels:
{{- include "zelkor-platform.labels" (dict "root" . "intent" "security.dnsLockdown") | nindent 4 }}
rules:
- apiGroups: [""]
resources: [services]
verbs: [get]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ $fullname }}-agent-hosts
namespace: {{ $dpNs }}
labels:
{{- include "zelkor-platform.labels" (dict "root" . "intent" "security.dnsLockdown") | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ $fullname }}-agent-hosts
subjects:
- kind: ServiceAccount
name: {{ $fullname }}-agent-hosts
namespace: {{ $ns }}
{{- end }}
---
apiVersion: batch/v1
kind: Job
metadata:
# Per revision: a Job's pod template is immutable, so a fixed name would break `helm upgrade`.
name: {{ $fullname }}-agent-hosts-{{ .Release.Revision }}
namespace: {{ $ns }}
labels:
{{- include "zelkor-platform.labels" (dict "root" . "intent" "security.dnsLockdown") | nindent 4 }}
app.kubernetes.io/component: agent-hosts
spec:
ttlSecondsAfterFinished: 600
backoffLimit: 10
activeDeadlineSeconds: {{ include "zelkor-platform.dnsLockdownWriterDeadline" . }}
template:
metadata:
labels:
{{- include "zelkor-platform.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: agent-hosts
spec:
restartPolicy: OnFailure
serviceAccountName: {{ $fullname }}-agent-hosts
{{- include "zelkor-platform.imagePullSecrets" . | nindent 6 }}
containers:
- name: writer
image: {{ include "zelkor-platform.image" .Values.mcp.image | quote }}
imagePullPolicy: {{ include "zelkor-platform.imagePullPolicy" (dict "root" . "image" .Values.mcp.image) }}
command: ["python", "/app/mcp/ops/agent_hosts.py"]
env:
- name: AGENT_HOSTS_SERVICES
value: {{ join " " $services | quote }}
- name: AGENT_HOSTS_REQUIRED
value: {{ join " " $required | quote }}
- name: AGENT_HOSTS_NAMESPACE
value: {{ $ns | quote }}
- name: AGENT_HOSTS_CONFIGMAP
value: {{ $cm | quote }}
- name: AGENT_HOSTS_RELEASE
value: {{ .Release.Name | quote }}
- name: AGENT_HOSTS_DEADLINE_S
value: {{ include "zelkor-platform.dnsLockdownWriterDeadline" . | quote }}
{{- include "zelkor-platform.logEnv" (dict "root" . "name" "zelkor-agent-hosts") | nindent 12 }}
resources:
requests: {cpu: 10m, memory: 32Mi}
limits: {cpu: 200m, memory: 128Mi}
{{- if .Capabilities.APIVersions.Has "admissionregistration.k8s.io/v1/MutatingAdmissionPolicy" }}
---
# K8s >= 1.36: every new agent pod of this platform gets no DNS and the current host map.
# One JSONPatch per entry: a CEL-built list of objects panics the 1.36.4 API server.
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicy
metadata:
name: {{ printf "%s-%s-agent-no-dns" $fullname $ns | trunc 253 }}
labels:
{{- include "zelkor-platform.labels" (dict "root" . "intent" "security.dnsLockdown") | nindent 4 }}
spec:
paramKind:
apiVersion: v1
kind: ConfigMap
matchConstraints:
resourceRules:
- apiGroups: [""]
apiVersions: [v1]
operations: [CREATE]
resources: [pods]
objectSelector:
matchLabels:
zelkor.io/platform-release: {{ .Release.Name | quote }}
matchExpressions:
- key: zelkor.io/workload-type
operator: In
values: [agent, app]
failurePolicy: Fail
reinvocationPolicy: IfNeeded
mutations:
- patchType: JSONPatch
jsonPatch:
expression: >
[
JSONPatch{op: "add", path: "/spec/dnsPolicy", value: "None"},
JSONPatch{op: "add", path: "/spec/dnsConfig",
value: Object.spec.dnsConfig{nameservers: ["127.0.0.1"]}},
JSONPatch{op: "add", path: "/spec/hostAliases", value: []}
] + params.data.map(h, JSONPatch{op: "add", path: "/spec/hostAliases/-",
value: Object.spec.hostAliases{ip: params.data[h], hostnames: [h]}})
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingAdmissionPolicyBinding
metadata:
name: {{ printf "%s-%s-agent-no-dns" $fullname $ns | trunc 253 }}
labels:
{{- include "zelkor-platform.labels" (dict "root" . "intent" "security.dnsLockdown") | nindent 4 }}
spec:
policyName: {{ printf "%s-%s-agent-no-dns" $fullname $ns | trunc 253 }}
paramRef:
name: {{ $cm }}
namespace: {{ $ns }}
# No map yet: refuse the pod rather than start it with DNS. Its ReplicaSet retries.
parameterNotFoundAction: Deny
{{- end }}
{{- end }}
Loading
Loading