Introducing a new way to review your PRs.

Read the announcement

elsa-workflows / elsa-core

The Workflow Engine for .NET

View on GitHub

32 documents · Updated Oct 7, 2026

docs / workflow-credential-bindings

Workflow credential bindings and grants

Workflow credential bindings let a tenant-owned workflow refer to a stored connection without saving credential values in workflow state. The resolver checks the host environment, the current binding, workflow-use permission, and connection lifecycle before it returns short-lived access material to the running activity.

Credential binding model

A logical binding is a stable workflow-facing name that points to one connection in one tenant and one host environment. The binding stores only the connection identity and a revision. A workflow input can name the logical binding, but it cannot choose the tenant or environment used for resolution. See Connections and credentials for the wider connection lifecycle.

The separation between a binding and a grant is intentional:

  • A binding selects the connection that currently represents a logical need such as payments.
  • A grant permits one workflow instance to use one exact binding revision.
  • The connection lifecycle remains a separate check. A valid binding or grant does not keep a disconnected connection usable.

References: src/…/ConnectionCredentialBinding.cs• L3-11 src/…/ConnectionCredentialUseGrant.cs• L3-20 src/…/IConnectionCredentialBindingStore.cs• L5-14

Binding scope and revision

Binding scope is the tuple of tenant, environment, and logical binding ID. The host supplies the environment through configuration. The workflow execution supplies the workflow instance ID for authorization, but it does not supply the environment or tenant. Bindings start at revision 1 and each successful rebind advances the revision.

Creation and rebind require a management authorizer. Rebind also requires the caller to provide the expected current revision. This compare-and-swap rule prevents a stale administrator or worker from replacing a newer connection. New resolutions read the latest revision, so a rebind affects later uses after the current authorization checks complete.

References: src/…/WorkflowCredentialBindingOptions.cs• L3-7 src/…/WorkflowCredentialBindingManager.cs• L15-68 src/…/EFCoreConnectionCredentialBindingStore.cs• L23-97

Workflow credential resolution

The workflow credential resolver is the controlled entry point for an activity that needs a stored connection credential. It converts the logical binding name into an authorized connection access credential, while keeping the value outside durable workflow data and normal serialized responses.

When a workflow asks for a credential, the resolver follows this sequence:

  1. Read the trusted tenant and configured environment.
  2. Load the logical binding for that scope.
  3. Ask the host use authorizer to approve the exact workflow, connection, and binding revision.
  4. If grant control is enabled, check the durable grant for the same workflow instance and snapshot.
  5. Read the binding again and reject a concurrent rebind.
  6. Ask the connection lifecycle service to resolve the current active credential.

This sequence makes authorization a point-in-time admission decision. A rebind after the final check does not cancel a call already admitted with the old snapshot. A later resolution uses the new revision. The lifecycle service separately checks that the connection is active, its stored generation is usable, and its credential material is valid.

The flow below shows the boundary between workflow authorization and connection lifecycle resolution.

flowchart TD
    A[Workflow activity requests logical binding] --> B[Read trusted tenant and host environment]
    B --> C[Load binding and connection revision]
    C --> D{Host use authorizer allows?}
    D -- No --> X[Fail as connection unavailable]
    D -- Yes --> E{Durable grant allows exact snapshot?}
    E -- No --> X
    E -- Yes --> F{Binding still has same revision and connection?}
    F -- No --> X
    F -- Yes --> G[Connection lifecycle resolves active credential]
    G --> H[Activity receives short-lived access credential]

References: src/…/WorkflowCredentialResolver.cs• L12-68 src/…/DefaultConnectionLifecycleService.cs• L216-280 src/…/IConnectionBackgroundUseService.cs• L5-12

Credential material boundary

The resolver returns a ConnectionAccessCredential only after all checks pass. OAuth access material includes an expiry; API-key material has no expiry value. Both forms are write-only for JSON and redact their secret value. Refresh material stays inside connection lifecycle management.

Workflow state should therefore retain the logical binding reference rather than the resolved credential. This keeps a persisted or resumed workflow independent of a particular token generation and allows the lifecycle service to apply rotation, expiry, or disconnect checks at the time of use.

References: src/…/CredentialMaterial.cs• L6-24 src/…/CredentialMaterial.cs• L27-93 test/…/WorkflowCredentialBindingTests.cs• L576-669

Credential-use grants

A credential-use grant is a durable permission for one workflow instance to use one logical binding revision. It records scope, workflow identity, connection identity, binding revision, issuing actor, and grant state. It never carries credential material.

Grant management is separate from connection management. An actor must pass the grant management authorizer before issuing or withdrawing a grant. Issuance checks that the requested binding revision still exists and points to an active connection. Withdrawal uses the current grant revision and marks the grant inactive while advancing its revision.

The grant is narrow by design. A grant for another workflow instance, tenant, environment, connection, or binding revision does not authorize use. A rebind makes an older grant stale. A disconnected connection also fails even when its grant remains active.

References: src/…/WorkflowCredentialGrantManager.cs• L10-95 src/…/EFCoreConnectionCredentialUseGrantStore.cs• L9-112 src/…/ConnectionCredentialUseGrantConfiguration.cs• L7-23

