Skip to content

Fix: store sensitive step outputs in a companion Secret instead of the plaintext context ConfigMap - #245

Open
sakirr05 wants to merge 1 commit into
kubevela:mainfrom
sakirr05:fix/sensitive-step-outputs-secret-store
Open

sakirr05 wants to merge 1 commit into
kubevela:mainfrom
sakirr05:fix/sensitive-step-outputs-secret-store

Conversation

@sakirr05

@sakirr05 sakirr05 commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

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>-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 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" across
sources and workflow steps rather than a second one here.

A new pkg/cue/sensitive walks the template AST and returns the marked paths. It is a copy of kubevela's pkg/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:

  1. Paths are absolute from the template root, with no block allowlist, so they compare directly against a step's valueFrom.
  2. It descends into if/for bodies and embeddings. kubevela's walker only looks at *ast.Field and skips *ast.Comprehension, which matters more here: read-object's entire output: block is two if arms, so a marker
    in one would have been dropped. This is the divergence worth carrying back.
  3. An unparseable template returns an error rather than nil, since returning nil is the silent under-redaction this exists to prevent.

Paths are extracted once per template in makeTaskGenerator, behind a content-keyed memo, not on every step run.

Where the values go.

  • Outputs whose valueFrom overlaps a marked path are routed through a new SetSensitiveVar instead of SetVar. Matching is bidirectional: extracting a parent of a marked path still carries the value, so it is sensitive too.
  • Sensitive vars persist to a companion Opaque Secret
    (workflow-<name>-context-sensitive) with the same owner references as the
    ConfigMap, so GC is unchanged. It is created only once something sensitive exists; plain workflows never get one.
  • GetVar reads both stores, consulting the Secret first, so data passing between steps is unchanged regardless of where a var lives.
  • A failed Secret write fails the Commit, so the 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.

Failing closed. If the markers cannot be read, every output goes to the Secret: "could not tell" is not "nothing is secret". Likewise, a valueFrom that is an expression rather than a plain dotted path, against a template that
marked 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 vars

No plaintext left behind. SetSensitiveVar removes the same path from wf.vars, so writeToStore cannot re-serialize a stale copy. CUE has no un-unify, so removal happens on the syntax tree in a new value.DeletePath,
mirroring how SetValueByScript already round-trips through format.Node.

One deliberate asymmetry: GetVar() with no path returns the ConfigMap vars only. A path-less read cannot say which field it wants, and vela dumping a whole context must not print credentials. It has its own test so it does not
read as an oversight later.

Plumbing note. pkg/executor installed one shared hooks.Output for every step, which left nowhere to put a per-template hook, so it no longer sets PostStopHooks and each task runner builds its own list locally; the shared
TaskRunOptions is never mutated across steps, and a caller that sets PostStopHooks itself keeps full control. types.TaskPostStopHook and hooks.Output are unchanged, so no exported signature moved. A step group has
no template, so it keeps the plain hooks.Output.

How has this code been tested

  • pkg/cue/sensitive: absolute paths, descent and dedupe, if/for bodies, embeddings and conjunctions, list elements and quoted labels, a mark covering everything beneath it, an unparseable template returning an error, Covers
    in both directions and dropping list indices. - pkg/context: Secret round trip, no Secret when nothing is sensitive,
    LoadContext recovery, a foreign Secret under the companion name refused, the plaintext copy evicted, the store labelled, and GetVar() 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 real NewTaskLoader run with no PostStopHooks set, asserting a marked output is absent from every ConfigMap value, present in the Secret, and readable through GetVar.
  • Full ./pkg/... green with -p 1. Note the repo pins
    ENVTEST_K8S_VERSION = 1.37; with 1.31 assets four suites fail at BeforeSuite. TestMetricCheck fails only under concurrent go test, a pre-existing collision between pkg/providers/metrics and pkg/providers/legacy/metrics.

@codecov

codecov Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.54475% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.75%. Comparing base (d7db9c4) to head (b86c53b).
⚠️ Report is 55 commits behind head on main.

Files with missing lines Patch % Lines
pkg/context/context.go 76.28% 23 Missing ⚠️
pkg/cue/model/value/value.go 60.00% 22 Missing ⚠️
pkg/cue/sensitive/sensitive.go 94.04% 5 Missing ⚠️
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     
Flag Coverage Δ
e2etests 38.21% <30.35%> (?)
unit-test 75.12% <77.82%> (+12.63%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread pkg/hooks/data_passing.go Resolved
Comment thread pkg/context/context.go Resolved
Comment thread pkg/context/context.go Resolved
@briankane

Copy link
Copy Markdown
Member

Thanks for this, and sorry it's taken a while to get a decision on it. We'd like to go with your approach:
the template author says what's secret, it lands in a companion Secret only when there is something sensitive,
GetVar reads both, and expressions fail closed. That's the right shape.

One change to how it's declared. KubeVela already has a marker for this: SourceDefinitions mark a field
// +sensitive and it covers everything beneath it (KEP-2.16, extractor in kubevela's
pkg/sources/source_sensitive.go). We'd rather definition authors had one way to say "this is secret" across
sources and workflow steps than a second one in $sensitivePaths. So:

  • Read the step's sensitive paths from the // +sensitive fields in its template, with the same rules as that
    extractor (nested structs, list elements and if/for bodies, a mark covering everything beneath it). A copy
    of it in workflow is fine for now; workflow can't import kubevela, and moving it to kubevela/pkg so both share
    one is tracked in Share the // +sensitive marker extractor between kubevela and workflow pkg#162.
  • Work them out once per template rather than on every run.
  • $sensitivePaths goes.

And the three open review points before it can land:

  • a malformed declaration has to fail closed, not open;
  • an existing Secret with that name shouldn't be overwritten unless we own it;
  • once a var moves to the Secret, its old value has to come out of the ConfigMap.

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>
@sakirr05
sakirr05 force-pushed the fix/sensitive-step-outputs-secret-store branch from 210737c to b86c53b Compare November 22, 2026 18:03
@sakirr05

Copy link
Copy Markdown
Member Author

Thanks @briankane, all of that sits right. Pushed: $sensitivePaths is gone and the paths now come from // +sensitive in the template, read by a new pkg/cue/sensitive (a copy of kubevela's extractor, with kubevela/pkg#162 referenced and three divergences documented, the notable one being that it descends into if/for bodies, which kubevela's skips and read-object's two-arm output: block needs). Worked out once per template in makeTaskGenerator, behind a content-keyed memo

The three points are fixed at the root: unreadable markers route every output to the Secret, the store is stamped with workflow.oam.dev/context-store and verified along with owner refs on both the write and the read path, and SetSensitiveVar evicts the plaintext from wf.vars with GetVar reading the Secret first

One structural change worth your eyes: pkg/executor installed one shared hooks.Output for every step, leaving nowhere for a per-template hook, so it no longer sets PostStopHooks and each task runner builds its own locally. No exported signature moved.

The earlier red unit-tests was mine and unrelated: the new test files imported crossplane-runtime/pkg/test while the repo is on /v2. ./pkg/... is green now with -p 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/data-passing Inputs, outputs, parameterKey and the workflow context store (pkg/hooks, pkg/context) security Security-relevant change or report type/feature New feature or request

Projects

None yet

2 participants