Skip to main content

Securing Batch Operations

· 6 min read
Shuayb Kassim
Software Engineer Intern @ Uber

A Cadence batch operation can terminate, cancel, signal, replicate or refresh thousands of workflows with one command. Batch operations now go through a dedicated BatchAPI, so a batch started through it is checked against the domain it changes and records who started it. This post covers why we built it and how it works.

Why we built it​

A batch operation applies one action to every workflow that matches a query: terminate, cancel, signal, replicate or refresh. A single request can reach thousands or millions of workflows, so it matters who is allowed to start one, and on which domain.

Until now, the CLI and Cadence Web started a batch by starting a built-in batch workflow in the cadence-batcher system domain. The domain to change, the query and the operation were passed to that workflow as input. This worked, but it left a gap. The access check at start only saw the cadence-batcher domain, because the domain being changed was just a field inside the workflow input. The actions the batch performs were also recorded under the batch workflow, not under the person who asked for them.

We closed that gap by making the batch an explicit API call. The request names the domain it changes, so the existing access check can look at it.

Figure 1: The request path before and after the BatchAPI. The batch workflow is the same in both.

How it works​

The BatchAPI is a gRPC service with five calls:

CallWhat it does
StartBatchOperationStarts a batch. It returns as soon as the batch is accepted, and the work runs asynchronously.
DescribeBatchOperationReturns the state, who started the batch, its limits and its progress.
ListBatchOperationsLists the batches for a domain, optionally filtered by state.
StopBatchOperationStops a running batch. Work that was already applied is not undone.
UpdateBatchOperationChanges the RPS and/or concurrency of a running batch.

Every request carries the domain the batch acts on as a top-level field. The frontend authorizes the call like any other domain API, then starts the batch workflow in cadence-batcher on the caller's behalf. The batch workflow itself did not change. Only the way you reach it did.

Figure 2: What happens when a batch starts. The response returns as soon as the batch is accepted.

A few choices are worth calling out:

  • The operation is a oneof, not an enum. Terminate, cancel, signal, replicate and refresh each carry their own parameters, for example the signal name and input for a signal. Adding a new operation later means adding a message, which is backward compatible.
  • Start is idempotent. You choose the batch ID, and it is scoped to the domain. Retrying a start with the same domain and batch ID returns the same batch instead of starting a second one.
  • The starter is recorded. The caller's identity is stored in the Operator search attribute, and describe and list return it as startedBy.

The BatchAPI is gRPC only. There is no Thrift equivalent.

Every batch is in one of a few states, and list --state filters on them:

Figure 3: The states of a batch operation.

Trying it​

The new commands live under cadence batch, from v1.4.6-prerelease06. Starting a batch looks like this:

$ cadence --domain cadence-samples batch start terminate \
--query "WorkflowType = 'order-workflow' AND CloseTime = missing" \
--reason "cleanup after release" \
--batch_id release-cleanup

From there, list, describe, update and stop follow the batch, change its rate and stop it. For every command, flag and requirement, see the Batch Operations page.

How access is checked​

Two questions decide whether a request is allowed: who is calling, and what that caller may do on a domain. Cadence's authorizer already answers both for the rest of the API. It takes the caller from the request context and checks the request against the domain it names.

That is why each BatchAPI request names its domain. The authorizer now sees the domain the batch changes, not the system domain the batch runs in. A caller needs access to the target domain, and does not need access to cadence-batcher. After the check passes, the server starts the batch workflow itself.

Try it yourself. Choose which domains the caller can use, which domain the batch changes, and how the batch is started:

The caller has access to
The batch changes workflows in
The batch is started through
Allowed (never checked against the target domain)
Access check sees: cadence-batcherAccess policy on it: none, so it is open

The check saw cadence-batcher, which has no access policy here. The caller has no access to billing, and the batch can still act on it.

A simplified model for illustration. Real policies depend on the authorizer you run. Here, cadence-batcher has no access policy.

Figure 4: A simplified access check. With the old way, the check sees only cadence-batcher. With the BatchAPI, it sees the target domain.
The old way still works

Starting the batch workflow in cadence-batcher directly is still possible, and the cadence workflow batch commands still exist. Until access to that domain is restricted, the new check is something the tools use, not a barrier.

The check runs on each BatchAPI call, including the start. Once a batch is running, this change does not narrow what the batch workers can reach.

What's next​

  • Close the old way. Once the CLI and Cadence Web use the BatchAPI, access to cadence-batcher can be restricted so the domain check applies to every batch.
  • Move Cadence Web over. The Web routes for start, list, describe, stop and update are in place, and the UI is being moved onto them behind a feature flag. For the UI itself, see Batch Actions UI.
  • Audit logging. The starter is already recorded on every batch. An audit trail built on it is one possible follow-up.

To learn how Cadence handles identity and access in general, see Identity & Access Management. The cadence batch commands are documented on the Batch Operations page, and the older cadence workflow batch commands in the CLI reference.

Try it today​

Run cadence batch --help against your own setup. We'd love to hear how you use it.