varek

by joaquinito2051

Helm chartv1.36.3App 1.36.3

VAREK on Kubernetes: the Warden's node agent, NRI plugin and launcher on each node (a DaemonSet), the VarekPolicy resource and its admission webhook. Each container of a pod that names a policy (the annotation varek.dev/policy) runs with the Warden deciding its calls under that policy, or does not run.

About this chart

VAREK's Helm chart

VAREK on Kubernetes (v1.34, docs/security/v1.34-kubernetes.md). Each container of a pod that names a policy runs with the Warden deciding its calls under that policy, as on a host, or does not run: its seccomp profile is VAREK's unsupervised one (every call refused), which only the NRI plugin replaces, with the Warden's filter. A node without the plugin, or a plugin that does not answer the runtime in time, leaves the profile in place, and the container does not start. The chart installs:

  • on each node (a DaemonSet): the Warden's node agent, the NRI plugin (varek-nri), which writes each container's filter and adds the launcher, the exporter, which gives each container's stream as OCSF in its log, and the unsupervised profile, under the kubelet's seccomp root;
  • the VarekPolicy resource (varek.dev/v1alpha1), a policy as written for the Warden, kept in the pod's namespace;
  • the VarekPlan resource (from 1.35), a plan as written for the Warden, kept in the pod's namespace beside its policy;
  • the VarekCredential resource (from 1.36), cluster-scoped: a credential a policy names, given from one source to the namespaces whose policies may name it;
  • the admission webhook (varek-admission), which refuses a policy the Warden does not load, and most of what the node agent would refuse at a container's start (the rest fails at the start).

Requirements

  • Kubernetes 1.30 or later (from 1.30 a pod's service account token names its node, which a node's key is tied to), Linux nodes with Landlock (kernel 5.13 or later). CI runs Kubernetes 1.35, 1.36 and 1.37 (the repository README's platform table); earlier versions the chart takes are not tested.
  • The kubelet's root at node.kubelet (/var/lib/kubelet): the DaemonSet mounts its pods/ directory, which must exist (a pod acting for a user's token is read there), so a node whose kubelet keeps its root elsewhere sets node.kubelet.
  • A runtime whose NRI lets a plugin set a container's seccomp policy and command: containerd 2.2 or later (EKS, kind), or CRI-O 1.35 or later (OpenShift). With an earlier one the plugin says so in its log and does not start, and the supervised pods on that node do not run.
  • amd64 or arm64 nodes: the release builds the node image for both, as one image (v1.36), and the DaemonSet is placed on every Linux node (nodeSelector). A supervised pod placed on a node without the node agent does not run.
  • A namespace of its own that admits privileged pods. The node agent is privileged on the node, in the node's PID namespace, as Falco and Tetragon are.

Install

The chart and its image are published together, each signed with cosign by the release workflow (.github/workflows/container-release.yml). The chart pins its image by the digest that was signed.

kubectl create namespace varek-system
kubectl label namespace varek-system pod-security.kubernetes.io/enforce=privileged
helm install varek-crds oci://ghcr.io/kwdoug63/charts/varek-crds --version VERSION -n varek-system
helm install varek oci://ghcr.io/kwdoug63/charts/varek --version VERSION -n varek-system

The custom resources (VarekPolicy, VarekPlan, VarekCredential, VarekNodeKey) are a chart of their own, varek-crds (packaging/helm/varek-crds), installed first: Red Hat's chart certification refuses a chart that holds a CRD, and helm upgrade changes a chart's templates where it never changes its crds/. Installed on a cluster without them, this chart refuses and says so (crds.check). The split is from 1.36.1; the charts of 1.36.0 and before hold them: install one of those alone.

To check the signatures first:

cosign verify ghcr.io/kwdoug63/charts/varek:1.36.3 \
  --certificate-identity https://github.com/kwdoug63/varek/.github/workflows/container-release.yml@refs/tags/v1.36.3 \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com

and the same for ghcr.io/kwdoug63/charts/varek-crds:1.36.3 and ghcr.io/kwdoug63/varek-node:1.36.3. From v1.36 the node image is one image for amd64 and arm64, and each architecture's is also tagged :<version>-amd64 and :<version>-arm64, signed the same way, with its bill of materials attested on it (cosign verify-attestation --type cyclonedx on that tag, with the same two options).

