Back to insights

Integration Security & Identity Architecture

A Named Credential is a trust boundary—not a URL shortcut

JSBC Labs8 min read

The callout line hides a security decision

Changing an Apex endpoint from a literal URL to callout:Payments_API is good engineering, but it does not finish the architecture. Someone has still decided which remote identity Salesforce presents, which users may invoke it, what that identity can do, how credentials reach each environment and what happens when authentication fails. If those decisions are implicit, the Named Credential has made the code cleaner while leaving the trust model undefined.

The JSBC Labs position is that a Named Credential should be reviewed as a trust boundary. Salesforce describes the modern model as a named endpoint linked to an External Credential that holds the authentication protocol and principals, with encrypted tokens stored as User External Credentials. That separation is valuable because endpoint, authentication and authorization can evolve independently. It also means architects must design all three, not stop when the callout compiles.

Separate destination, authentication and authority

Use the Named Credential to identify the destination and transport, and the External Credential to define how Salesforce authenticates. One External Credential can support more than one Named Credential, so related endpoints can reuse an authentication policy without duplicating secrets. This is especially useful when the same remote platform exposes distinct APIs, regions or service paths that share a controlled identity.

Reuse is not automatically safer. Two endpoints should share an External Credential only when their risk, ownership, lifecycle and required remote permissions genuinely align. A credential that can read customer files should not be reused for an unrelated endpoint merely because both happen to use the same vendor. Draw the relationship explicitly: Salesforce workload, Named Credential, External Credential principal, remote identity, permitted remote resources and accountable owner.

Choose whose identity crosses the boundary

A named principal lets Salesforce users share one remote service identity. It simplifies central administration and is often appropriate for system-to-system processing, but the remote platform may see every operation as the same actor. A per-user principal preserves individual identity and remote entitlements, improving attribution and user-level control, but each user may need to authenticate and integrations must handle users whose tokens are absent, revoked or expired.

Choose from the business accountability model, not developer convenience. If a scheduled process performs an organisation-owned obligation, a narrowly scoped service identity may be honest. If a user retrieves a document they personally have permission to see, a shared super-user identity can silently bypass the remote system's access model. Document execution contexts too: synchronous UI, Flow, Queueable, Batch and scheduled automation may run under different Salesforce users even when they invoke the same Apex.

Permission to run Apex is not permission to use the credential

Modern External Credential principals map to Salesforce permission sets, profiles or permission set groups. At runtime, Salesforce checks whether the calling user is entitled to use that principal. This creates a distinct authorization layer: a user can have access to an Apex class or Flow while still being denied the remote identity. Use that boundary deliberately instead of assigning credential access to a broad administrator-style persona.

Create capability-based permission sets such as Use_Payments_Read or Submit_Carrier_Shipment and grant only the principal required for that capability. Then align the remote account's scopes and roles with the same narrow purpose. Salesforce authorization controls who may present the credential; the remote system controls what the presented identity may do. Least privilege fails if either side grants more authority than the business action needs.

Treat credential population as a deployment step

Named and External Credentials contain deployable metadata, but sensitive tokens, client secrets and certificates are not simply transported as readable package content. Salesforce's packaging guidance requires environment-specific credential material to be populated after installation, and signing certificates may need to be created and associated in the target org. A metadata deployment can therefore succeed while the integration remains unusable.

Put credential provisioning in the release runbook. Name the remote application registration, callback URLs, scopes, certificate owner, secret source, target principal and verification call for every environment. Never copy a production credential into a sandbox to make testing convenient. Use separate remote identities and endpoints so non-production failures, data access and audit activity remain contained. The release gate is a successful least-privilege handshake, not the presence of a metadata component.

Design rotation before the first expiry

OAuth reduces the need to handle passwords in Apex, and Salesforce can manage token exchange and refresh for supported configurations. That does not eliminate lifecycle work. Consent can be revoked, refresh tokens can expire, client secrets and signing certificates can rotate, remote scopes can change, and an identity can be disabled. The first time the team discovers the credential owner should not be during a production incident.

Record ownership, expiry signals, rotation lead time, emergency revocation and the re-authentication path. Salesforce provides APIs for credential management and token refresh or deletion, but automation should not conceal governance: rotate through an approved process, verify the intended principal, and retain evidence without exposing secrets. Prefer overlapping validity where the remote platform supports it so a new certificate or secret can be proven before the old one is withdrawn.

Make authentication failure an operational state

Do not flatten every 401, 403, timeout and remote 500 into Callout failed. A 401 can indicate expired or invalid authentication; a 403 can indicate that authentication succeeded but the principal lacks authority. Retry policies differ: repeating a forbidden request wastes capacity, while a transient dependency failure may merit bounded retry. Return structured categories to the orchestration layer and keep user-safe messages separate from diagnostic evidence.

Monitor by Named Credential, business operation and outcome. Alert on sustained authentication failure, rising forbidden responses, unexpected principals and certificate or secret expiry. Include correlation IDs without logging authorization headers or token values. Define who owns Salesforce configuration, the remote application and the business process, because a credential incident crosses all three. A dashboard without a named responder only makes failure easier to observe, not faster to restore.

Test the trust contract, not just the HTTP parser

Apex callout mocks should prove request construction, response handling, timeout behaviour and safe retry logic. They do not prove that the deployed user can access an External Credential principal, that OAuth scopes are correct, that a certificate is trusted or that the remote account is limited appropriately. Add environment verification that exercises a harmless operation with the actual configured principal and records the result as release evidence.

Test denied paths as deliberately as success: a user without principal access, a revoked token, insufficient remote scope, an unavailable identity provider and a rotated credential. Confirm that failures do not leak secrets, trigger duplicate business work or invite unsafe retries. A Named Credential is successful when the right Salesforce workload can perform the right remote action under an explainable identity—and every other workload is predictably refused.

Official references

Continue reading