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 / security-and-multitenancy

Security and multitenancy services

Elsa's security platform controls who can use workflow services and which tenant owns each operation. It resolves tenant context, authenticates users and clients, evaluates role and permission grants, protects secret values, issues scoped tokens, and turns external provider identities into Elsa identities without giving provider claims direct authority.

Access boundaries

The access model combines a data boundary with an identity boundary. Tenant resolution selects the data context first. Authentication then identifies the caller, and authorization checks whether that identity may perform the requested action.

Tenant context

Tenant context identifies the tenant that owns an operation and its isolated data. A tenant is resolved from configured request signals or an identity claim, then checked against the known tenant set before Elsa creates the scope used by the request.

The resolver pipeline can use a route prefix, host, header, or authenticated claim. The first resolved signal has precedence. If its ID is not known, Elsa rejects the resolution instead of silently selecting another tenant. The same tenant ID can be carried into command and background-work messages so deferred work keeps the boundary selected by the originating request.

The default tenant ID and the tenant-agnostic ID (*) have platform meaning. They are not ordinary customer tenant IDs. Tenant activation and refresh also control the tenant scopes that hold tenant-specific services.

flowchart TD
    Request[Request or workflow message] --> Signals[Configured tenant signals]
    Signals --> Known{Known tenant?}
    Known -->|Yes| Scope[Create tenant scope]
    Known -->|No| NoTenant[Continue without resolved tenant]
    Scope --> Auth[Authenticate caller]
    Auth --> Permission[Evaluate permission]
    Permission --> Operation[Run workflow operation]

References: src/…/DefaultTenantResolverPipelineInvoker.cs• L17-40 src/…/TenantResolutionMiddleware.cs• L18-49 src/…/HostTenantResolver.cs• L9-29 src/…/HeaderTenantResolver.cs• L11-24 src/…/RoutePrefixTenantResolver.cs• L12-39 src/…/ClaimsTenantResolver.cs• L11-23 src/…/TenantPropagatingMiddleware.cs• L12-27 src/…/Tenant.cs• L11-36 src/…/DefaultTenantService.cs• L56-99

Identity and authorization

Identity proves who is calling Elsa. Local users and clients can use JWT bearer tokens or API keys. A local login returns an Elsa access token and refresh token. The access token carries the stable user ID, tenant when present, roles, and permission claims. Authentication alone does not allow a protected operation.

Authorization uses a permission catalog. A permission names a resource and an action, while a role groups permissions for assignment to users. Role IDs are unique across the whole store, while role names are unique within a tenant. New roles receive a generated ID unless a caller supplies one that is not already used. Tenant-agnostic roles are visible across tenants but are not treated as tenant-owned roles when a tenant creates or changes a role.

Protected endpoints require the permission for their resource and action. Wildcard permissions can cover a resource tree, so role creation and change use the same evaluator to prevent a caller from granting more access than the caller holds. The server validates requested grants against the permission catalog before it applies this anti-escalation check.

The catalog is also the contract for role-management clients. The catalog endpoint supplies valid resources and actions, the reach endpoint shows what a wildcard covers now, and the caller-permissions endpoint supports interface state only. The server rechecks every protected operation. Malformed or no-longer-resolvable stored grants do not authorize.

Role changes can affect existing tokens. An optional permission stamp records the effective role grants at token issue time and checks them again with a tenant-scoped cache. This gives deployments a shorter revocation bound than the access-token lifetime without treating a missing stamp on an older token as a failure.

Elsa groups refresh tokens into sign-in sessions. A refresh carries the session ID forward, so logout can revoke the session and all refresh tokens issued from it. The revocation check runs before refresh, while the access tokens already issued remain valid until their short lifetime ends. Refresh resolves the user by the stable subject ID and restores the token's tenant context before it looks up the user. A session revocation is tenant-agnostic because it must be checked before tenant resolution, so session IDs are unique across tenants.

