tfy-agent

by TrueFoundry

Helm chartv0.2.114Verified publisher

Truefoundry workload agent for k8s clusters

About this chart

Tfy-agent helm chart packaged by TrueFoundry

Tfy-agent is an application that runs on the compute plane Kubernetes cluster to connect to the TrueFoundry control plane.

This application has two parts.

  1. TFY Agent
    • This is used to stream the state of the compute plane cluster to the control plane.
  2. TFY Agent Proxy
    • This enables the control plane to access the compute plane cluster's Kubernetes API server.

Compute plane cluster authorization

TFY Agent

  • TFY Agent runs informers to stream kubernetes resource updates and send it to the control plane.
  • To run informers, the TFY Agent needs to be able to list and watch those resource types across all the namespaces in the cluster.
    • The config.allowedNamespaces field allows you to configure a list of allowed namespaces. TFY Agent will filter out any namespaced resource's update if the resource is not part of the allowed namespaces.

TFY Agent Proxy

  • The proxy ServiceAccount is never granted cluster-admin (apiGroups/resources/verbs: *). Only the enumerated least-privilege rules are applied.
  • Rules never grant secrets get/list/watch/delete, or pods create. Secrets may only be created/patched (server-side apply); pods are not created by the proxy (Argo CD / controllers own that).
  • Note: Kubernetes returns the full object (including data) on Secret patch responses, so patch is not a complete “no-read” guarantee. Prefer config.allowedNamespaces to limit where Secret apply is allowed.
  • Optional feature permissions (default true; set false to drop those rules):
    • tfyAgentProxy.clusterRole.enableSpark — SparkApplication / SparkConnect / Spark-UI VirtualService (+ agent SparkApplication list/watch)
    • tfyAgentProxy.clusterRole.enableIntercepts — EnvoyFilter for traffic intercept / shadow
    • tfyAgentProxy.clusterRole.enableAlerts — PrometheusRule / AlertmanagerConfig / ExternalSecret for alert configs

Cluster Scope resource access

  • This file documents all the authorization rules we set for the resources for which we require cluster-scope access.
  • Note that if you have configured a list of allowed namespaces, the control plane cannot create any new namespace in the cluster.

Namespace Scope resource access

  • This file documents all the authorization rules we set for the resources the control plane can work with namespace-scope access.
  • If you give a list of allowed namespaces using the config.allowedNamespaces field, we use setup role binding for only those namespaces.
  • If the list of allowed namespaces is empty. We set up cluster-wide access for these namespaced resources.

Network policies

Set networkPolicy.enabled: true to create NetworkPolicies on the same model as the truefoundry chart, without its in-release mesh (tfy-agent, tfy-agent-proxy and sds-server never call each other). They select this release's tfy-agent, tfy-agent-proxy and sds-server pods (app.kubernetes.io/instance: <release> and their app.kubernetes.io/name):

PolicyPurpose
<release>-default-deny-ingressBlock all ingress to the release's pods by default
<release>-allow-all-egressAllow all egress (API server, NATS, control plane, DNS)
<release>-sds-server-clientsAllow sds-server's port (8000) from networkPolicy.sdsServer.ingressFrom; by default every namespace, because its clients are Envoy sidecars and gateways in workload namespaces
<release>-ingress-externalOne policy for cross-namespace sources (allowedIngressFrom) and raw rules (extraIngress); only rendered when either is set

With nothing else configured, nothing can reach tfy-agent or tfy-agent-proxy, so Alertmanager can no longer post to /alerts and Prometheus can no longer scrape /metrics. List those callers when you enable the policies. Policy names longer than 63 characters are shortened to a 54-character prefix plus a hash.

Minimal setup, with Prometheus and Alertmanager in the prometheus namespace:

networkPolicy:
  enabled: true
  allowedIngressFrom:
    - namespace: prometheus

Only specific pods in a namespace, plus a CIDR (for example a VPN) on tfy-agent's port:

networkPolicy:
  enabled: true
  allowedIngressFrom:
    - namespace: prometheus
      podSelector:
        app.kubernetes.io/name: alertmanager
    - namespace: prometheus
      podSelector:
        app.kubernetes.io/name: prometheus
  extraIngress:
    - from:
        - ipBlock:
            cidr: 10.0.0.0/8
      ports:
        - port: 3000
          protocol: TCP

sds-server limited to TrueFoundry workload namespaces instead of every namespace:

networkPolicy:
  enabled: true
  sdsServer:
    ingressFrom:
      - namespaceSelector:
          matchLabels:
            truefoundry.com/managed-by: servicefoundry