Authorizer composition

Workflow use has two policy boundaries. The host use authorizer can apply deployment-specific rules to the exact binding request. The stored-grant authorizer then checks the durable grant and current connection status. Grant enablement replaces only the adapter’s default deny rule; it does not override a host policy that denies the request.

The system also defaults management paths to deny. A host must explicitly provide policy for binding creation or rebind, grant issue or withdrawal, and credential use. This prevents installing the workflow feature from silently making stored connections usable.

References: src/…/WorkflowCredentialBindingsFeature.cs• L13-27 src/…/WorkflowCredentialUseGrantsFeature.cs• L12-33 src/…/StoredConnectionCredentialBindingUseAuthorizer.cs• L6-26 src/…/DenyAllConnectionCredentialBindingAuthorizers.cs• L5-16

Persistence and unavailable services

Durable binding and grant stores provide the continuity needed for workflow resume and multi-host execution. The persistence layer uses tenant and environment scope, unique logical references, and revision checks so concurrent workers cannot silently overwrite a binding or duplicate an active grant.

When a host does not register a durable store, the workflow feature supplies an unavailable-store fallback. The fallback reports no binding or grant and does not create or withdraw records. Resolution and management then fail closed with the safe connection_unavailable result or exception. Missing environment configuration, default or agnostic tenant scope, invalid identifiers, missing authorizers, and missing lifecycle services follow the same safety goal: no credential service call occurs.

References: src/…/UnavailableConnectionCredentialBindingStore.cs• L6-33 src/…/UnavailableConnectionCredentialUseGrantStore.cs• L6-20 src/…/WorkflowCredentialBindingManager.cs• L58-68 test/…/WorkflowCredentialBindingTests.cs• L258-308 test/…/WorkflowCredentialBindingTests.cs• L397-418

Persisted workflow resume

On resume, the runtime must restore the workflow’s tenant context before the resolver reads the binding. The workflow carries the logical binding reference, while the host context supplies the tenant and environment used to find the binding and grant. A wrong tenant cannot load the instance or reach credential resolution. A wrong environment finds no matching binding or grant.

This allows a workflow to resume on another host without copying secret values between hosts. It also means that a host environment change is a scope change, not an automatic migration of an existing binding.

References: test/…/WorkflowCredentialBindingTests.cs• L576-669 test/…/WorkflowCredentialBindingTests.cs• L680-822 doc/…/workflow-use-grant-runtime-validation.md• L3-11

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the binding revision in step with the connection and grant snapshot checks. A change that updates one revision without the others can admit stale workflow access.
  • Preserve the host-owned environment boundary. Do not allow workflow input or persisted workflow data to select a different environment.
  • Keep grant management separate from binding management. Connection access permission must not become an implicit grant.
  • Keep both authorizer layers active when grant support is enabled. A grant must not bypass a host use policy.
  • Keep credential values outside workflow state, grant records, logs, and JSON output. Changes to credential result types must preserve write-only behavior.
  • Keep unavailable-service defaults fail closed. A missing binding store, grant store, authorizer, or environment must not become an allow path.

Important failure modes

TriggerConsequenceGuard
Binding revision changes after the first authorization checkResolution stops before the lifecycle service is calledRe-read the binding and compare both connection ID and revision
Grant belongs to another workflow or binding revisionThe workflow receives connection unavailableMatch tenant, environment, workflow instance, logical binding, connection, and binding revision
Connection is disconnected or its current credential generation is invalidAn active-looking grant cannot produce a credentialRecheck connection lifecycle state and current generation during resolution
Durable binding or grant persistence is not configuredBinding and grant operations report unavailable and no credential is returnedUse unavailable stores and deny by default
Host use policy denies a request after a grant is issuedNo credential service call occursRun the host authorizer and stored-grant check as separate gates
Resumed workflow runs under the wrong tenant or environmentThe instance or binding is not foundRestore trusted tenant context and use the host-configured environment

Key files

FileWhy to read it
src/…/WorkflowCredentialResolver.csShows the end-to-end resolution and admission checks.
src/…/WorkflowCredentialBindingManager.csShows creation, rebind, scope, and revision control for logical bindings.
src/…/WorkflowCredentialGrantManager.csShows separate grant issue and withdrawal policy.
src/…/StoredConnectionCredentialBindingUseAuthorizer.csShows how a durable grant and live connection state combine at use time.
src/…/ConnectionCredentialBinding.csDefines the tenant-scoped logical binding record.
src/…/ConnectionCredentialUseGrant.csDefines the workflow-specific permission snapshot.
src/…/DefaultConnectionLifecycleService.csShows the final active-connection and credential-material checks.
src/…/EFCoreConnectionCredentialBindingStore.csShows durable binding persistence and compare-and-swap rebinds.
src/…/EFCoreConnectionCredentialUseGrantStore.csShows durable grant issuance and withdrawal rules.
test/…/WorkflowCredentialBindingTests.csDemonstrates tenant, environment, revision, grant, resume, and fail-closed behavior.
doc/…/workflow-use-grant-runtime-validation.mdSummarizes the persisted multi-host runtime validation and its limits.