On OpenShift (CRI-O), add --set runtime=cri-o --set openshift.enabled=true. This creates a SecurityContextConstraints that only the node agent's service account may use.

A supervised pod

apiVersion: varek.dev/v1alpha1
kind: VarekPolicy
metadata: { name: agent, namespace: team-a }
spec:
  policy: |
    require warden 1.29
    allow path /work/
    allow host api.example.com:443
---
apiVersion: v1
kind: Pod
metadata:
  name: agent
  namespace: team-a
  annotations: { varek.dev/policy: agent }
spec:
  containers:
    - name: agent
      image: example/agent:1
      command: ["/usr/bin/agent"]
      securityContext:
        allowPrivilegeEscalation: false
        runAsNonRoot: true
        runAsUser: 1000
        runAsGroup: 1000
        readOnlyRootFilesystem: true
        capabilities: { drop: [ALL] }
        seccompProfile: { type: Localhost, localhostProfile: varek/unsupervised.json }
      volumeMounts: [{ name: work, mountPath: /work }]
  volumes: [{ name: work, emptyDir: {} }]

The webhook refuses an annotated pod whose containers would be refused at their start, and says why. A container must:

  • name VAREK's unsupervised seccomp profile (Localhost, varek/unsupervised.json), on the container or the pod;
  • turn privilege escalation off;
  • drop every capability, and add none;
  • not run as root, nor in group 0 (runAsGroup, supplementalGroups, fsGroup);
  • name its command by an absolute path;
  • not use the node's network, PID or IPC namespace, nor share a PID namespace with the pod's other containers (shareProcessNamespace);
  • use the cluster's DNS (no dnsPolicy: None, no dnsConfig.nameservers): the policy's host names are resolved through the pod's DNS server;
  • give no runtime class, or one in admission.runtimeClasses (a sandboxed runtime, Kata or gVisor, does not run the Warden's filter);
  • have a read-only root under a policy that decides launches.

A pod's varek.dev/policy annotation is not added, changed or removed after it is created.

Label a namespace varek.dev/policy-required=true to also refuse its pods that name no policy.

A plan (from 1.35)

A pod can name a plan as it names its policy: a VarekPlan of its namespace, by the annotation varek.dev/plan: NAME. The node agent decides the plan with the pod's policy as each container starts, in the container's view (each step SATISFIED, or the container does not run), and holds the run to it: a call the policy allows and no step of the plan covers is refused (outside_plan). A policy that says require plan admits no pod that names no plan.

apiVersion: varek.dev/v1alpha1
kind: VarekPlan
metadata: { name: summarize, namespace: team-a }
spec:
  plan: |
    plan 1.35
    action read file_open /work/ open=read
    action api net_connect api.example.com:443

and on the pod, beside varek.dev/policy: agent, varek.dev/plan: summarize. What the agent's own runtime reads as it starts is held too, so it is a step as well (file_open /usr/ open=read and the like). The webhook refuses a plan the Warden does not read, a pod naming a plan not in its namespace, and a pod naming a plan whose policy does not say require warden 1.35 (a node still on 1.34 during an upgrade would run it under its policy alone, not held; with that line it refuses the container). Like the policy's, a pod's varek.dev/plan annotation is not added, changed or removed after it is created.

A plan is bound by its name, as a policy is: each container start (a restart too) takes the VarekPlan of that name as it is then, so whoever may update varekplans in the namespace decides what its pods are held to. The run's first record names the plan it was held to by its SHA-256 (run_start.hold.plan_sha256).

Helm installs a chart's CRDs only when it first installs the chart: on an upgrade apply every CRD of the release first (see Upgrading).

Credentials (from 1.36)

A policy names a credential as on a host (credential gh_token from file:/var/lib/varek/credentials/gh-token/token, then credential=gh_token header=Authorization on a request rule). On a node, the node agent fetches its value with warden-secrets, in the node agent's own network and under the DaemonSet's identity, and hands it to the proxy in the pod's network. The agent's pod never holds it: the plugin sets a placeholder (VAREK_CRED_GH_TOKEN=varek_ph_gh_token_...), new for each container, which the proxy replaces on the requests the policy names.

A cluster administrator gives each credential to namespaces:

apiVersion: varek.dev/v1alpha1
kind: VarekCredential
metadata:
  name: gh-token
spec:
  credential: gh_token
  source: file:/var/lib/varek/credentials/gh-token/token
  namespaces: [agents]

A pod runs only where a VarekCredential gives each credential its policy names, from the policy's source, to the pod's namespace: the webhook refuses the pod otherwise, and the node agent refuses the container at its start (from the list the plugin writes on each node, POLICY_DIR/.credentials). The webhook also refuses a VarekCredential whose file: source is not under credentials.dir. Whoever may write varekcredentials decides which namespaces' agents may use which values; whoever may write a namespace's varekpolicies decides which requests carry them.

The sources:

  • file:: a key of a Secret of the chart's namespace, named in credentials.secrets, mounted in the node agent at credentials.dir/<secret>/<key> (root's, 0400);
  • vault:: credentials.vault.addr, with Vault's Kubernetes auth (kubernetesAuth.role): the node agent's service account's token, which the kubelet projects with audience kubernetesAuth.audience, logs in as that role; caSecret names a Secret with ca.crt to verify Vault with;
  • aws-sm:: IRSA (credentials.aws.roleArn: that role, assumed with a projected token of audience sts.amazonaws.com), or EKS Pod Identity (credentials.aws.podIdentity: the role associated with the node agent's service account, from the node's Pod Identity agent), or neither: the node's instance role (IMDSv2).