API keys can represent an application whose roles supply permissions, or an explicitly configured admin key used for bootstrap and break-glass access. The admin provider is disabled unless a key is configured. It replaces application API-key validation while enabled, so it should be removed after initial administration is complete.

The in-memory identity stores apply the same tenant boundary as durable identity storage. User and application writes inherit the current tenant when needed. User, application, and role reads stay within the ambient tenant, and identity names and client IDs remain unique within that tenant. This prevents an in-memory deployment from becoming a shared identity store across tenants.

Initial access uses an explicit seeded administrator or an administrator API key. The default administrator initializer runs when each tenant is activated. It resolves or creates a tenant-owned admin role, uses that role's generated ID when it creates the user, and adds missing configured permissions without changing existing ones. It skips tenant-agnostic roles so tenant bootstrap cannot widen a role shared by every tenant. A localhost request is not the normal bootstrap path because network position is not a reliable identity boundary in a deployed system. Elsa reports an empty identity store with neither bootstrap option at startup instead of granting anonymous management access.

References: src/…/DefaultAuthenticationFeature.cs• L16-24 src/…/IdentityFeature.cs• L166-250 src/…/DefaultElsaTokenService.cs• L18-108 src/…/DefaultAccessTokenIssuer.cs• L40-63 src/…/DefaultIdentityRefreshTokenService.cs• L22-57 src/…/IdentityTokenOptions.cs• L55-130 src/…/Endpoint.cs• L28-59 src/…/Endpoint.cs• L12-75 src/…/SessionRevoker.cs• L16-92 src/…/MemoryRevokedSessionStore.cs• L7-40 src/…/RefreshTokenSubject.cs• L6-40 src/…/RoleAuthorizationService.cs• L13-66 src/…/IRoleManager.cs• L9-25 src/…/RoleManager.cs• L10-106 src/…/Endpoint.cs• L16-69 src/…/RoleStoreExtensions.cs• L12-80 src/…/RoleFilter.cs• L9-68 src/…/AdminUserInitializer.cs• L12-122 src/…/MemoryApplicationStore.cs• L18-40 src/…/MemoryIdentityUniqueness.cs• L10-34 src/…/MemoryRoleStore.cs• L68-129 src/…/MemoryUserStore.cs• L18-82 src/…/Endpoint.cs• L9-33 src/…/Endpoint.cs• L10-51 src/…/Endpoint.cs• L8-37 src/…/PermissionStampCalculator.cs• L10-48 src/…/PermissionStampValidator.cs• L12-57 src/…/IdentityBootstrapDiagnostic.cs• L11-67 src/…/AdminApiKeyProvider.cs• L10-55 src/…/DefaultApiKeyProvider.cs• L9-55 src/…/README.md• L3-17 src/…/README.md• L93-116

Secret protection

The Secrets service lets workflows and platform services refer to sensitive values by name. It keeps secret payloads out of workflow definitions and management responses while allowing an authorized consumer to resolve the current value only when needed.

Secret lifecycle

A secret has a name, type, store, scope, status, and versions. The manager validates that the selected type and store can work together, writes a first version, and exposes lifecycle actions for update, rotation, revocation, deletion, and testing. Rotation retires the prior active version. Revocation makes the secret unavailable.

The resolver accepts an optional type and scope requirement. It checks those requirements before it reads the active version from the selected store. The built-in encrypted store protects the value and keeps the payload separate from the metadata. Workflow expressions hold a secret reference and resolve it at run time, so a workflow does not copy the value into its definition.

Secret records are protected by permission checks. Viewing metadata and changing or testing a secret are separate authorization actions. A missing, expired, revoked, incompatible, or unreadable active version fails the dependent operation rather than returning an old or unverified value.

The default file and in-memory repositories apply the same tenant rules as the durable store. They show only secrets visible to the current tenant, assign tenant ownership on writes, and preserve ownership when a secret is replaced. The same name can therefore exist in separate tenants without allowing one tenant to read or replace another tenant's secret.

