Back to Terraform

ConfigMaps and Secrets: Configuration Delivery Without False Security Claims

November 6, 2026 Wasil Zafar 18 min read

Separate application configuration, secret values and Terraform artifact exposure

Table of Contents

  1. Separate Public Configuration from Secret Material
  2. Base64 Encoding Is Not Encryption
  3. Choose External Secret or Workload Identity Boundaries
  4. Inspect Terraform Artifacts Without Publishing Them
  5. Rehearse Rotation and Workload Reload Behavior

Separate Public Configuration from Secret Material

Configuration is public by contract. A ConfigMap holds values a reviewer should be able to read in a diff: feature flags, endpoint hostnames, tuning thresholds, a proxy fragment. If disclosure would force an incident, it does not belong there, however convenient the mount.

A Secret is a delivery object, not a vault. It carries confidential bytes from the API server to a pod and nothing more. Its protection comes from the authorization rule that grants a read and from whatever encrypts the stored copy, not from the kind of object it is.

Runtime identity is the third option, and the only one that expires. A projected service account token is minted for one workload, limited to one audience, and replaced by the kubelet before it lapses. A copied client secret has none of those properties, so moving a credential into a Secret is a storage change, not an identity change.

The data contract decides, not the tooling. Ask who may read the value, how long it must live, and who writes the next one. Those three answers select a ConfigMap, a Secret or a projection without further debate.

