Skip to main content

Secure workflows with access policies

In a multi-application workflow, a parent workflow running on one app schedules child workflows and activities on another app. By default, any app in a Diagrid project can do this to any other app. The same is true for the other cross-app workflow operations: with no policy, an app can get, raise events to, pause, resume, terminate, purge, start and rerun the workflow instances of any other app in the project. Workflow access policies let you lock this down: you declare which caller apps are allowed to run which operations on which workflows and activities on a target app, and Diagrid denies everything else.

A WorkflowAccessPolicy is a project-level resource that you manage with the diagrid workflow access-policy commands or apply declaratively as a YAML manifest.

How policies work​

A policy has two parts:

  • Scopes — the target apps the policy protects. Leave scopes empty to protect every app in the project.
  • Rules — each rule grants a list of callers (apps) access to specific workflows and activities on the target apps. Names are matched exactly or as glob patterns: * matches any sequence of characters, ? matches a single character, and [abc] matches a character set.

Policies are a pure allow-list. As soon as a policy covers an app, every cross-app workflow call to that app must match a rule — if no rule matches, Diagrid denies the call with a PermissionDenied error. Without any policy in place, all cross-app calls are allowed, including calls that read a workflow's input and output or that terminate or purge a workflow instance.

Workflow access policy evaluationDiagridOrchestrator appApp IDorchestrator-appAccess policyApp IDorder-appOrder appscheduleorder-workflowallowed
Workflow access policy evaluationDiagrid evaluates the access policy for the caller's App ID before the workflow is scheduled on the target app.

Three behaviors to keep in mind:

  • Self-calls are always allowed. A policy only gates cross-app calls; an app can always schedule and manage its own workflows and activities, so it never needs to list itself as a caller. A rule that lists the target app as a caller is accepted, but it has no effect.
  • Multiple policies combine. When several policies cover the same app, a call is allowed if any rule in any of them matches.
  • Policies apply to every cross-app workflow operation. Workflow rules require an operations field. The values are schedule, get, raise, pause, resume, terminate, purge, and rerun. These operations route between apps, and a policy denies each one that no rule allows with PermissionDenied. Activity rules have no operations field because activities only support scheduling.

Create a policy​

The fastest way to create a policy is with the --scopes and --callers flags:

diagrid workflow access-policy create order-app-policy \
--project my-project \
--scopes order-app \
--callers orchestrator-app,reporting-app

This protects order-app and allows orchestrator-app and reporting-app to schedule every workflow and activity on it. Any other app in the project that tries is denied.

Fine-grained rules with a YAML manifest​

The --callers flag is all-or-nothing. To grant access to specific workflows, activities and operations, define the policy as a YAML manifest and apply it:

# order-app-policy.yaml
apiVersion: dapr.io/v1alpha1
kind: WorkflowAccessPolicy
metadata:
name: order-app-policy
scopes:
- order-app
spec:
rules:
- callers:
- appID: orchestrator-app
workflows:
- name: order-processing
operations: [schedule]
- name: "report-*"
operations: [schedule]
activities:
- name: charge-payment
diagrid workflow access-policy create -f order-app-policy.yaml --project my-project

Here orchestrator-app can schedule the order-processing workflow, any workflow whose name starts with report-, and the charge-payment activity on order-app — and nothing else. Prefer exact names over glob patterns where you can; a broad pattern like * grants more than you might intend.

Known issue: a cross-app start can report PERMISSION_DENIED

With only schedule, a client that starts a workflow on another app gets PERMISSION_DENIED for the operation get, but the workflow starts and runs. A client that retries on this error starts the workflow again. Until this is fixed, also grant get to a caller that starts workflows: operations: [schedule, get].

Start from deny by default​

For the strictest posture, apply a single policy with no scopes and no rules. It covers every app in the project, and because policies are a pure allow-list, it denies every cross-app workflow call:

# default-deny.yaml
apiVersion: dapr.io/v1alpha1
kind: WorkflowAccessPolicy
metadata:
name: default-deny
spec:
rules: []

Each app can still run its own workflows and activities, since self-calls are always allowed. From this baseline, layer on narrowly scoped policies like the earlier examples to grant only the access each caller needs.

Known issue: cross-app child workflows do not complete under a policy

A policy that covers the app of a parent workflow blocks the result of a child workflow that runs on another app. The child completes, but the parent does not get the result and stays running, with no error. No rule in the policy prevents this today. Deny by default covers every app, so it always causes this. If your workflows start child workflows on other apps, do not apply a policy that covers the parent's app.

Manage policies​

List the policies in a project:

diagrid workflow access-policy list --project my-project

Inspect a policy, including its full rule set:

diagrid workflow access-policy get order-app-policy --project my-project -o yaml

Update a policy with flags. The flags replace the corresponding fields of the existing policy, so the example below replaces all existing rules with a single grant that allows orchestrator-app to schedule everything:

diagrid workflow access-policy update order-app-policy \
--project my-project \
--callers orchestrator-app

To change fine-grained rules, edit the YAML manifest and run diagrid workflow access-policy update -f — the manifest replaces the existing policy.

Delete a policy to lift its restrictions:

diagrid workflow access-policy delete order-app-policy --project my-project

Verify a policy​

To confirm a policy is enforced, schedule a workflow or activity from an app that no rule allows. The caller receives a PermissionDenied error:

access denied by workflow access policy: app 'reporting-app' operation 'schedule' on workflow 'order-processing'

Calls that match a rule continue to succeed, and the target app never sees the denied requests.

Next steps​