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

SA
11h ago
+558-3

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 whose valueFrom overlaps a declared path (either
    direction — extracting a parent of a sensitive path still includes the value)
    get routed through a new SetSensitiveVar instead of SetVar.
  • 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.
  • GetVar reads both stores transparently, so inputs/data-passing between
    steps work exactly as before regardless of where a var lives.
  • If valueFrom is 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 SetSensitiveVar to persist sensitive vars to workflow-<name>-context-sensitive (Opaque, owner-referenced).
    • Output() routes outputs whose valueFrom overlaps $sensitivePaths; expressions are treated as sensitive.
    • GetVar reads from both ConfigMap and Secret; EnableInMemoryContext keeps sensitive data in memory only.
    • Secret write errors fail commit; no fallback to ConfigMap; no Secret is created for non-sensitive workflows.
  • Migration

    • Add $sensitivePaths to step templates to protect outputs; existing templates stay unchanged.