Skip to content

Configuration ​

This page covers all configuration options for the Kloak controller and webhook, namespace and workload enablement, and production resource tuning.

Controller Flags ​

The controller runs as a DaemonSet on every node. It manages secret reconciliation and eBPF uprobe attachment.

FlagDefaultDescription
--health-probe-bind-address:8081Address for health (/healthz) and readiness (/readyz) probe endpoints.
--cgroup-path/sys/fs/cgroupPath to the cgroup v2 filesystem. When running in a container with a host mount, this is typically /host/sys/fs/cgroup.
--trusted-dns-servers(empty)Comma-separated DNS server IPs trusted in addition to kube-dns. Only answers from trusted servers are rewritten to virtual IPs for host-restricted secrets. kube-dns's ClusterIPs and the addresses of its endpoints are discovered and kept current. Set via the Helm value controller.dns.trustedServers (a YAML list).
--enable-ebpffalseLoad the eBPF programs and attach TLS uprobes. The Helm chart sets this to true (controller.ebpf.enabled).
--egress-interfaceautoContainer interface whose host-side veth peer gets the tc patch program. auto uses the interface of the container's default IPv4 route, or of its default IPv6 route in an IPv6-only pod; a name pins it; none (or lo-only) disables the tc program, so no secret is rewritten. Set via controller.ebpf.egressInterface.
--tc-attach-modeautoHow the tc patch program is attached: auto uses TCX on Linux 6.6+ and falls back to a clsact qdisc + cls_bpf filter on older kernels; tcx requires TCX; clsact always uses the classic filter. Set via controller.ebpf.tcAttachMode.
--secret-bindingenforceWhich pods may use a secret: only pods that reference it in their spec. enforce refuses the rewrite for any other pod; audit allows it but logs each violation. Set via controller.ebpf.secretBinding. See Per-Pod Secret Binding.
--sni-checkenforceA secret restricted to a hostname is only rewritten on a connection whose TLS ClientHello names that host (SNI). enforce refuses other rewrites; audit allows them but logs each one. Set via controller.ebpf.sniCheck. See SNI check.
--virtual-ip-range198.18.0.0/15,2001:2::/48The ranges virtual IPs come from: an IPv4 range (/19 or larger) and, optionally, an IPv6 range (/115 or larger), comma-separated. Set via controller.ebpf.virtualIPRange. See Virtual IP Ranges.
--nri-socket/var/run/nri/nri.sockNRI socket of the container runtime (containerd 2.0+, CRI-O 1.30+). "" disables NRI. Set via controller.nri.enabled and controller.nri.socketPath. See Container Runtime Hook (NRI).

Environment Variables ​

The controller and webhook read these environment variables (set automatically by the chart):

VariableDescription
NODE_NAMEThe Kubernetes node name. Used to filter pod watches so each controller instance only manages pods on its own node. Populated from spec.nodeName via the downward API.
KLOAK_LOG_LEVELLog level: trace, debug, info, warn, or error. From the Helm value log.level (default info). Controller and webhook.
KLOAK_LOG_DEVtrue switches to human-readable console logs. From log.dev (default false). Controller and webhook.
KLOAK_BPF_LOG_LEVELeBPF verifier log level when loading programs: branch, instruction, or stats. From log.ebpfLevel (default empty). Controller only.
POD_NAMESPACESet on the controller from metadata.namespace. Currently unused.

Webhook Flags ​

The webhook runs as a Deployment and serves the mutating (pod) and validating (Secret) admission endpoints.

FlagDefaultDescription
--health-probe-bind-address:8081Address for health and readiness probe endpoints.
--cert-dir/certsDirectory containing the TLS certificate and key files (tls.crt, tls.key). Mounted from the kloak-webhook-certs secret, or from certificates.provided.secretName in provided mode.

The webhook listens on port 9443 for admission requests. The Service fronting the webhook maps port 443 to this target port.