Separate Public Configuration from Secret Material
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Value the workload needs"] --> B{"Safe to publish?"}
    B -->|"yes"| CM["ConfigMap
readable in a diff"] B -->|"no"| C{"Issued and expired
by the platform?"} C -->|"yes"| WI["Projected token
audience-bound, short-lived"] C -->|"no"| D{"Who writes
the next value?"} D -->|"the platform repo"| SEC["Secret written by Terraform
value plus revision counter"] D -->|"a vault or cloud store"| EXT["ExternalSecret or CSI volume
controller reads at runtime"] CM --> DEL["Delivered to the pod
as environment or file"] SEC --> DEL EXT --> DEL WI --> DEL DEL --> R{"Environment
or volume?"} R -->|"environment"| RST["Restart required
fixed at container start"] R -->|"volume"| REF["Kubelet refreshes
subPath never updates"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A primary; class CM,SEC,EXT secondary; class WI,DEL ok; class B,C,D,R warn; class RST danger; class REF ok;

Figure 1 starts at the value rather than at the resource. The two branches that cause most incidents are the ones that skip the lifetime question: a long-lived credential stored as a Secret, and a confidential value parked in a ConfigMap because that mount was already written.

Three delivery mechanisms crossing four trust boundaries, each hop holding its own copy A ConfigMap, a Secret and a projected token all start at a source of truth and pass through a Terraform artifact, the API server and etcd, and finally the kubelet into a pod. Each boundary keeps a copy with a different audience. A footer states that a copy is only as protected as its reader, and that base64, TLS and encryption at rest each cover one hop only. One value, four copies, four audiences The mechanism decides who may hold a copy, not whether the copy is readable. ConfigMap · public by contract Secret · confidential, readable Projected token · expires SOURCE OF TRUTH Git, or a remote store the author decides what may be published review happens here TERRAFORM ARTIFACT plan file and state retained versions everything the schema is willing to store sensitive hides the print API SERVER AND ETCD authn, authz, admission then a stored copy encrypted per type or not at all reads are gated here POD AND CONTAINER environment fixed at start volume on a timer subPath never refreshes plaintext either way a copy, not the source A copy is only as protected as its reader Base64, TLS and encryption at rest each cover one hop. None of them covers the pod.

Figure 2 draws the hops that a single claim usually hides. The ConfigMap and the Secret differ at the API server, where authorization decides who may read the copy; after the kubelet writes it into the pod, both arrive as plaintext in the same place.

The pod copy is not automatically safer. A Secret volume is memory-backed by default, but an environment variable is readable from the process that owns it, and a debug endpoint or crash dump can print it. Delivery changes the location of the copy, never its readability.

Base64 Encoding Is Not Encryption

The encoding exists because JSON is text. Every data value must survive a JSON document, so the API represents each one as a base64 string. Nothing is derived from a key, and decoding is a library call rather than an exploit.

stringData does not change that. It is a write-only convenience field: the API server merges its entries into data and returns only the encoded form. Reading the object back still yields a decodable value.

Five different layers get folded into one sentence, and each protects a different thing. The table separates them, because "secrets are encrypted" usually describes one row.

LayerWhat it protectsWhat it leaves exposedWho can still read the value
Base64 encodingkeeps bytes valid inside a JSON documentthe value itself, with no key involvedanyone allowed to read the object
TLS in transitthe HTTP session between client and serverthe stored copy and every copy after itthe API server, the kubelet, any authorized reader
Encryption at restthe etcd value and the backups taken from itAPI responses, mounts, logs, state filesevery principal the API authorizes
RBACwhich verbs apply to which objectsfield values inside an object you may readevery principal bound to get or list
External storethe value's home outside the clusterthe copy the controller writes or mountsworkloads granted the store role

Encryption at rest is opt-in and per resource type. An EncryptionConfiguration on the API server decides whether secrets are written to etcd as ciphertext, and a KMS provider keeps the key material outside the cluster. Without it, the etcd copy is plaintext and a volume backup is a disclosure.

Authorization is the control that actually gates reads. Permission to get one named Secret returns its data; permission to list returns every Secret in the namespace with data attached. A rule narrowed to named objects cannot constrain list or watch, so a list grant is a namespace-wide read.

Transport encryption ends at the API server. TLS protects the request between client and server and says nothing about the etcd copy, the kubelet cache, the mounted file, a log line or the Terraform state. Each is a separate copy with a separate reader, and only one is on the wire.

Type validation checks key names, not strength. The TLS type requires the two expected keys and the basic-auth type requires a username and a password; neither inspects the value. A one-character password satisfies the schema.

Base64 Encoding Is Not Encryption
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    W["Writer
kubectl, controller or Terraform"] --> ENC["Client encodes the bytes
base64 inside a JSON string"] ENC --> TLS["TLS session
to the API server"] TLS --> AUTHN{"Authenticated?"} AUTHN -->|"no"| E401["401 Unauthorized
no object written"] AUTHN -->|"yes"| AUTHZ{"Verb allowed
on this resource?"} AUTHZ -->|"no"| E403["403 Forbidden
identity was valid"] AUTHZ -->|"yes"| ADM["Admission and type check
key names only"] ADM --> STORE{"Encryption at rest
configured for secrets?"} STORE -->|"no"| PLAIN[("etcd
plaintext value")] STORE -->|"yes"| CIPHER[("etcd
ciphertext, key outside")] PLAIN --> READ["Authorized read
base64 in, bytes out"] CIPHER --> READ READ --> WIDE{"Grant reaches
list or watch?"} WIDE -->|"yes"| ALL["Every Secret in the namespace
returns with its data"] WIDE -->|"no"| NAMED["Named object only
one value disclosed"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class W,TLS primary; class ENC,ADM,READ secondary; class CIPHER,NAMED ok; class PLAIN,ALL danger; class AUTHN,AUTHZ,STORE,WIDE warn; class E401,E403 danger;

Figure 3 separates the write path from the read path. The two failure branches are an unauthenticated writer and a reader whose grant is wider than intended; the storage branch changes only what a compromise of etcd reveals.

The dangerous claim is the short one. "The Secret is encrypted" is true only if you can name the resource type in the encryption configuration, the holder of the key, and the authorization rule that limits reads. Without all three, the sentence is a statement about base64.

Choose External Secret or Workload Identity Boundaries

Three parties can own a value, and the design fails when two of them think they do. Terraform can own the object, a remote store can own the bytes, and the platform can own the identity that reads them. Pick one owner per value and record the choice where the object lives.

An external store keeps the value out of Terraform entirely. An ExternalSecret names a remote key and a target Secret; the controller fetches the bytes and writes the object. Terraform manages the reference, so plan and state hold a key name rather than a credential.

A CSI volume goes one step further. The Secrets Store CSI Driver mounts the value from the provider into the pod's filesystem and can skip creating a Kubernetes Secret at all. Nothing is stored in the API server, so nothing can be read back from it.

Workload identity removes the stored credential instead of moving it. The pod presents a projected token with a specific audience, and the cloud or vault exchanges it for scoped credentials. Enable it deliberately, and disable the default token mount on pods that do not need one.

A controller is a prerequisite, not an implementation detail. The custom resource definitions must exist before the object applies, the controller's service account needs permission to write Secrets, and a cluster-scoped store needs a namespace selector that admits the target namespace.

The creation policy decides who may write the target. Owner lets the controller own and delete the object; Merge keeps existing keys and adds the controller's. A third setting refuses to create anything missing, which is the strictest option and the easiest to audit.

Two writers on one Secret is a permanent diff. If Terraform also manages that object, every apply restores its value and every controller sync overwrites it again. Import the object or stop managing it in Terraform, but never both.

A stopped controller is a silent staleness bug. Pods keep running with the last synced value, the object still looks healthy, and the only signal is a SecretSyncedError condition on the ExternalSecret. Alert on sync failure and on the age of the last refresh, not on the object's existence.

Inspect Terraform Artifacts Without Publishing Them

Sensitivity is a display rule. Marking a value sensitive replaces it with a marker in CLI output and requires matching sensitivity on outputs; it does not encrypt state, purge a plan file or suppress provider debug logs.

The provider stores the decoded value. The kubernetes_secret_v1 documentation says it plainly: all arguments, including secret data, are kept in raw state as plain text. The API round trip produces base64 on the wire and the original bytes in state, so encoding never reaches the file you are trying to protect.

A saved plan has the same property. Terraform records the proposed value so that apply can use it, and terraform show -json returns it in the change body while marking the attribute in a parallel sensitivity map. Redaction happens when the plan is rendered, not when it is written.

Where the provider allows it, a write-only argument closes the gap. The Secret resource accepts data_wo for the value and keeps only a revision integer behind. Increment that revision to force the write; editing the value alone produces no diff.

The write-only path needs a recent CLI and provider. Support arrived in provider 2.36.0 and requires Terraform 1.11 or later, so a root pinned to an earlier CLI cannot use it. The binary counterpart, binary_data_wo, carries its own revision counter.

A ConfigMap has no write-only path, by design. Its data map is not marked sensitive in the provider schema, so it appears in plan output as ordinary values. That is correct for public configuration and the wrong place for a credential.

Prove the claim with a canary, never a real value. Write a unique marker as the secret value, then search the plan, the state and the CI log for it. A hit is evidence; a miss in one artifact says nothing about the others.

History outlives the resource. Backend versioning keeps older state objects after a rotation, and a saved plan in a pipeline artifact outlives the branch that produced it. Deleting the current state does not delete the copies that were already published.

Where an ordinary secret value persists compared with a write-only argument On the left, an ordinary data argument passes through a saved plan and the state file into retained state versions, while the sensitive flag redacts only the printed output. On the right, a write-only argument reaches the provider during apply and leaves a revision integer in state. A footer states that editing a value is not rotation because the revision counter is what produces a diff. The write path decides what the artifacts hold Redaction is applied when Terraform prints, not when it stores. ORDINARY DATA ARGUMENT value = synthetic marker saved plan holds the value state holds the value retained versions keep every copy sensitive = true changes the display only WRITE-ONLY ARGUMENT value reaches the provider no copy in the plan file state holds a revision integer the value is not recoverable from state the revision counter is what produces a diff Editing a value is not rotation. Only the revision counter makes Terraform write it again.

Figure 4 compares the two write paths. The ordinary argument leaves the value in the plan, the state and every retained version; the write-only path leaves a revision integer that is useless without the value it triggered.

Absence from the plan is not absence from state. Check the artifact you actually intend to defend, then expire the ones you cannot. A clean plan on the screen and an unencrypted bucket are perfectly compatible.

Rehearse Rotation and Workload Reload Behavior

Rotation has two halves and only one of them is a write. Writing a new value updates the object; making the application use it requires the process to read it again. A rotation that stops at the write looks complete in the diff and changes nothing at runtime.

Environment variables are frozen at container start. A value injected with env or envFrom is copied into the process environment once, so a new Secret has no effect until the container restarts. A pod template change or a deliberate rollout is the only mechanism that reloads it.

Volume mounts update in place, on the kubelet's clock. The kubelet refreshes a mounted ConfigMap or Secret and the file changes without a restart, but not at the instant of the API write. The documented worst case is the kubelet sync period plus its cache delay, so a rotation rehearsal should measure the gap.

A subPath mount is a copy, not a projection. The file is placed at container start and never refreshed, which is why some charts use it to avoid partial reads and why it silently defeats every rotation that relies on a volume.

Immutable objects turn a rotation into a replacement. With immutable = true the object cannot be updated, so Terraform replaces it and running pods keep the old value until they are recreated. Immutability blocks accidental edits and makes the restart unavoidable.

Write-only rotation needs the revision bump. Because Terraform never stored the old value, it cannot detect a change; only the revision counter produces a diff. A runbook that edits the value and skips the counter reports success and writes nothing.

External stores add a second clock. The controller refreshes on its own interval, and the pod reloads on the kubelet's schedule or the Deployment's. A value can be correct in the store, correct in the Secret, and still absent from the running process.

The only reliable reload is a rollout you can observe. Annotate the pod template with a hash of the rendered configuration so a change forces new pods, then confirm the value through the application, not the object.

Lab

Rehearse Rotation and Workload Reload Behavior

Status: design-only. No cluster was contacted, no output is recorded, and every value is a synthetic marker.

Prerequisites. Terraform 1.17.1 with hashicorp/kubernetes 3.5.0, a disposable namespace, and one Deployment that reads a single value from a Secret. Use a marker that appears nowhere else in the cluster.

CaseChangeExpected observation
Environmentbump the revision and applythe pod keeps the old marker until its template changes
Volume directorysame write, mounted as a directorythe file shows the new marker after the kubelet refresh
Volume subPathsame write, mounted with subPaththe file never changes
Immutable objectchange the value with immutability onthe object is replaced, old pods keep the old marker
Saved planinspect the plan as JSONthe marker is absent on the write-only path and present on the ordinary one
  1. Apply the Secret with the marker and a revision of 1, then read it from inside the pod to prove delivery.
  2. Change the marker, increment the revision, apply, and read again without restarting. Record the old value and how long it survived.
  3. Switch the mount to a directory volume, repeat step 2, and time how long the file takes to change.
  4. Add a subPath mount, repeat the write, and confirm the file does not change at all.
  5. Enable immutability, change the value, and confirm the plan proposes a replacement rather than an update.
  6. Search a saved plan and the current state for the marker, then repeat with a write-only value and search again.
  7. Destroy the namespace, then search the backend's retained state versions for the marker from step 6.

Expected observation. The environment case changes only on restart, the directory mount changes late, and the subPath mount never changes. The plan contains the marker for the ordinary argument and a revision integer for the write-only one.

Failure check. If the file changes instantly, the mount is not a subPath and the kubelet watch is doing the work. If the plan shows no diff after editing the value, the revision was not incremented. If the pod shows the new value without a restart, it is reading the file rather than the environment.

Evidence to keep. The revision numbers before and after, the elapsed time for the volume refresh, the plan that shows a replacement, and the search result for the marker in each artifact. Keep the marker, never a real credential.

Next in the Series

In Persistent Storage: PVCs, StorageClasses and Stateful Recovery, we'll explore Distinguish Kubernetes objects, provisioned cloud volumes and recoverable application data.