Fix: store sensitive step outputs in a companion Secret instead of the plaintext context ConfigMap
Description of your changes
Workflow vars — including step outputs whose values come straight out of
Kubernetes Secrets — all get serialized into workflow-<name>-context ConfigMap
data by writeToStore. So a step like kubevela's generate-jdbc-connection,
which reads a Secret and exposes the decoded password, leaks that password in
plaintext to anyone with configmap read access the moment a user declares an
output on it. Same class of problem as kubevela/kubevela#6840, which recently
got fixed on the policy side — this is the workflow-side variant.
The fix follows the same idea, adapted to how the context store works:
- Step templates can declare
$sensitivePaths: ["password", ...]in their
rendered value. Outputs whosevalueFromoverlaps a declared path (either
direction — extracting a parent of a sensitive path still includes the value)
get routed through a newSetSensitiveVarinstead ofSetVar. - Sensitive vars are persisted to a companion Opaque Secret
(workflow-<name>-context-sensitive) with the same owner references as the
ConfigMap, so GC is unchanged. The Secret is only created once something
sensitive exists — plain workflows never get one. GetVarreads both stores transparently, so inputs/data-passing between
steps work exactly as before regardless of where a var lives.- If
valueFromis an expression rather than a plain dotted path and the
template declared any sensitive paths, it's treated as sensitive — can't
prove an expression doesn't embed the value, so it fails closed. - A failed Secret write fails the Commit (reconcile retries). It never falls
back to writing the ConfigMap. - In-memory context mode (
EnableInMemoryContext) keeps sensitive vars in the
in-memory object, which never reaches the API server anyway.
Couple of honest limitations: templates have to opt in by declaring
$sensitivePaths, existing templates aren't retroactively protected. And the
alternative — a sensitive field on the outputs API type — would be a
kubevela/pkg change plus CRD schema updates across repos, which felt too heavy
for a first pass. Open to going that way if preferred.
How has this code been tested
- New tests: round-trip (value in Secret, absent from ConfigMap, readable via
GetVar), no-Secret-when-nothing-sensitive, LoadContext recovery from an
existing Secret, sync-on-later-commits, end-to-end Output() routing, and a
table test for the path matching. - Existing pkg/context and pkg/hooks tests all pass.
- Full ./pkg/... suite: the two http provider packages fail identically on a
clean main checkout (SHA1-signed test cert rejected by go1.23), so those are
pre-existing and unrelated. - gofmt / go vet / go build clean.
Summary by cubic
Stores sensitive step outputs in a companion Secret instead of the plaintext workflow context ConfigMap to prevent leaks. Templates declare $sensitivePaths; matching outputs are saved securely, and GetVar reads remain seamless.
-
Bug Fixes
- Added
SetSensitiveVarto persist sensitive vars toworkflow-<name>-context-sensitive(Opaque, owner-referenced). Output()routes outputs whosevalueFromoverlaps$sensitivePaths; expressions are treated as sensitive.GetVarreads from both ConfigMap and Secret;EnableInMemoryContextkeeps sensitive data in memory only.- Secret write errors fail commit; no fallback to ConfigMap; no Secret is created for non-sensitive workflows.
- Added
-
Migration
- Add
$sensitivePathsto step templates to protect outputs; existing templates stay unchanged.
- Add