References: src/…/Secret.cs• L5-37 src/…/ISecretManager.cs• L3-17 src/…/ISecretResolver.cs• L3-7 src/…/DefaultSecretManager.cs• L62-114 src/…/DefaultSecretManager.cs• L148-220 src/…/DefaultSecretResolver.cs• L7-21 src/…/EncryptedSecretStore.cs• L3-50 src/…/SecretExpressionHandler.cs• L10-23 src/…/SecretsResourcePermissions.cs• L11-25 src/…/Endpoint.cs• L8-31 src/…/ServiceCollectionExtensions.cs• L15-34 src/…/FileSecretRepository.cs• L12-89 src/…/InMemorySecretRepository.cs• L9-88 src/…/SecretRepositoryTenant.cs• L6-37 src/…/Elsa.Secrets.csproj• L15-19

SAS tokens

A shared access signature (SAS) token is a protected carrier for a small workflow payload. Elsa uses time-limited or non-expiring SAS tokens for public event links and bookmark resume links when a caller needs a narrow link instead of a normal user session.

SAS protection is separate from Elsa identity tokens. A SAS token proves that its payload can be unprotected with the configured data-protection keys. It does not supply the roles or permissions in an Elsa access token. A producer and consumer that run on different nodes must use compatible durable protection keys.

References: src/…/ITokenService.cs• L3-31 src/…/DataProtectorTokenService.cs• L10-45 src/…/DataProtectorTokenService.cs• L48-100 src/…/Endpoint.cs• L14-36 src/…/Endpoint.cs• L17-34

External authentication

External authentication is an optional broker for sign-in through deployment-installed identity-provider adapters. It keeps provider-specific trust at the edge, maps the provider result to a tenant-bound Elsa identity, resolves permission grants, and issues Elsa credentials that downstream workflow services already understand.

Brokered sign-in

The broker supports local and external login methods through a common authorization-code flow. It validates the client and redirect URI, binds the transaction to a tenant and provider connection, and uses PKCE (Proof Key for Code Exchange) before it returns an Elsa token. The completion code is short-lived and consumed once.

For an external login, the broker starts the provider flow, validates the callback against the saved connection state, resolves or provisions the Elsa user, resolves the allowed grants, and creates an external session. Refresh uses a rotating refresh credential. Logout revokes the session and can continue through the provider when upstream logout is enabled.

The broker rechecks connection state and secret generations during callback, token exchange, and refresh. A disabled, archived, shadowed, changed, or stale connection stops the flow. Elsa remains the issuer of the final access token and the authority for its permission claims.

sequenceDiagram
    participant Client
    participant Broker
    participant Provider as External provider
    participant Elsa as Elsa identity and permission services
    Client->>Broker: Start tenant-bound login with PKCE
    Broker->>Provider: Begin authorization
    Provider-->>Broker: Callback with provider result
    Broker->>Elsa: Resolve or provision identity
    Broker->>Elsa: Resolve bounded role and claim grants
    Elsa-->>Broker: Elsa user and effective grants
    Broker-->>Client: One-time code
    Client->>Broker: Exchange code and verifier
    Broker-->>Client: Elsa access and refresh tokens

See External authentication for the broker flow, connection management, identity linking, and provider rules.

References: src/…/ExternalAuthenticationContracts.cs• L9-36 src/…/ExternalAuthenticationBroker.cs• L68-163 src/…/ExternalAuthenticationBroker.cs• L165-268 src/…/ExternalAuthenticationBroker.cs• L306-398 src/…/DefaultExternalAuthenticationTokenIssuer.cs• L26-89

Identity linking and permission grants

An external identity is the provider and subject pair returned by a trusted connection. Elsa can link that identity to an existing tenant user or provision a user when an explicit unlinked-identity policy allows it. An unknown identity is rejected by default; matching and creation rules are controlled policy choices rather than automatic trust in provider claims.

Permission grants from external authentication have named sources. A source can use the user's Elsa roles or explicit claim mappings. The resolver validates each grant against the permission catalog and an optional deployment allow and deny boundary. Deny rules win, and an administrator who configures a mapping must hold the required delegation permission unless the unrestricted delegation action is granted.

Identity-link administration is tenant-bound. Prelink, replace, and unlink operations check the target user and connection in the same tenant, and link changes publish redacted security events after the state change.

References: src/…/ExternalAuthenticationResourcePermissions.cs• L11-29 src/…/ClaimMappingPermissionGrantSource.cs• L6-23 src/…/ElsaRolePermissionGrantSource.cs• L8-30 src/…/DefaultPermissionGrantResolver.cs• L19-64 src/…/DefaultPermissionGrantResolver.cs• L90-145 src/…/ExternalIdentityLinkManagementService.cs• L25-173 src/…/ExternalAuthenticationSecurityNotifier.cs• L7-30

External secret bindings

External provider connections use secret bindings instead of storing secret values in connection definitions. A binding can read a deployment-owned configuration value or an active Elsa secret. Management views expose binding state without exposing the value.

Each resolved binding returns a generation fingerprint. The broker stores a fingerprint with the sign-in transaction and session, so replacing or rotating a provider secret invalidates callbacks and refresh operations that depend on the old trust material. Secret values are treated as short-lived sensitive data during the provider call.

See Secrets, tenants, and identity for the core service relationships.

References: src/…/ExternalAuthenticationContracts.cs• L90-111 src/…/ConfigurationSecretBindingResolver.cs• L7-31 src/…/ExternalAuthenticationBroker.cs• L558-583 src/…/DefaultExternalAuthenticationTokenIssuer.cs• L94-106 src/…/README.md• L58-103

Service relationships

These services form one access path rather than independent security features. Tenant context limits the data boundary, identity supplies the caller, authorization decides the operation, and secret or SAS services provide narrowly scoped protected values for workflows and platform links.

Protected workflow operation

When Elsa processes a workflow request, it applies the access boundaries in sequence. External sign-in enters this path by converting a provider result into an Elsa user and token; it does not replace the normal authorization check.

sequenceDiagram
    participant Caller
    participant Tenants as Tenant services
    participant Identity
    participant Authorization
    participant Workflow
    participant Secrets
    Caller->>Tenants: Request or queued workflow command
    Tenants-->>Workflow: Tenant scope
    Caller->>Identity: JWT or API key
    Identity-->>Authorization: User, roles, and grants
    Authorization-->>Workflow: Allow or reject
    Workflow->>Secrets: Resolve named secret when needed
    Secrets-->>Workflow: Current protected value
    Workflow-->>Caller: Operation result or protected link

No single tenant identifier, external claim, secret name, SAS payload, or authentication result is a complete authorization decision. The workflow services use the tenant scope and permission context produced by the combined checks.

See Secrets, tenants, and identity for the core tenant, identity, and secret service relationships. See External authentication for the provider-facing sign-in boundary.

References: src/…/TenantResolutionMiddleware.cs• L18-48 src/…/DefaultElsaTokenService.cs• L46-74 src/…/DefaultAuthenticationFeature.cs• L96-121 src/…/SecretExpressionHandler.cs• L13-23 src/…/ExternalAuthenticationBroker.cs• L203-240 src/…/BackgroundWorkflowDispatcher.cs• L65-75

Change checklist

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

  • Keep tenant resolver order and tenant claim normalization aligned. A new request signal can override an identity-derived tenant if its precedence is not explicit.
  • Keep HTTP tenant scope creation and command tenant propagation aligned. Deferred work must use the tenant selected by the originating operation.
  • Keep permission descriptors, endpoint requirements, role delegation checks, and external grant validation on the same resource-and-action vocabulary.
  • Keep role IDs globally unique while keeping role names unique within the ambient tenant. Role lookup by name must prefer the tenant-owned role over a tenant-agnostic role.
  • Keep role creation validation, anti-escalation checks, store uniqueness rules, and security events aligned. A role can otherwise be saved with grants the caller cannot delegate or can produce a misleading audit record.
  • Keep tenant activation and admin bootstrap aligned. The initializer must resolve the current tenant's role, skip tenant-agnostic roles, and assign the generated role ID to the tenant's admin user.
  • Keep role changes aligned with token permission data and the optional permission-stamp cache. A token can otherwise keep an old grant until its normal expiry or cache bound.
  • Keep refresh-token subject extraction aligned with token claim mapping. Conflicting or missing stable user IDs must fail closed rather than select a user by name.
  • Keep session claims, refresh-token validation, session revocation, logout ownership checks, and refresh-token continuation aligned. A refresh that drops the session ID can escape a later logout.
  • Keep revoked-session storage shared and durable across nodes when logout must work across restarts or instances. The default memory store loses revocations on restart and does not share them between nodes.
  • Keep bootstrap behavior aligned with the permission-based identity endpoints. Removing the seeded admin or configured admin key can leave an empty instance with no way to create the first user.
  • Keep secret status, active-version selection, type or scope checks, and store capabilities aligned. Metadata that looks valid must still resolve at run time.
  • Keep in-memory identity and secret stores aligned with durable tenant visibility, tenant ownership on writes, and per-tenant uniqueness. A provider switch must not change the access boundary.
  • Keep the Secrets service registration and tenant-service dependency aligned. The default repository path must receive the tenant context when multitenancy is enabled.
  • Keep connection revisions and secret generation fingerprints aligned across external login initiation, callback, token exchange, refresh, and logout.
  • Keep external permission grant sources bounded by the deployment allow and deny rules. A role grant and a mapped claim must not bypass the same boundary.
  • Keep SAS data-protection keys shared by every node that creates or consumes a public event or bookmark link.

Important failure modes

TriggerConsequenceGuard
A resolver selects a tenant ID that is not in the tenant storeThe request has no usable tenant scopeResolve only known tenants and review resolver warnings
A queued command omits its tenant contextBackground work can run outside the originating tenant boundaryPropagate the current tenant ID when dispatching the command
A caller has a valid token but lacks the required permissionThe workflow operation is rejectedGrant the action through an approved role or external grant source
A role contains a malformed or obsolete permissionThat grant authorizes nothingRe-author the role against the current permission catalog
A requested role name already exists in the tenantRole creation returns a conflict instead of creating a second ambiguous roleUse a distinct name within the tenant
A supplied role ID already exists anywhere in the shared storeRole creation returns a conflictLet Elsa generate the ID or supply a globally unused ID
A role lookup treats a tenant-agnostic role as the tenant's own roleA tenant can change or bootstrap against a role shared by all tenantsPrefer the tenant-owned role and exclude tenant-agnostic roles for tenant-owned changes
A role or mapped external grant exceeds the actor or deployment boundaryRole creation, mapping, or token issuance is rejected or the grant is droppedUse evaluator-based containment and explicit allow or deny rules
Permission grants change while an old token remains validThe old token can retain its prior grants until expiry or the stamp cache boundEnable permission stamps when tighter revocation is required
A refresh token has no single stable subject IDRefresh fails instead of risking lookup of the wrong userIssue and validate one consistent user ID claim
A refresh continues without its prior session IDLogout of the session leaves the new refresh token usablePreserve the session ID and session expiry on every refresh
A revoked-session store is memory-only in a multi-node or restart-prone deploymentA logged-out session can become usable again after restart or on another nodeUse a shared durable revoked-session store
Logout receives a token owned by another user or tenantThe session is not revokedRequire refresh-token ownership before revocation
No administrator bootstrap exists in an empty user storeManagement endpoints return 403 and no user can start administrationSeed the default administrator or configure an admin API key
An in-memory identity or secret store lacks the ambient tenant contextData can use default tenant behavior instead of the intended tenant boundaryRegister and invoke the store through the tenant-aware service path
The active secret is expired, revoked, incompatible, or unreadableA workflow or provider sign-in that needs it failsTest and rotate the secret before expiry
A provider connection or bound secret changes during sign-in or refreshThe old flow or session is rejected as staleRestart the flow with the current connection and secret material
An external identity has no accepted link or creation policyProvider authentication succeeds but Elsa sign-in stopsLink the identity or configure a narrow unlinked-identity policy
SAS protection keys differ between producer and consumerPublic event or bookmark links cannot be openedUse durable shared data-protection keys across participating nodes

Key files

FileWhy to read it
src/…/DefaultTenantResolverPipelineInvoker.csShows how request signals become a known tenant or no tenant.
src/…/TenantResolutionMiddleware.csShows where tenant resolution becomes the HTTP operation scope.
src/…/DefaultTenantService.csShows tenant activation, refresh, and lifecycle scope ownership.
src/…/DefaultAuthenticationFeature.csShows the JWT and API-key authentication boundary.
src/…/DefaultElsaTokenService.csShows the identity, tenant, role, permission, and session data carried by Elsa tokens.
src/…/DefaultIdentityRefreshTokenService.csShows refresh-token validation and restoration of the token's tenant context.
src/…/Endpoint.csShows ownership checks for session logout.
src/…/SessionRevoker.csShows how a session revocation covers the refresh-token chain.
src/…/MemoryRevokedSessionStore.csShows the default process-local behavior for revoked sessions.
src/…/RefreshTokenSubject.csShows the fail-closed stable-user lookup used during refresh.
src/…/IRoleManager.csDefines the role creation contract and the distinction between globally unique IDs and tenant-scoped names.
src/…/RoleManager.csShows the tenant-scoped role name check and generated role ID behavior.
src/…/Endpoint.csShows catalog validation, anti-escalation checks, conflict handling, and role-change notification.
src/…/RoleStoreExtensions.csShows how role names are resolved across tenant-owned and tenant-agnostic roles.
src/…/RoleFilter.csShows the tenant visibility rules applied to role queries.
src/…/AdminUserInitializer.csShows per-tenant admin role and user bootstrap.
src/…/RoleAuthorizationService.csShows the anti-escalation rule for assigning and changing role permissions.
src/…/PermissionStampValidator.csShows the optional tenant-scoped check for changed effective grants.
src/…/MemoryApplicationStore.csShows tenant visibility and per-tenant uniqueness for in-memory applications.
src/…/MemoryUserStore.csShows tenant stamping and visibility for in-memory users.
src/…/MemoryRoleStore.csShows tenant filtering and safe replacement for in-memory roles.
src/…/MemoryIdentityUniqueness.csShows the shared per-tenant uniqueness rule for in-memory identities.
src/…/IdentityBootstrapDiagnostic.csShows how an empty identity store reports missing initial access.
src/…/AdminApiKeyProvider.csShows the explicit admin API-key bootstrap boundary.
src/…/DefaultApiKeyProvider.csShows how application roles become API-key permissions.
src/…/README.mdShows signing-key, bootstrap, role initialization, and API-key operating rules.
src/…/DefaultSecretManager.csShows the secret version, rotation, revocation, and resolution boundary.
src/…/SecretExpressionHandler.csShows how workflows resolve a named secret at run time.
src/…/SecretRepositoryTenant.csShows the shared tenant visibility, ownership, and name rules for secret repositories.
src/…/FileSecretRepository.csShows tenant-aware persistence for the default file repository.
src/…/InMemorySecretRepository.csShows tenant-aware behavior for the in-memory repository.
src/…/ServiceCollectionExtensions.csShows the default secret services and their tenant-aware registrations.
src/…/DataProtectorTokenService.csShows the protected and time-limited link-token contract.
src/…/ExternalAuthenticationBroker.csShows the tenant-bound external sign-in and token-exchange boundary.
src/…/DefaultPermissionGrantResolver.csShows how role and claim grants are cataloged and bounded before issuance.
src/…/DefaultExternalAuthenticationTokenIssuer.csShows external session refresh and reapplication of the deployment grant boundary.
src/…/ExternalIdentityLinkManagementService.csShows tenant-safe identity link administration.
src/…/ExternalAuthenticationResourcePermissions.csShows the authorization resources for provider connections, links, sessions, policies, and grants.