Repository navigation
Fix: store sensitive step outputs in a companion Secret instead of the plaintext context ConfigMap - #245
Fix: store sensitive step outputs in a companion Secret instead of the plaintext context ConfigMap#245sakirr05 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #245 +/- ##
===========================================
+ Coverage 62.49% 80.75% +18.26%
===========================================
Files 62 89 +27
Lines 4415 7305 +2890
===========================================
+ Hits 2759 5899 +3140
- Misses 1324 1406 +82
+ Partials 332 0 -332
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
Thanks for this, and sorry it's taken a while to get a decision on it. We'd like to go with your approach: One change to how it's declared. KubeVela already has a marker for this: SourceDefinitions mark a field
And the three open review points before it can land:
Shout if any of that doesn't sit right. |
…ext ConfigMap Step outputs are serialized into workflow-<name>-context by writeToStore Signed-off-by: sakirr05 <sakirahmed690078@gmail.com>
210737c to
b86c53b
Compare
|
Thanks @briankane, all of that sits right. Pushed: The three points are fixed at the root: unreadable markers route every output to the Secret, the store is stamped with One structural change worth your eyes: The earlier red |
Fixes #317
Description of your changes
Workflow vars, including step outputs whose values come straight out of Kubernetes Secrets, all get serialized into
workflow-<name>-contextConfigMap data bywriteToStore. 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 was fixed on the policy side; this is the workflow-side variant.
How a template declares it. A definition author marks the field
// +sensitive, the marker SourceDefinitions already use (KEP-2.16), and it covers everything beneath it. There is one way to say "this is secret" acrosssources and workflow steps rather than a second one here.
A new
pkg/cue/sensitivewalks the template AST and returns the marked paths. It is a copy of kubevela'spkg/sources/source_sensitive.go, since workflow cannot import kubevela; sharing one copy is tracked in kubevela/pkg#162, which the file comment points at, along with three deliberate divergences:valueFrom.if/forbodies and embeddings. kubevela's walker only looks at*ast.Fieldand skips*ast.Comprehension, which matters more here:read-object's entireoutput:block is twoifarms, so a markerin one would have been dropped. This is the divergence worth carrying back.
Paths are extracted once per template in
makeTaskGenerator, behind a content-keyed memo, not on every step run.Where the values go.
valueFromoverlaps a marked path are routed through a newSetSensitiveVarinstead ofSetVar. Matching is bidirectional: extracting a parent of a marked path still carries the value, so it is sensitive too.(
workflow-<name>-context-sensitive) with the same owner references as theConfigMap, so GC is unchanged. It is created only once something sensitive exists; plain workflows never get one.
GetVarreads both stores, consulting the Secret first, so data passing between steps is unchanged regardless of where a var lives.EnableInMemoryContext) keeps sensitive vars in the in-memory object, which never reaches the API server.Failing closed. If the markers cannot be read, every output goes to the Secret: "could not tell" is not "nothing is secret". Likewise, a
valueFromthat is an expression rather than a plain dotted path, against a template thatmarked anything, is treated as sensitive, since an expression cannot be proven
not to embed the value.
Not overwriting a Secret we do not own. Creation stamps
workflow.oam.dev/context-store, and both the patch path and the load path verify that label plus the owner references before touching the Secret. A mismatch is an error. Checking on load matters as much as on write: without it a Secret squatting the companion name would be read back in as this workflow's varsNo plaintext left behind.
SetSensitiveVarremoves the same path fromwf.vars, sowriteToStorecannot re-serialize a stale copy. CUE has no un-unify, so removal happens on the syntax tree in a newvalue.DeletePath,mirroring how
SetValueByScriptalready round-trips throughformat.Node.One deliberate asymmetry:
GetVar()with no path returns the ConfigMap vars only. A path-less read cannot say which field it wants, andveladumping a whole context must not print credentials. It has its own test so it does notread as an oversight later.
Plumbing note.
pkg/executorinstalled one sharedhooks.Outputfor every step, which left nowhere to put a per-template hook, so it no longer setsPostStopHooksand each task runner builds its own list locally; the sharedTaskRunOptionsis never mutated across steps, and a caller that setsPostStopHooksitself keeps full control.types.TaskPostStopHookandhooks.Outputare unchanged, so no exported signature moved. A step group hasno template, so it keeps the plain
hooks.Output.How has this code been tested
pkg/cue/sensitive: absolute paths, descent and dedupe,if/forbodies, embeddings and conjunctions, list elements and quoted labels, a mark covering everything beneath it, an unparseable template returning an error,Coversin both directions and dropping list indices. -
pkg/context: Secret round trip, no Secret when nothing is sensitive,LoadContextrecovery, a foreign Secret under the companion name refused, the plaintext copy evicted, the store labelled, andGetVar()with no path excluding sensitive vars.pkg/hooks: marked outputs absent from the ConfigMap while siblings flow as before, unreadable markers routing everything to the Secret, an earlier plaintext copy evicted.pkg/tasks/custom: the end-to-end gate, a realNewTaskLoaderrun with noPostStopHooksset, asserting a marked output is absent from every ConfigMap value, present in the Secret, and readable throughGetVar../pkg/...green with-p 1. Note the repo pinsENVTEST_K8S_VERSION = 1.37; with 1.31 assets four suites fail atBeforeSuite.TestMetricCheckfails only under concurrentgo test, a pre-existing collision betweenpkg/providers/metricsandpkg/providers/legacy/metrics.