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 / connections-and-credentials

Connections and credential lifecycle

Connections give Elsa a tenant- and environment-scoped way to use an external provider account. The domain keeps provider identity separate from secret material, controls who may manage or use a connection, and moves credential changes through durable states so a crash does not silently lose a token or publish an unknown value. Workflow-time bindings and grants build on this domain but are described in Workflow credential bindings.

Connection domain

An integration connection is the durable link between an Elsa environment and one provider account. It records the provider identity, current lifecycle state, revision, and a pointer to the current credential generation. The connection does not expose the credential value as part of its metadata.

The main connection states describe whether a consumer may use the current generation:

StateMeaning
ActiveThe connection has a published generation that may be resolved after authorization.
DisconnectedLocal use is stopped. Provider offboarding may still be pending.
RecoveryRequiredA credential operation crossed a point where its result is not known. Use stays blocked until reconciliation can safely restore or publish a generation.

The revision changes when connection state or its published generation changes. Consumers use it as a concurrency marker, so a stale management request cannot overwrite a newer connection state.

References: src/…/IntegrationConnection.cs• L6-18 src/…/IntegrationConnection.cs• L21-68 src/…/IConnectionLifecycleService.cs• L50-64

Credential material

Credential material is provider data held for lifecycle work. OAuth material contains an access token, a refresh token, and an access-token expiry. API-key material contains one non-expiring value. Refresh material stays inside lifecycle management; an authorized consumer receives only an access credential for the current generation.

The lifecycle service stores the material through the managed Secrets boundary. The connection stores only the secret name, generation identity, credential kind, and safe scheduling data. Managed generations are owner-checked and cannot be read or deleted as ordinary secrets. This separation lets the connection domain rotate or retire values without placing raw credentials in connection records, workflow state, grants, or normal responses.

An access credential is write-only on the wire: its serialized form reports its kind and OAuth expiry, but not the value. This keeps response metadata useful without turning management or diagnostic output into a credential transport.

References: src/…/CredentialMaterial.cs• L6-24 src/…/CredentialMaterial.cs• L27-93 src/…/IManagedSecretManager.cs• L5-24 src/…/DefaultSecretManager.cs• L173-224

Credential generation flow

Credential updates use a staged generation model. A generation is an immutable unit of credential material. The service first records durable operation intent, then creates the protected generation, records that generation as staged, and publishes it only after the database confirms that the operation still owns the expected revision.

The flow protects one-time provider actions and supports recovery after process loss:

flowchart LR
    A[Connect or refresh] --> B[Claim operation]
    B --> C[Call provider when required]
    C --> D[Create protected generation]
    D --> E[Record staged generation]
    E --> F[Publish current generation]
    F --> G[Active connection]
    C --> H[Unknown result]
    D --> H
    E --> H
    H --> I[Recovery required]
    I --> J[Reconcile and promote or restore]

An OAuth refresh advances through the provider boundary only after the service records that the call started. If the result is uncertain after that point, the connection becomes unavailable instead of replaying a refresh token that may already have been consumed. API keys use the same generation and publish model but do not use provider refresh and do not receive an expiry.

The old generation remains available until the new generation is safely published and cleanup proves that the old generation is no longer current or referenced by an unresolved operation. This makes cancellation and retry safe across the database and Secrets store.

References: src/…/DefaultConnectionLifecycleService.cs• L137-214 src/…/DefaultConnectionLifecycleService.cs• L512-657 src/…/DefaultConnectionLifecycleService.cs• L759-872 src/…/EFCoreConnectionLifecycleStore.cs• L531-761

Authorization boundaries

Connection use is an explicit authorization decision over a principal, tenant, environment, connection, and purpose. Identifiers select a resource but do not prove access. The authorizer also distinguishes human actions from trusted background actions, so a caller cannot obtain system-level behavior by choosing a different request kind.

The lifecycle service applies authorization before connect, use, refresh, disconnect, revocation, uninstall, cleanup, and reconciliation. Background access uses a service-owned system identity and a host-only contract. The default connection feature denies use until the host installs a real policy.