The chart writes warden-secrets' configuration from these values (a Secret, <release>-node-secrets-conf). It holds no token or key.

Helm installs a chart's CRDs only when it first installs the chart: on an upgrade apply every CRD of the release first (see Upgrading).

Sub-agents and confined MCP servers (from 1.36)

A policy names sub-agents (allow exec PATH subagent=NAME) and confined MCP servers (mcp server NAME exec PATH) as on a host. The container's own control group (the runtime's) is the run's: the node agent makes each sub-agent's group below it from the node, and attributes each call by the calling process's group, so a sub-agent's calls, and those of everything it starts, are its own whatever it says. The pod gets no capability and nothing is delegated to it. A plan's subagent and mcp_call steps are decided as on a host (an mcp_call to a stdio server is UNKNOWN there too).

The node's own refusals: a sub-agent launched by the container's first process itself (subagent_first_process: that process stays in the container's group, so a process started in the container later, with kubectl exec, is not put in a sub-agent's), and a container running as root. A pod's network has none of the kernel's process events, so a sub-agent of the program its launcher runs is told from a failed launch by its memory layout, and refused where the node's layouts are not randomized (kernel.randomize_va_space not 2).

A pod acting for a user (from 1.36)

A policy trusts the user's token's issuer (trust issuer URL audience AUD [jwks URL]) as on a host, and may say require on-behalf-of. A pod acting for a user names the Secret holding the token (key token):

metadata:
  annotations:
    varek.dev/policy: agent
    varek.dev/on-behalf-of: alice-token

The webhook's mutating hook gives the pod a Secret volume of it, varek-obo, and an init container that alone mounts it: the node image, /bin/true, not root, with no privilege and the runtime's default seccomp profile. The kubelet mounts no volume that no container names, so the init container is what makes the kubelet keep a copy on the node. The node agent reads that copy by the pod's uid, under node.kubelet's pods/ (mounted read-only, as the kubelet mounts each volume, with HostToContainer propagation). warden-secrets verifies the token on the node as the Warden's --on-behalf-of does on a host. run_start names the user, and every decision is the user's. No container of the agent's can read the token: the webhook refuses a pod whose other containers mount varek-obo, an ephemeral container added later that mounts it, an init container of that name other than its own, and the annotation added, changed or removed after the pod is created. A pod naming no Secret under a policy that says require on-behalf-of is refused at deploy, and again by the node agent.

An issuer reached over TLS with a private CA, such as the cluster's own service account issuer, is verified with onBehalfOf.issuerCaConfigMap (kube-root-ca.crt for that one). Its discovery document and keys must be readable by the node agent's pod without credentials. On many clusters that means binding system:service-account-issuer-discovery to system:unauthenticated, as for federation.

The agent's SVID (a policy's trust spiffe DOMAIN bundle FILE) comes from the node's SPIRE agent through its Delegated Identity API. varek-svid

Deploy varek with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has varek on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartvarek is pinned at v1.36.3 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply