Design the Experiment with a Synthetic Marker
A persistence audit needs a value that is safe to leak. Generate a marker from a fixed prefix and a random suffix, then handle it exactly like a production credential for the rest of the exercise. The prefix makes it searchable, and the randomness keeps an unrelated string from producing a false match.
Isolation belongs to the directory, not to the configuration. Create one directory outside every repository, remove group and other permissions, and use the local backend so the state object never leaves the machine. Do not run version control inside it, do not point a workspace at a hosted organisation, and do not configure a remote backend.
Publishing is the failure this experiment exists to avoid. A CI artifact, a screenshot, a pasted transcript and a ticket comment are copies with their own readers and their own retention. Keep the run on one machine, keep the evidence in one file, and plan to delete both.
The inventory below is the real deliverable. Six surfaces can hold the marker in a local run, and each one is written by a different part of the tool.
| Artifact | Written by | Can hold the marker | Reader during the test |
|---|---|---|---|
| Saved plan | terraform plan -out=tfplan | Every input variable and every planned value | The account running the CLI |
| State file | plan and apply | Resource attributes, data source results and outputs | The same account |
| State backup | the next write to local state | The previous version of everything above | The same account |
| Plan document | rendering the plan with terraform show -json | The same values as the plan, without screen redaction | Whatever the pipe reaches |
| Debug log | TF_LOG and a crashing provider | Request and response bodies from the failing call | The log file, then its readers |
| Backend record | initialisation | Endpoint, bucket name and any credential written into the backend block | The same account |
The two easily forgotten rows are the backup and the backend record. Neither appears in plan output. The backup is created beside the state on the next write, and the backend record is written by initialisation into a hidden directory, where it sits until someone reads it.
Figure 1 follows the marker from generation to deletion and marks the two paths that leave the sandbox.
%%{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','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#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','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
M["Synthetic marker
fixed prefix, random suffix"] --> E["Disposable directory
owner-only permissions"]
E --> V["Sensitive variable
supplied at the prompt"]
V --> P["Plan with a saved file
local backend only"]
P --> A["Apply completes"]
A --> R["Artifacts written to disk"]
R --> C1["Saved plan"]
R --> C2["State file and backup"]
R --> C3["Plan document on stdout"]
C1 --> Q["Record path, size and match count"]
C2 --> Q
C3 --> Q
Q --> W["Delete the directory
and the evidence note"]
P -. "remote backend configured" .-> X["Outside this run
add it to the audit inventory"]
A -. "debug logging enabled" .-> Y["Log becomes an artifact
count it, do not read it"]
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 M,E,V,P primary;
class A,R,C1,C2,C3 secondary;
class Q,W ok;
class X danger;
class Y warn;
Layers, not files, are what an audit has to name. A value moves from configuration into process memory, from process memory into an artifact, and from an artifact into somebody else's copy. Each layer has a different owner and a different way of being cleared.
Figure 2 draws those five layers with the persistence boundary between the third and the fourth, and names what an audit can honestly claim at each level.
Two limits belong in the experiment design, stated before the first apply. A local sandbox cannot show what a hosted backend retains, what a provider keeps on its side, or what a colleague copied last month. Those are scope items for the audit in the next sections, not gaps in the proof.
A marker also fails quietly when it is transformed. If the provider base64-encodes the value or the plan compresses it, a plain text search of the file finds nothing and the result looks clean. Search for the encoded form as well, and prefer asking Terraform to render the artifact over reading its bytes.
Trace Redacted and Non-Persisted Value Paths
Sensitivity is a display instruction. Marking a value sensitive makes Terraform print a placeholder in human-readable plan output, apply output and the hosted UI. The bytes remain in the plan file and in state, and the machine-readable forms return them in clear text.
The version each mechanism arrived in matters. This is the Terraform 1.17.1 baseline, where all three are available, but an estate running an older CLI will reject the declarations rather than fall back quietly. Check the CLI version of every pipeline that could plan the configuration before the configuration uses it.
Ephemeral means the value has no record. Terraform 1.10 added ephemeral input variables, ephemeral resources and ephemeral outputs from child modules. The value exists for the operation and is omitted from both artifacts, which is a stronger promise than redaction and a narrower one than deletion: the source still holds it.
Write-only is a property of the provider schema. From Terraform 1.11, a provider can mark an argument as write-only, and Terraform then sends the value during the operation while storing null in its place. A companion version counter supplies the diff that a value Terraform never stores could not otherwise produce.
The table is the comparison to put in a design review, because each row answers a different question about what survives.
| Mechanism | What Terraform changes | Plan file | State file | Copies that remain |
|---|---|---|---|---|
| Plain argument | Nothing | Value | Value | Every artifact below |
sensitive = true | Display only | Value on disk, placeholder on screen | Value | Every artifact below |
| Ephemeral value | Omits the value | Absent | Absent | Environment, variable file, shell history |
| Ephemeral resource | Omits the object | Absent | Absent | Provider lease, request log |
| Write-only argument | Stores null plus a version | Write-only marker, no value | null | Provider store, request log |
Read the last column before the middle ones. The first two rows persist everywhere and protect a screen. The last three remove a copy from Terraform's artifacts, and none of them removes the copy at the source or the copy the provider keeps.
Figure 3 places the three mechanisms side by side against the same boundary, with the shared source that all of them leave behind.
The mechanisms compose rather than compete. An ephemeral value can feed a write-only argument, which is the strongest arrangement the language currently offers: the value has no source file inside the configuration and no stored copy on Terraform's side. Each mechanism covers one leg, and the pair covers both.
Figure 4 follows the decision and the three branches that turn a good intention into a stored secret.
%%{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','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#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','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
S["Value arrives
environment, file or store"] --> D{"Which mechanism
is in use?"}
D -- "sensitive" --> S1["Marked for display redaction"]
S1 --> S2["Plan and state keep the bytes"]
S2 --> S3["JSON form and named output
return it in clear text"]
D -- "ephemeral" --> E1{"Destination supports
an ephemeral value?"}
E1 -- "no" --> E2["Plan error
invalid use of ephemeral value"]
E1 -- "yes" --> E3["Omitted from plan and state"]
E3 --> E4["Source still holds a copy
environment, file, history"]
D -- "write-only" --> W1{"Provider schema marks
the argument write-only?"}
W1 -- "no" --> W2["Ordinary argument
value persisted as usual"]
W1 -- "yes" --> W3["Null in state
version counter remains"]
W3 --> W4{"Counter incremented?"}
W4 -- "no" --> W5["No diff for a reviewer to see"]
W4 -- "yes" --> W6["Provider receives the new value"]
W3 --> W7["Provider store keeps versions
outside Terraform's reach"]
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 S,D,E1,W1,W4 primary;
class S1,S2,W3,S3 secondary;
class E3,W6 ok;
class E2,W2,W5 danger;
class E4,W7 warn;
Each failure branch is a different kind of wrong. A plan error stops the run, which is the good outcome. A write-only argument without a version bump produces a clean plan and no change, which is the quiet outcome. Sensitive in an ordinary argument produces a redacted screen and a stored value, which is the common outcome.
A root output is the sharpest example of the difference. Terraform rejects an ephemeral output at the root module, because a root output exists to be stored for other configurations to read. The rejection is the language telling you that the value would have become an artifact.
The audit question is therefore not which flag is set. It is which artifact still contains the bytes, and who can read that artifact today. A workspace full of sensitive marks can still be the leakiest configuration in the estate.
Inspect Artifacts Privately and Report Only Findings
An audit reads artifacts; it does not print them. Every probe should return a property of the artifact, such as a count, a boolean, a hash or a key name, rather than its content. That single constraint is what makes the result safe to attach to a ticket.
Start with a filename-only search over the working directory. A recursive search that lists matching paths tells you where the marker landed without printing a byte of it. Record the command, the directory, the exit status and the timestamp beside the counts, because those four fields are what make the number evidence.
Binary artifacts need a different probe. A saved plan is not a text file, and a text search of it proves nothing when the bytes are compressed. Ask Terraform to render the plan as a document, then reduce that document to a count of matching strings, so the value never reaches the terminal.
The table maps each surface to a probe that returns a verdict rather than a value.
| Surface | Probe that stays safe | What comes back | How it leaks by accident |
|---|---|---|---|
| Working tree | filename-only recursive search | paths with a match | printing the matching line |
| Saved plan | plan document piped to a match count | an integer | redirecting the document to a file |
| Current state | state pulled through a pipe, counted | an integer | writing the raw state to disk |
| Previous versions | backend version listing | version ids and dates | downloading a version to inspect it |
| Logs | per-file match count | one integer per file | opening the log to see the context |
| Provider cache | file listing and schema dump | plugin names, attribute names | nothing: schema has no values |
A workspace audit starts at the backend, not at the files. The backend configuration names the object that holds the state, its versioning and lock settings say what history exists, and its policy says who can read that history. Read those three things before running a probe, because they bound every finding that follows.
The provider cache is the one surface that is genuinely clean. It holds plugin binaries and module source, and the lock file beside it records provider hashes; none of those contain attribute values. Saying so explicitly is worth the sentence, because it stops an auditor from spending a day on the least interesting directory.
Encoded forms are the silent false negative. If the provider stores the value base64-encoded, or the artifact nests it inside a JSON string, a raw text search returns zero while the value sits in the file. Encode the marker and search for that form too, and treat a zero result from one probe as one result, not a conclusion.
Figure 5 places the probe outside the artifact zone and shows the only thing allowed to cross back: counts, hashes and verdicts.
Findings have three values, and unknown is one of them. A surface is present, absent or not observable from where you sit. The third value is the most useful, because it forces the record to name the reader who could observe it instead of pretending the surface was checked.
A claim is only as good as its scope. "Absent from the current state and the saved plan, in this directory, at this time, using these two probes" is evidence. "The workspace is clean" is a sentence that will be quoted back at you after the next release.
The record below is enough for a reviewer to reproduce the result without seeing the value.
| Field | What to write | Why it belongs |
|---|---|---|
| Scope | Root, backend, artifact set, timestamp | Bounds the claim to what was checked |
| Probe | Command shape and filter, not its output | Another auditor can repeat it |
| Result | Match count, boolean or artifact hash | Shows the finding without the bytes |
| Verdict | Present, absent or not observable | Prevents a gap becoming a pass |
| Owner | Team accountable for the artifact | Makes the follow-up actionable |
| Next review | Date tied to the retention clock | Keeps the finding from ageing silently |
The strongest finding is usually an absence that should not be there. A marker missing from state may mean the argument is write-only, or that apply never wrote the resource. The probe cannot tell you which, so the record needs the second observation: the value present at the provider, or the resource absent from the plan.
Old Object Versions and CI Artifacts Remain Part of the Scope
A clean current artifact says nothing about yesterday. Every write creates a new version, and every versioning scheme keeps the old one for a period that was chosen by someone who was not thinking about this secret. Fixing the configuration changes what the next write contains; it does not reach backwards.
Versioning is a feature that works against deletion. S3 versioning, blob versioning and object generations all retain the previous object, and an object-lock policy can refuse removal until a date. Hosted backends keep their own state version list, so a workspace can show a clean current state while the previous three still hold the marker.
CI keeps what it was given. An uploaded plan or a job log is a secret-bearing artifact with the platform's default retention, which for GitHub Actions is ninety days for both artifacts and logs unless the repository changes it. Ninety days is not a storage detail; it is the floor of the exposure.
Editing state edits one file. Removing a resource from state, or pushing a hand-edited state, changes the current object and leaves the previous version, the backup beside it and the hosted version list untouched. The edit is a story about the file, not about the copies.
Figure 6 puts the write history on a timeline and keeps the outside copies visible beside it.
Three clocks decide how long the exposure lasts. The credential stays valid at the target until it is revoked there. The artifact stays readable until its retention expires. The reader keeps whatever they downloaded, for as long as they keep it.
| Clock | Reset by | Not reset by |
|---|---|---|
| Credential validity | Revocation or rotation at the target | Changing the Terraform variable |
| Artifact retention | Expiry of the version, object or CI artifact | Deleting the current state file |
| Reader access | Removing the permission, or the reader | Either of the above |
The honest inventory lists the copies you cannot delete. A provider's secret versions, a backup under a retention lock and a transcript in a ticket are all in scope, and none of them will be removed by a Terraform change. Naming them is what separates a remediation from a claim.
This is why the record needs two dates, not one. The date the new value was deployed is the start of the fix. The date the old value stopped working is the start of the end. Between them, every retained copy is still a working credential.
Write a Remediation Record with Explicit Residual Exposure
Remediation is a record, not a cleanup. The work is ordered, the evidence is written down as it happens, and the note ends with what is still exposed rather than with what was deleted. A reader who was not in the room should be able to reconstruct the decision.
The order is issue, deploy, verify, revoke, purge. A new credential is issued at the source, applied so the target and the state both move, verified with a real request, then the old one is revoked at the target. Purging comes last, because until revocation succeeds the old value is still live and the artifacts may be needed for a rollback.
Evidence is metadata, never content. For each surface, record the command shape, the filter, the exit status, the timestamp and a hash of the artifact. Together they prove what was checked and let another auditor repeat it, without creating the copy the audit was meant to prevent.
Residual exposure is a section, not a disclaimer. It names the copies that remain, who can read each, when each expires and which owner accepted the gap. A record with an empty residual section is usually a record that stopped looking.
Access remediation changes who can reach the copies. Narrow the backend role to one state key, remove the artifact readers who only needed last quarter's plan, and retire the CI secret that still holds the old value. Permission is the only control that works on a copy you cannot delete.
Retention is the change you can ship this week. Shorten the plan artifact window, add a lifecycle rule on noncurrent state versions, and test a restore before you expire anything. A retention policy nobody has restored from is a guess about availability and a promise about deletion.
The lab below runs the whole sequence against a disposable root, with a legacy snapshot that deliberately contains the marker so the difference between current and historical is observable rather than assumed.
Audit the persistence boundary
Status: design-only. The sequence is written for Terraform 1.17.1 with the local backend and no cloud account. No command below was executed to produce recorded output, every identifier is a placeholder, and the marker is synthetic throughout.
Prerequisites. Terraform 1.17.1, a shell with a text search tool, a SHA-256 utility and a JSON filter, and one disposable directory outside every repository. No remote backend, no CI, no version control inside the directory.
Setup. Create the directory, restrict it to your own user, and export a marker built from a fixed prefix and random hex. Keep the marker in the environment only, never in a file you intend to keep.
| Deliverable | File | Pass condition |
|---|---|---|
| Marker record | marker.sha256 | Hash only, no value |
| Artifact inventory | inventory.md | Every surface has a writer and a reader |
| Probe results | findings.md | Counts, hashes and verdicts, no content |
| Retention check | retention.md | Versioning, object lock and CI window named |
| Rotation record | rotation.md | Issue, deploy, verify, revoke, purge with times |
| Residual exposure | residual.md | Remaining copies, readers, expiry, owner |
- Export the marker, then write only its hash to the record file. From this point the value exists in one process environment and nowhere else that you control.
- Write a minimal root: one variable marked sensitive, one resource argument that stores it, and the local backend. Apply once, so a real artifact set exists.
- Copy the state into a
snapshots/directory with owner-only permissions. This is the stand-in for yesterday: a copy that the migration will not touch. - Probe the working tree with a filename-only recursive search, then probe the saved plan and the current state through a counted pipe. Write down one integer per surface and nothing else.
- Fix the configuration to the non-persisting route the provider supports, ideally a write-only argument fed by an ephemeral source, apply, and repeat the same three probes. The current plan and state should now return zero; the snapshot and the backup should still return a match.
- List the retained versions through the backend, if one is reachable, and record version ids, dates and reader groups. Where no backend is reachable, mark the surface not observable rather than absent.
- Rotate in order: issue at the source, apply, verify a real request, revoke the old value, then delete the snapshot and the plan. Confirm the old value now fails at the target, not only in Terraform.
- Write the residual section: the provider's own versions, any backup under retention, the CI window and the readers who may still hold a copy. Give each a date and an owner.
| Check | Expected result | Evidence to keep |
|---|---|---|
| Current state after the fix | Zero matches | Count and timestamp |
| Saved plan after the fix | Zero matches | Count and timestamp |
| Snapshot taken before the fix | One or more matches | Count only, never the line |
| Backend version list | Older versions still present | Version ids and dates |
| Old credential after revocation | Rejected at the target | Status or error class, no secret |
| New credential after rotation | Accepted | Status code and time |
Expected observation. The probes separate three states that are easy to conflate: the current artifacts are clean, the retained copies are not, and the provider still holds its own history. The snapshot match is the finding that a configuration-only fix would have missed.
Failure checks. A zero result in the snapshot means the copy was taken after the fix, so repeat step 3 first. A zero result everywhere including the provider means the value never reached the target. A match in the current state means the argument is not actually write-only, so re-check the schema rather than the configuration. A match that appears only after decoding a base64 string means the raw search was a false negative.
Cost and cleanup. Zero cloud spend; the cost is disk and attention. Delete the directory, the snapshot, the plan and the markers, clear the environment variable, and close the shell so the value does not survive in its history. On a shared machine, check the trash and any backup tool before declaring the copy gone.
Evidence to keep. The marker hash, the inventory with writers and readers, one count per surface per run, artifact hashes, the retention findings, the ordered rotation record with timestamps, and the residual exposure section with an owner per remaining copy. Never keep the marker, a raw state file, a plan file or a log line that contains either.