Workflow bindings add two separate controls. A binding selects a connection for a logical workflow reference but grants no use by itself. A workflow grant authorizes one workflow instance to use one binding revision. At resolution time the grant must still be active and match the binding snapshot, while the lifecycle service must still find the connection active. See Workflow credential bindings for that workflow-specific contract.

References: src/…/IConnectionUseAuthorizer.cs• L5-26 src/…/IConnectionBackgroundUseService.cs• L5-12 src/…/DefaultConnectionLifecycleService.cs• L216-280 src/…/DefaultConnectionLifecycleService.cs• L874-875 src/…/DenyAllConnectionUseAuthorizer.cs• L5-8 src/…/StoredConnectionCredentialBindingUseAuthorizer.cs• L6-26

Offboarding

Offboarding separates local shutdown from remote provider actions. A disconnect changes the local connection to Disconnected and records the local operation. Token-pair revocation and installation uninstall are then durable provider operations that can be retried or reported for operator action.

Each provider operation carries a stable operation identity, a lease, a fence, an attempt count, and a safe error code. The provider declares whether repeating that operation identity is safe. A confirmed success is completed durably. A retryable failure is scheduled again. An outcome that may have reached the provider becomes UnknownOutcome and is not replayed automatically unless the provider guarantees stable operation-id idempotency.

Generation cleanup follows the same no-secret principle. The lifecycle store first records that a retired generation is no longer current and is not needed by an unresolved operation. Only then may the managed Secrets service delete the owner-checked generation. A durable cleanup tombstone prevents the same generation identity from being staged or published again.

References: src/…/DefaultConnectionLifecycleService.cs• L283-510 src/…/DefaultConnectionLifecycleService.cs• L659-757 src/…/ConnectionOffboardingOperation.cs• L3-41 src/…/IConnectionOffboardingProvider.cs• L5-38 src/…/ConnectionGenerationCleanup.cs• L3-22

Background reconciliation

The reconciliation worker repairs lifecycle work that is due or left incomplete after a lease expires. A scoped candidate store returns nonsecret pointers for OAuth refresh, expired operations, recovery, generation cleanup, and offboarding. The worker re-reads each item through the lifecycle recovery service rather than trusting the candidate snapshot.

The worker scans one tenant and environment scope at a time. It uses bounded pages, limited parallel work, a cursor that advances only after a whole page succeeds, and per-scope backoff after failures. A recovery-required or non-replayable unknown outcome is handled for the scan but remains visible as operator work; it does not block unrelated candidates forever.

sequenceDiagram
    participant W as Reconciliation worker
    participant Q as Due candidate store
    participant L as Lifecycle recovery service
    participant P as Provider or Secrets
    W->>Q: Read due nonsecret candidates
    Q-->>W: Bounded page and cursor
    W->>L: Dispatch candidate in tenant scope
    L->>L: Re-read and claim with revision or fence
    L->>P: Refresh, clean up, or offboard when safe
    P-->>L: Result or unknown outcome
    L-->>W: Durable result
    W->>Q: Advance cursor only after page success

The scheduler uses explicit credential kind and expiry metadata. Legacy rows without that metadata are not scheduled for automatic OAuth refresh, which prevents the worker from guessing the meaning of old credential material.

References: src/…/IConnectionDueCandidateStore.cs• L5-21 src/…/ConnectionDueCandidate.cs• L3-19 src/…/ConnectionLifecycleReconciliationWorker.cs• L21-169 src/…/ConnectionLifecycleReconciliationFeature.cs• L11-26 src/…/EFCoreConnectionLifecycleStore.cs• L14-101

Persistence architecture

The persistence layer keeps connection state, credential references, workflow mappings, use grants, cleanup tombstones, and offboarding operations in one scoped data model. The EF Core connection context owns these records and applies tenant and environment keys so workers and request paths resolve the same lifecycle state.

Protected credential values remain in the Secrets system. The connection database stores only references and lifecycle facts. Conditional updates use revisions and fences to coordinate multiple workers. This gives the lifecycle service a compare-and-swap boundary for claims, publication, recovery, cleanup, and offboarding without placing provider values in durable connection tables.

The persistence contract is split by responsibility:

RecordRole in the lifecycle
ConnectionProvider identity, status, revision, current generation pointer, and operation state
BindingTenant and environment mapping from a logical workflow reference to a connection
Use grantWorkflow-instance authorization for one binding revision; contains no secret
Generation cleanupDurable proof and lease for retiring a generation
Offboarding operationDurable remote disconnect, token revocation, or uninstall work

EF Core is one persistence adapter for these contracts. Its scoped keys and indexes support active-state checks, due-work scans, lease recovery, and exact binding or grant lookups. Other hosts can provide the same contracts with a different store, but they must preserve the same tenant, revision, fence, and no-secret boundaries.

References: src/…/ConnectionsElsaDbContext.cs• L7-24 src/…/IntegrationConnectionConfiguration.cs• L7-34 src/…/ConnectionCredentialBindingConfiguration.cs• L7-18 src/…/ConnectionCredentialUseGrantConfiguration.cs• L7-23 src/…/ConnectionGenerationCleanupConfiguration.cs• L7-21 src/…/ConnectionOffboardingOperationConfiguration.cs• L7-27 src/…/EFCoreConnectionsPersistenceFeature.cs• L11-25

Change checklist

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

  • Keep credential kind and expiry metadata aligned with due-candidate selection and the provider refresh contract.
  • Keep every generation publish, recovery, and cleanup path aligned with the managed-secret owner and generation checks.
  • Keep revision and fence checks aligned across request operations, worker reconciliation, and persistence conditional updates.
  • Keep offboarding provider idempotency claims aligned with the handling of retryable and unknown outcomes.
  • Keep binding revisions, workflow-use grants, and lifecycle status checks aligned when workflow credential access changes.
  • Keep the tenant and environment scope on connection rows, due candidates, bindings, grants, and offboarding records.

Important failure modes

TriggerConsequenceGuard
A refresh provider call starts and its result is lostThe connection can no longer safely assume that its refresh token is validRecord the provider-call boundary before the call and enter RecoveryRequired on an unknown result
A staged generation is published from a stale operationA newer connection state can be overwritten by an old workerRequire the expected revision, operation identity, fence, and staged generation to match
A binding is treated as permission to use a connectionA workflow can use a selected connection without an approved grantCheck the exact active grant and binding revision before resolution
A disconnected or recovering connection is resolvedA workflow or background task receives material that must no longer be usedRe-read lifecycle state immediately before returning the access credential
A remote offboarding call may have succeeded but the worker cannot confirm itAutomatic replay can apply a destructive provider action twicePersist UnknownOutcome and replay only when stable operation-id idempotency is guaranteed
A retired generation is deleted without a durable no-reference claimAn in-flight operation can lose the credential it still needsClaim cleanup after current and pending references are excluded, then delete through the managed owner check
Legacy credential metadata is missingThe scheduler may guess the wrong refresh behaviorExclude rows with unknown credential kind or expiry from automatic OAuth scheduling

Key files

FileWhy to read it
src/…/IntegrationConnection.csDefines the connection identity, lifecycle states, revisions, and operation metadata.
src/…/CredentialMaterial.csDefines the difference between lifecycle-held material and the write-only access credential.
src/…/DefaultConnectionLifecycleService.csShows the end-to-end rules for connect, use, refresh, recovery, disconnect, offboarding, and cleanup.
src/…/IConnectionUseAuthorizer.csDefines the authorization boundary for human and background connection use.
src/…/ConnectionLifecycleReconciliationWorker.csShows how due lifecycle work is scanned, dispatched, retried, and kept scoped.
src/…/IManagedSecretManager.csDefines the protected generation boundary between lifecycle state and secret values.
src/…/EFCoreConnectionLifecycleStore.csShows the durable revision, fence, lease, due-work, and cleanup coordination rules.
src/…/ConnectionsElsaDbContext.csShows the persistence boundary for connections, bindings, grants, cleanups, and offboarding.
src/…/WorkflowCredentialResolver.csShows how workflow resolution joins a logical binding, its grant policy, and the active lifecycle service.
docs/workflow-credential-bindings.mdExplains the child workflow domain for logical bindings and per-instance use grants.