[Backport release-0.8] Fix: workflow fixes from the v1.12 release testing

Merged
BR
9d ago
+2136-152

Description of your changes

Backport of kubevela/workflow#287 to release-0.8, the workflow line KubeVela 1.12 ships with. The same five
commits, applied cleanly.

I have:

  • All commits are signed off (DCO).

How has this code been tested

Every commit builds on its own; the unit tests pass as on main, and lint is clean.

What each commit changes (5 commits)

Fix(http): bound a workflow HTTP request's time and response size

Before: A request with timeout "0" or a negative one had no timeout, ran on a context the reconcile could not cancel, and read its whole response into memory, holding a reconcile worker.

Now: Both HTTP providers refuse a zero, negative or over-the-maximum timeout (60s by default, --max-workflow-http-timeout), keep 3s when unset, run on the step's context and refuse a body over 1 MiB (--max-workflow-http-response-bytes). Chart values workflow.http.maxTimeout and workflow.http.maxResponseBytes.

Tests: bounds_test.go

Behaviour change for existing users: Steps with a zero, negative or too-large timeout, or a response over 1 MiB, now fail. Set a valid timeout or raise the chart values.

Fix(http): read a step's TLS Secret only from its own namespace

Before: An HTTP step's tls_config Secret was read from any namespace it named, namespace/name references never resolved, and TLS errors were swallowed so the request went out without the certificate.

Now: The Secret is read from the step's namespace, or another only when the step's user may get it there. References parse correctly, the PEM may be raw or base64-encoded, a CA alone is fine, and a Secret with no TLS material or a half keypair fails the step.

Tests: stepsecret_test.go, tls_namespace_test.go, tls_secret_test.go

Behaviour change for existing users: A step whose TLS Secret lives in another namespace, or whose TLS config cannot be applied, now fails. Move the Secret into the step's namespace and check its keys (ca.crt, client.crt, client.key).

Fix: stop completed side-effect steps of a WorkflowRun running again

Before: A reconcile from a stale cached WorkflowRun, or a status write lost to a conflicting write (a kubectl annotate, a GitOps sync, a user's terminate), could run completed webhook and notification steps again.

Now: A reconcile reads the WorkflowRun from the API server while the cache is behind its last write; that record is dropped once the cache shows it, and a finished run's a minute after its finishing write. A status write that conflicts is merged onto the live run, up to three writes: this reconcile's step records are written, and what the other writer changed (terminate and suspend, and the steps the user operations moved) is kept, for that write and every later one in the reconcile; a terminate is applied to the merged status as TerminateWorkflow applies it (both through utils.TerminateStatus), so the steps after the in-flight one stop and the run ends terminated. A run restarted since (including from a step or sub-step) is not merged over: the conflict is returned and the step guard follows the restarted run. A failed write sets the step guard to the steps last written.

Tests: runs_once_test.go (user operations survive a conflicting write, merged writes keep the user's terminate and the reconcile's own suspend, a merged terminate still stops the run, restarts including from a sub-step are not merged over, step guard and own-write record cleanup); runs_once_reconcile_test.go (a full reconcile with a terminate mid-request between two suspend steps, asserting no later step runs and the run ends terminated, and with an annotate mid-step; EnablePatchStatusAtOnce on and off)

Behaviour change for existing users: None.

Fix: fail a step whose $( ) if cannot be evaluated

Before: A runtime error in a step's $( ) condition skipped the step, and the workflow went on to succeed without it.

Now: The step fails with the evaluation error; a read still pending keeps it waiting as before. A CUE if that errors still skips, as in 1.11.

Tests: condition_test.go

Behaviour change for existing users: Workflows whose $( ) conditions error now fail instead of silently skipping the step. Fix the condition (for example guard a missing output).

Fix(http): check the IPv4 address a NAT64 address carries

Before: An address under the well-known NAT64 prefix (64:ff9b::/96) reached its embedded IPv4 address without that address's deny rules applying.

Now: The embedded IPv4 address is checked too, using the longest matching prefix. Network-specific prefixes can be added with --workflow-http-nat64-prefix (chart workflow.http.nat64Prefixes); IPv4-mapped prefixes are refused.

Tests: policy_test.go

Behaviour change for existing users: Requests to a denied IPv4 address through a NAT64 address are now refused like the address itself.

Behaviour changes in this PR
  • Fix(http): bound a workflow HTTP request's time and response size: Steps with a zero, negative or too-large timeout, or a response over 1 MiB, now fail. Set a valid timeout or raise the chart values.
  • Fix(http): read a step's TLS Secret only from its own namespace: A step whose TLS Secret lives in another namespace, or whose TLS config cannot be applied, now fails. Move the Secret into the step's namespace and check its keys (ca.crt, client.crt, client.key).
  • Fix: fail a step whose $( ) if cannot be evaluated: Workflows whose $( ) conditions error now fail instead of silently skipping the step. Fix the condition (for example guard a missing output).
  • Fix(http): check the IPv4 address a NAT64 address carries: Requests to a denied IPv4 address through a NAT64 address are now refused like the address itself.

Summary by cubic

Backports the workflow fixes from kubevela/workflow#287, plus the TLS Secret namespace/name lookup fix from #278, to the release-0.8 line that KubeVela 1.12 ships with.

  • Workflow HTTP requests now refuse an unbounded timeout or an unlimited response body, with 60s and 1 MiB as the defaults, both exposed in the chart.
  • An HTTP step's tls_config Secret reference now parses correctly as a name or namespace/name and resolves from the step's namespace, or another only when its user may read it there.
  • Conflicting WorkflowRun status writes are retried against the live object, so completed webhook and notification steps do not run again.
  • A runtime error in a step's $( ) condition now fails the step instead of silently skipping it.
  • NAT64 addresses are also checked by the IPv4 address they carry, with the well-known and local-use prefixes enabled by default.