Each allowedIngressFrom entry requires namespace; add podSelector to narrow it to specific pods. Use extraIngress for anything else, such as an ipBlock, a port restriction or matchExpressions; its entries are raw NetworkPolicyIngressRule objects appended verbatim to <release>-ingress-external.

The external-secrets and reloader subchart pods are not selected and keep their default behavior; the external-secrets webhook has to stay reachable from the API server.

Security contexts

From 0.2.110, tfy-agent, tfy-agent-proxy and sds-server run non-root with a read-only root filesystem, no privilege escalation, all capabilities dropped and the RuntimeDefault seccomp profile. Defaults live in global.podSecurityContext and global.containerSecurityContext; each component's podSecurityContext / securityContext overrides single fields.

ComponentUserWritable paths (emptyDir)
tfy-agent1001 (appuser in the image)/tmp (160Mi, kubectl cache), /app/.kube (2Mi, generated kubeconfig), /app/yamls (8Mi, manifests for kubectl apply)
tfy-agent-proxy65532 (nonroot; the image itself defaults to root)none
sds-server65532 (image default)none

tfy-agent's emptyDirs, and KUBECACHEDIR=/tmp/kube-cache (kubectl's discovery cache, otherwise under the read-only $HOME), are only added while its root filesystem is read-only. If you already mount /tmp, /app/.kube or /app/yamls through tfyAgent.extraVolumeMounts, remove that mount or set tfyAgent.securityContext.readOnlyRootFilesystem: false.

The emptyDir size limits are tfyAgent.emptyDir.{tmp,kube,yamls}.sizeLimit ("" for no limit). Together they stay inside tfy-agent's 256Mi ephemeral-storage limit with room for container logs and the custom CA emptyDir; if you raise one, raise tfyAgent.resources.limits.ephemeral-storage with it, or the kubelet evicts the pod.

Opt-outs:

# Everything off (the pre-0.2.110 output)
global:
  podSecurityContext:
    enabled: false
  containerSecurityContext:
    enabled: false

# Or per component, e.g. keep tfy-agent-proxy on the image's root user
tfyAgentProxy:
  podSecurityContext:
    runAsNonRoot: false
    runAsUser: 0

sds-server's pod no longer mounts a ServiceAccount token (sdsServer.serviceAccount.automountServiceAccountToken, default false), even when it uses an existing ServiceAccount; it does not call the Kubernetes API.

Troubleshoot

Using self-signed certificate in control plane URL

If your control plane URL is using self-signed CA certificate, follow these steps:

  1. Update CA bundle in the container by mounting your CA bundle. This can be done in two ways:

    1. using volume mounts

      • create a config map using your ca-certificate.crt file

        kubectl create configmap tfy-ca-cert -n tfy-agent --from-file=ca-certificate.crt

      • add following volume and volume mounts in both tfyAgent and tfyAgentProxy

        tfyAgent:
            extraVolumes:
            - name: ca-certificates-volume
              configMap:
                name: tfy-ca-cert
                items:
                - key: ca-certificates.crt
                  path: ca-certificates.crt
            extraVolumeMounts:
                - name: ca-certificates-volume
                  mountPath: /etc/ssl/certs/ca-certificates.crt
                  subPath: ca-certificates.crt
                  readOnly: true
        tfyAgentProxy:
            extraVolumes:
            - name: ca-certificates-volume
              configMap:
                name: tfy-ca-cert
                items:
                - key: ca-certificates.crt
                  path: ca-certificates.crt
            extraVolumeMounts:
                - name: ca-certificates-volume
                  mountPath: /etc/ssl/certs/ca-certificates.crt
                  subPath: ca-certificates.crt
                  readOnly: true
        
    2. using jspolicy - link

  2. Add extraEnv in tfyAgent to allow insecure connection

    tfyAgent:
        extraEnvVars:
            - name: NODE_TLS_REJECT_UNAUTHORIZED
              value: '0'
    

Parameters

Global parameters for tfy-agent

NameDescriptionValue
global.labelsGlobal labels to add to all resources{}
global.annotationsGlobal annotations to add to all resources{}
global.podLabelsGlobal labels to add to all pods{}
global.podAnnotationsGlobal annotations to add to all pods{}
global.deploymentLabelsGlobal labels to add to all deployments{}
global.deploymentAnnotationsGlobal annotations to add to all deployments{}
global.serviceLabelsGlobal labels to add to all services{}
global.serviceAnnotationsGlobal annotations to add to all services{}
global.serviceAccount.nameGlobal service account name to use as fallback when component-specific service account is not created and no name is specified""
global.serviceAccount.labelsGlobal labels to add to all service accounts{}
global.podSecurityContext.enabledApply pod security conte

Deploy tfy-agent with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has tfy-agent 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 charttfy-agent is pinned at v0.2.114 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