Webhook Certificates ​

Kubernetes requires all admission webhooks to serve TLS. When the API server intercepts a pod creation and forwards it to Kloak's mutating webhook, the connection must be encrypted. The API server also needs a trusted CA bundle to verify the webhook's certificate -- this is set in the caBundle field of the MutatingWebhookConfiguration and ValidatingWebhookConfiguration.

Kloak needs a TLS certificate and key pair for the webhook service, and the corresponding CA certificate must be registered with the API server so it trusts the webhook endpoint.

Certificate management is configured via the Helm value certificates.mode:

auto (default) ​

Helm generates a self-signed TLS certificate at install time, stores it in the kloak-webhook-certs secret, and sets the caBundle on both webhook configurations. This is the recommended mode for most deployments -- no additional setup required.

certManager ​

Integrates with cert-manager. Helm creates a Certificate and Issuer resource. The cert-manager cainjector automatically patches the caBundle on both webhook configurations. Use this mode if you already run cert-manager and want automated certificate rotation.

yaml
# values.yaml
certificates:
  mode: certManager
  certManager:
    issuerRef:
      name: kloak-selfsigned
      kind: Issuer

provided ​

Helm skips certificate generation entirely and expects the secret named by certificates.provided.secretName (default kloak-webhook-certs) to already exist. The chart does not set a caBundle in this mode: either the certificate must chain to a CA the API server already trusts, or you must set caBundle on both webhook configurations yourself (for example with cert-manager's cainjector). Use this mode when managing certificates externally (e.g., through your own PKI or a secrets management tool).

yaml
# values.yaml
certificates:
  mode: provided
  provided:
    secretName: kloak-webhook-certs
    certKey: tls.crt
    keyKey: tls.key

Using cert-manager with provided mode

If you prefer full control, you can use provided mode with a cert-manager Certificate resource targeting the kloak-webhook-certs secret. You will need to set the caBundle on the MutatingWebhookConfiguration and ValidatingWebhookConfiguration yourself, or use cert-manager's cainjector.

Enablement Model ​

Kloak uses a strict opt-in model. Nothing is intercepted unless explicitly enabled. For Kloak to protect a secret end-to-end, two things must be enabled independently:

  1. The secret itself -- tells Kloak which secrets to protect. Enabling a secret causes the controller to create a shadow copy with random kl:: placeholders and load the shadow-to-real mapping into the eBPF map on each node. Without this, no shadow secret exists and there is nothing to rewrite.

  2. The workload -- tells Kloak which pods should have their TLS writes intercepted. Enabling a workload causes the webhook to rewrite Secret references (volumes, env[].valueFrom.secretKeyRef, and envFrom[].secretRef) to point to shadow secrets, and the controller to attach eBPF uprobes to the pod's process. Without this, the pod mounts the original secret and no eBPF interception occurs.

Both sides are required. Enabling only the secret creates the shadow copy but no pod uses it. Enabling only the workload attaches uprobes but rewrites nothing, because the webhook only rewrites references to kloak-enabled secrets.

A kloak-enabled pod can also only use the secrets it references in its own spec. See Per-Pod Secret Binding.

Secret Enablement ​

Label any secret to have Kloak create a shadow copy. Destination filters go in annotations:

yaml
apiVersion: v1
kind: Secret
metadata:
  name: my-secret
  labels:
    getkloak.io/enabled: "true"           # Required: triggers shadow secret creation
  annotations:
    getkloak.io/hosts: "api.example.com"  # Optional: restrict allowed destination host
    getkloak.io/port: "443"               # Optional: restrict allowed destination port
type: Opaque
stringData:
  token: "my-real-token-value"

When the SecretReconciler detects this label, it creates my-secret-kloak with a random kl:: placeholder for each key, exactly as long as the real value (and with the same HPACK Huffman length, so HTTP/2 rewrites stay valid). Whenever an enabled secret or its shadow is created, changed or deleted, the controller joins each enabled secret with its shadow and syncs the shadow-to-real mapping into the eBPF map in the kernel. It also resyncs every 5 minutes. The original secret is untouched.

A key whose value can't be rewritten (shorter than 8 bytes, or with a character mix no same-length placeholder can match) is left out of the shadow, and the secret's other keys are still shadowed. A pod gets no value for that key, never the real one. If no key qualifies, no shadow is created. The validating webhook rejects such values at admission, so this only happens when the webhook is bypassed.

The validating webhook rejects a kloak-enabled Secret at kubectl apply time if:

  • getkloak.io/hosts or getkloak.io/port is set as a label instead of an annotation
  • the host is not a single lowercase DNS name of at most 63 bytes, an IP address, or *
  • the port is not PORT or PORT/tcp|udp
  • the Secret has no data
  • any value is shorter than 8 or longer than 128 bytes
  • any value's character mix can't be matched by a same-length placeholder (rare; use a different or longer value)

Workload Enablement ​

Workloads can be enabled at two levels -- pod label or namespace label. The kloak-mutating-webhook configuration has two webhooks with Kubernetes selectors so that only kloak-enabled namespaces and pods are sent to the webhook. Non-kloak workloads are never affected, even if the webhook is down.

Pod Label ​

Label individual pods (via the pod template in a Deployment/StatefulSet/DaemonSet):

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  template:
    metadata:
      labels:
        getkloak.io/enabled: "true"
    spec:
      containers:
        - name: app
          # ...

When the pod is created, the webhook rewrites references to kloak-enabled secrets (secret volumes, secretKeyRef, and envFrom.secretRef, in containers, init containers, and ephemeral containers) to the shadow secret. Projected volume sources are not rewritten. It also adds the getkloak.io/enabled annotation so the controller knows to attach eBPF uprobes. If the shadow secret has not been created yet (controller hasn't reconciled), or isn't a Kloak-managed shadow, the webhook rejects the pod to prevent real secrets from being mounted.

Namespace Label ​

Enables Kloak for all pods in a namespace. Useful when an entire namespace should be protected:

bash
kubectl label namespace my-namespace getkloak.io/enabled=true

Every pod created in this namespace is treated as Kloak-enabled, even without an explicit pod label.

WARNING

Labeling a namespace enables Kloak for every pod in that namespace. Make sure all applications are compatible (see Supported Runtimes). Pods using unsupported TLS stacks will fail to have uprobes attached, which is logged as an error but does not block the pod.

Enablement Precedence ​

The webhook checks enablement in the following order, stopping at the first match:

  1. Pod label -- if the pod has the getkloak.io/enabled label, its value decides: "true" enables Kloak, any other value (for example "false") opts the pod out, even in an enabled namespace.
  2. Namespace label -- getkloak.io/enabled: "true" on the pod's namespace.

If neither enables it, the pod is not processed by Kloak. Pods in Kloak's own release namespace are never mutated, and a pod annotation does not enable Kloak.

TIP

Workload-level inheritance (Deployment, DaemonSet, StatefulSet labels) is not supported. Use pod template labels or namespace labels instead.

Per-Pod Secret Binding ​

A placeholder is only rewritten for the pods that reference its secret in their spec, through a secret volume, env[].valueFrom.secretKeyRef, or envFrom[].secretRef in a container or init container. The webhook points these references at the shadow secret, and the controller binds the pod's containers to the secrets they name before it attaches the uprobes. A volume with items, or a secretKeyRef, binds only the keys it names. Ephemeral containers are not bound. The binding is removed when the pod is deleted.

If any other kloak-enabled pod sends the placeholder, even one that learned it from a log or another pod, the placeholder goes out unchanged and the controller logs a warning:

secret binding violation (rewrite refused): pod used a secret it does not reference

This also refuses apps that read a shadow secret through the Kubernetes API instead of mounting it. To find such workloads before enforcing the binding, install with --set controller.ebpf.secretBinding=audit: the rewrite is allowed and each violation is still logged.

Host Filtering ​

The getkloak.io/hosts annotation on a secret controls which TLS destinations receive the real value:

yaml
annotations:
  getkloak.io/hosts: "api.example.com"   # Single host, single IP, or "*" (any)
  getkloak.io/port: "443"                # Optional: PORT or PORT/tcp|udp

Setting either key as a label is rejected by the validating webhook.

A single value only — a comma-separated list is not supported yet and is rejected by the validating webhook (see spinningfactory/kloak#102).

Kloak gives every hostname in a getkloak.io/hosts annotation its own virtual IP. A pod that references a secret restricted to that host gets the virtual IP in place of the host's addresses in DNS answers, and its connections to the virtual IP are redirected to one of the real addresses. The secret is only rewritten on a connection made to the host's virtual IP whose TLS SNI is that host. Anywhere else, the remote server receives the harmless kl::... placeholder. See the Host Filtering guide for details.

Omitting getkloak.io/hosts (or setting it to *) allows the secret to be sent to any destination. Wildcard subdomains such as *.example.com are not supported.

Virtual IP Ranges ​

The virtual IPs come from controller.ebpf.virtualIPRange (--virtual-ip-range): an IPv4 range of /19 or larger and, optionally, an IPv6 range of /115 or larger, comma-separated. The defaults, 198.18.0.0/15 and 2001:2::/48, are reserved for benchmarking (RFC 2544, RFC 5180) and never routed.

At startup the controller refuses to start if a range overlaps a node address, a pod CIDR, a service CIDR, or a route of its node. The service ranges come from the ServiceCIDR API (Kubernetes 1.33+); on older clusters the controller checks the ClusterIPs of the kubernetes and kube-dns Services instead.

To use other ranges, pick ones your cluster and nodes don't use, and escape the comma with --set:

bash
helm upgrade kloak kloak/kloak -n kloak-system --reuse-values \
  --set controller.ebpf.virtualIPRange='10.200.0.0/16\,fd00:6b6c::/112'

Without an IPv6 range, AAAA answers are left unchanged, and an app that connects over IPv6 gets no host-restricted secret.

The virtual IPs and the real addresses behind them are kept in BPF maps pinned under /sys/fs/bpf/kloak, so a controller restart keeps them. While the controller is not running, connections to virtual IPs fail.

Container Runtime Hook (NRI) ​

With containerd 2.0+ or CRI-O 1.30+, Kloak hooks into the container runtime through NRI (the Node Resource Interface). The runtime waits for Kloak while it creates each pod sandbox, so the DNS rewrite is in place before any container of the pod resolves a name, and again before each container starts, so the container's TLS uprobes are attached before its first TLS write.

NRI is on by default (controller.nri.enabled: true, socket /var/run/nri/nri.sock, mounted from the host). On a runtime without NRI, or with it disabled, the controller attaches the DNS rewrite by polling pending pods, and a container's uprobes once the pod's status reports it running. That leaves a short window at pod start: a lookup made in it gets the real addresses (and a connection made with them gets no host-restricted secret until the app resolves the name again), and a TLS write made in it sends the placeholder. The controller logs which way each node runs.

Helm Values ​

KeyDefaultDescription
image.repositoryghcr.io/spinningfactory/kloakController and webhook image.
image.tagchart versionRelease charts pin the matching image version.
image.pullPolicyIfNotPresent
log.levelinfotrace, debug, info, warn, error.
log.devfalseHuman-readable console logs.
log.ebpfLevel""eBPF verifier log level (branch, instruction, stats).
controller.ebpf.enabledtruePassed as --enable-ebpf.
controller.ebpf.egressInterfaceautoPassed as --egress-interface.
controller.ebpf.tcAttachModeautoPassed as --tc-attach-mode.
controller.ebpf.secretBindingenforcePassed as --secret-binding (enforce or audit).
controller.ebpf.sniCheckenforcePassed as --sni-check (enforce or audit).
controller.ebpf.virtualIPRange198.18.0.0/15,2001:2::/48Passed as --virtual-ip-range.
controller.nri.enabledtrueHook into the container runtime through NRI.
controller.nri.socketPath/var/run/nri/nri.sockThe runtime's NRI socket. Its directory is mounted from the host. Passed as --nri-socket.
controller.cgroupPath/host/sys/fs/cgroupPassed as --cgroup-path.
controller.dns.trustedServers[]DNS server IPs trusted in addition to kube-dns, joined into --trusted-dns-servers. Add a node-local cache that pods query at its own address, such as NodeLocal DNSCache's 169.254.20.10.
controller.resourcessee below
webhook.replicas1
webhook.resourcessee below
certificates.modeautoauto, certManager, or provided (see Webhook Certificates).
demo.enabledfalseDeploys a demo app and two demo secrets in demo.namespace (kloak-demo).

Default Resources ​

The default Helm values include conservative resource defaults suitable for development and testing:

Controller (DaemonSet):

yaml
resources:
  requests:
    cpu: 10m
    memory: 64Mi
  limits:
    cpu: 500m
    memory: 512Mi

Webhook (Deployment):

yaml
resources:
  requests:
    cpu: 10m
    memory: 64Mi
  limits:
    cpu: 500m
    memory: 128Mi

Sizing for your workload

The controller's memory usage scales with the number of secrets being tracked and the number of pods being monitored on each node. For clusters with hundreds of secrets, consider increasing the memory limit to 1Gi. The eBPF programs themselves have minimal overhead once loaded.

Custom Resource Overrides ​

Override resources via Helm values:

yaml
# my-values.yaml
controller:
  resources:
    requests:
      cpu: 100m
      memory: 128Mi
    limits:
      cpu: "1"
      memory: 1Gi
bash
helm upgrade kloak kloak/kloak -n kloak-system -f my-values.yaml

Ports Reference ​

ComponentPortPurpose
Controller8081Health and readiness probes
Webhook8081Health and readiness probes
Webhook9443Admission webhook endpoint (TLS)

Security Context ​

The controller requires elevated privileges for eBPF operations. The manifest sets:

yaml
securityContext:
  privileged: true
  runAsUser: 0
  runAsGroup: 0
  appArmorProfile:
    type: Unconfined
  capabilities:
    add:
      - BPF
      - NET_ADMIN
      - SYS_ADMIN
      - SYS_RESOURCE

The controller also requires hostPID: true at the pod level to see container processes (/proc/<pid>/root, /proc/<pid>/exe) for uprobe attachment, to enter pod and host network namespaces when attaching the tc programs, and to read the node's routes for the virtual IP range check.

The webhook does not require any elevated privileges and runs with default security settings.

Volume Mounts (Controller) ​

The controller DaemonSet mounts these host paths:

Mount PathHost PathAccessPurpose
/host/sys/fs/cgroup/sys/fs/cgroupRead-writeCgroup v2 filesystem for resolving container cgroup IDs
/sys/fs/bpf/sys/fs/bpfRead-writeBPF filesystem. The virtual IP maps are pinned under /sys/fs/bpf/kloak so a restart keeps them; programs and other maps are released when the controller stops
/sys/kernel/btf/sys/kernel/btfRead-onlyKernel BTF (BPF Type Format) data for CO-RE (Compile Once, Run Everywhere)
/sys/kernel/tracing/sys/kernel/tracingRead-write (Bidirectional)Tracefs for eBPF tracepoint and kprobe attachment. The mount-tracefs init container mounts tracefs here.
/var/run/nri/var/run/nriRead-writeThe container runtime's NRI socket directory (only when controller.nri.enabled; follows controller.nri.socketPath)

Released under the GNU AGPL-3.0 License.