Credentials in a cluster
In a cluster, Turf™ reads credentials by the same rule as on a laptop: each process reads its own (see Where credentials are read). In a cluster, that rule decides which pod each Secret goes on:
- Provider credentials go on the engine. Provider plugins run there.
- State backend credentials and
TF_VAR_go on the server. The server reads and writes state and evaluates variables. - The CLI configuration goes on both, one ConfigMap, since both install providers from it.
- The identity key is split. restate-server holds the private half, the engine the public half.
Providers: the engine
Section titled “Providers: the engine”Provider plugins run in the engine, so the environment they see is the engine pod’s, and nothing of
the server’s unless the server names variables to send. Put their
credentials in a Secret and give it to the engine’s container with envFrom:
kubectl -n turf create secret generic turf-provider-credentials \ --from-literal=ARM_CLIENT_ID=... --from-literal=ARM_CLIENT_SECRET=... \ --from-literal=ARM_TENANT_ID=... --from-literal=ARM_SUBSCRIPTION_ID=...# The engine's containerenvFrom: - secretRef: name: turf-provider-credentialsThe usual names apply: AWS AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION; Azure
ARM_SUBSCRIPTION_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET, ARM_TENANT_ID; GCP
GOOGLE_APPLICATION_CREDENTIALS, GOOGLE_PROJECT. With the credentials in the environment, a default
provider instance needs no block at all. Provider arguments in the HCL (profile, assume_role,
config_path) override the environment.
A kubernetes or helm provider configured in-cluster authenticates as the engine’s ServiceAccount. What that ServiceAccount may do is what an approved plan may do, so grant exactly what your configurations declare. The configuration in Minimal manifests creates a namespace and a ConfigMap in it, so its engine needs:
apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: turf-enginerules: - apiGroups: [""] resources: [namespaces, configmaps] verbs: [get, list, watch, create, update, patch, delete]---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: turf-enginesubjects: - kind: ServiceAccount name: turf-engine namespace: turfroleRef: kind: ClusterRole name: turf-engine apiGroup: rbac.authorization.k8s.ioA configuration that manages more needs more: widen the ClusterRole to what it declares, or, for a
cluster the agent runs entirely, bind cluster-admin. A configuration that manages nothing in the
cluster needs no binding. turf-kagent’s engine runs a fleet of AWS Lambda functions, so its
ServiceAccount is bound to no Role, and the credential it holds is one AWS key
(An agent in the cluster, with kagent).
Variables the server sends
Section titled “Variables the server sends”Credentials on the engine stay the recommendation. The server can also send providers a provider
environment: the variables it is told to send by name. Set TURF_PROVIDER_ENV in the server
Deployment’s env, naming variables the server’s container holds:
# The server's containerenv: - name: AWS_REGION value: eu-west-1 - name: TURF_PROVIDER_ENV value: AWS_REGIONThe server sends their values to the engine with each run, and the engine keeps them in its store with the run. Two consequences in a cluster:
- Every client gets the same values. Over HTTP the values are the server process’s, so every client of that server runs its providers with them.
- A path must exist on the engine pod. A value that is a file’s path (
KUBECONFIG,GOOGLE_APPLICATION_CREDENTIALS) names a file where the engine runs, not in the server’s pod.
More in Send a variable to providers.
The state backend and variables: the server
Section titled “The state backend and variables: the server”The server never runs a provider. It opens state and evaluates variables, from its own environment:
-
The Kubernetes® backend authenticates as the server’s ServiceAccount, with
in_cluster_config: trueinopen’sbackend_config. State is a Secret,tfstate-<workspace>-<suffix>, and the lock a Lease,lock-tfstate-<workspace>-<suffix>, in the namespacebackend_confignames:open({workspace_name: "demo",backend_type: "kubernetes",backend_config: { secret_suffix: "turf", namespace: "turf", in_cluster_config: true }})The server’s Role needs Secrets and Leases in that namespace, and nothing else (Minimal manifests).
-
Any other backend (S3, azurerm, gcs,
remote) reads its credentials from the server’s environment, plusopen’sbackend_config. -
TF_VAR_<name>comes from the server’s environment.open’svarandvar_fileare kept per workspace in the server’s memory only: after the server restarts,openthe workspace again with the same values. -
State encryption:
TF_ENCRYPTIONand a key provider’s own credentials come from the server’s environment.
# The server's container: backend credentials, TF_VAR_ values, TF_ENCRYPTIONenvFrom: - secretRef: name: turf-server-envKubernetes RBAC cannot scope create and list on Secrets by name, so the server can read every
Secret in the namespace that holds state. If the engine’s identity key and the server’s own token are
in that namespace, it can read them too. To narrow it, keep state in a namespace of its own (the
namespace in backend_config) and move the Role there. turf-kagent does this: its state is in
kagent-tfstate, and its server has no rights in turf.
The CLI configuration
Section titled “The CLI configuration”The OpenTofu® CLI configuration’s provider_installation block says where provider plugins come from
. The server’s init installs and locks providers from it, and the engine installs
from it when it plans and checks what init locked, so both must read the same block. Use one
ConfigMap, mounted on both and named by TF_CLI_CONFIG_FILE. For a cluster that reaches no registry,
add a mirror, name what it serves with include, and exclude the same from direct:
apiVersion: v1kind: ConfigMapmetadata: name: turf-cli-config namespace: turfdata: turf.tfrc: | provider_installation { # filesystem_mirror { # path = "/turf/providers" # include = ["registry.opentofu.org/hashicorp/*"] # } # network_mirror { # url = "https://providers.example.internal/" # include = ["registry.opentofu.org/hashicorp/*"] # }
# With a mirror above: direct { exclude = ["registry.opentofu.org/hashicorp/*"] } direct {} }filesystem_mirror: a read-only volume at the same absolute path in every pod, such as an image volume holding whattofu providers mirror -platform=linux_amd64 -platform=linux_arm64writes.network_mirror: an https service; tofu refuses http.oci_mirror: an OCI registry, with its credentials in a Docker-style config mounted from a Secret at~/.docker/config.json(/home/turfin the image).
Each pod reads the file once, at start: restart every pod that mounts it after a change. A file in error stops the pods from starting, where tofu would warn and carry on.
Registry tokens stay out of the ConfigMap. A token for a private registry, a mirror host or the
remote backend is TF_TOKEN_<host> (dots as underscores), from a Secret, on every pod: the server
needs it for the remote backend and init’s installs, the engine for the installs a plan makes.
The identity key: restate-server and the engine
Section titled “The identity key: restate-server and the engine”restate-server signs every request it sends the engine, and the engine serves nothing it did not sign
(one path, /health, answers unsigned). The key pair lives in one Secret, turf-engine-identity:
| Half | Goes to | As |
|---|---|---|
identity.pem, private |
restate-server | RESTATE_WORKER__INVOKER__REQUEST_IDENTITY_PRIVATE_KEY_PEM_FILE, or a RestateCluster’s security.requestSigningPrivateKey |
public-key, public |
the engine | TURF_ENGINE_IDENTITY_KEYS (comma-separated, for more than one restate-server) |
Mount only the private half on restate-server. turf-engine --identity-keygen makes the pair
(Minimal manifests). The engine’s
--insecure-no-identity turns the check off: anything that can reach the engine’s port can then run
any engine handler on input of its choosing, with the engine’s credentials. Leave it off.
RBAC at a glance
Section titled “RBAC at a glance”| ServiceAccount | Needs | And nothing else because |
|---|---|---|
turf-mcp-server |
Secrets and Leases in the state namespace, for the Kubernetes backend | it never runs a provider |
turf-engine |
what its providers manage | an approved plan can do what the engine can |
| the console | nothing (automountServiceAccountToken: false) |
it reads restate-server’s ingress alone |
Workload identity tokens that Turf mints for each round’s providers, in place of a static key in a Secret, are coming soon coming soon: see Workload identity.
Turf™ is a trademark of Turf LLC. Terraform® is a trademark of HashiCorp. Ansible® is a trademark of Red Hat, LLC, registered in the United States and other countries. Helm®, Kubernetes®, Prometheus® and OpenTelemetry® are registered trademarks, and Jaeger™ is a trademark, of the Linux Foundation. OpenTofu® and Model Context Protocol® are registered trademarks of LF Projects, LLC. All other trademarks are the property of their respective owners. Turf is not affiliated with, endorsed by, or sponsored by HashiCorp, IBM, Red Hat, the Linux Foundation, LF Projects or the OpenTofu project.
© 2026 Turf LLC. Free for individuals, education and small businesses within the Community limits, under the Turf Community Edition License 1.0. Government and larger organizations need a commerciallicense.turf.build · Discord ·GitHub