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.
%%{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.
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.
| Layer | What it protects | What it leaves exposed | Who can still read the value |
|---|---|---|---|
| Base64 encoding | keeps bytes valid inside a JSON document | the value itself, with no key involved | anyone allowed to read the object |
| TLS in transit | the HTTP session between client and server | the stored copy and every copy after it | the API server, the kubelet, any authorized reader |
| Encryption at rest | the etcd value and the backups taken from it | API responses, mounts, logs, state files | every principal the API authorizes |
| RBAC | which verbs apply to which objects | field values inside an object you may read | every principal bound to get or list |
| External store | the value's home outside the cluster | the copy the controller writes or mounts | workloads 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.
%%{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.
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.
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.
| Case | Change | Expected observation |
|---|---|---|
| Environment | bump the revision and apply | the pod keeps the old marker until its template changes |
| Volume directory | same write, mounted as a directory | the file shows the new marker after the kubelet refresh |
| Volume subPath | same write, mounted with subPath | the file never changes |
| Immutable object | change the value with immutability on | the object is replaced, old pods keep the old marker |
| Saved plan | inspect the plan as JSON | the marker is absent on the write-only path and present on the ordinary one |
- Apply the Secret with the marker and a revision of 1, then read it from inside the pod to prove delivery.
- Change the marker, increment the revision, apply, and read again without restarting. Record the old value and how long it survived.
- Switch the mount to a directory volume, repeat step 2, and time how long the file takes to change.
- Add a subPath mount, repeat the write, and confirm the file does not change at all.
- Enable immutability, change the value, and confirm the plan proposes a replacement rather than an update.
- Search a saved plan and the current state for the marker, then repeat with a write-only value and search again.
- 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.