Sub topic 12
MFA, API Logins, and Integrations
This chapter assumes you can create users, assign profiles and permission sets, and have already enabled MFA for interactive logins. It covers what happens when software, not a person at a browser, signs in to Salesforce.
Why API logins are different
MFA works well for people because a person can approve a prompt or type a code. A scheduled integration can't do that. Salesforce therefore treats two kinds of login separately:
- User interface logins: a person signs in through the browser or a mobile app. The MFA requirement applies here.
- API logins: a program authenticates to call the REST API, SOAP API, or another API. MFA is not applied by default.
Leaving API logins unprotected is a real gap. If an attacker has a user's username and password, a direct API login can bypass the prompt that the browser would show.
Options for protecting API access
You have three main choices.
- Require MFA for API logins. The "Multi-Factor Authentication for API Logins" permission makes a user's API logins require a verification code. Use it for people who run tools such as data loaders or scripts under their own account. It does not suit unattended integrations, because no one is there to supply a code.
- Move integrations to OAuth. Flows such as JWT bearer and client credentials authenticate with a certificate or a client secret, not a person's password. You create a connected app (or external client app), and the integration never handles a user password.
- Use a dedicated integration user. Give the integration its own user with the API Only User permission, so that account can't sign in through the browser. Limit its access with a permission set that grants only the objects and fields the integration needs.
Combine options 2 and 3 for unattended integrations. Use option 1 for people who work through the API.
Add network limits for integrations
An integration usually runs from a known server. Restrict its profile's login IP ranges to that server's addresses, so stolen credentials fail from anywhere else. Chapter material on network restrictions covers the setup. Because the integration user has no person behind it, an IP restriction is often the strongest control you can apply.
Also set the connected app's IP Relaxation and Permitted Users policies deliberately. For example, setting Permitted Users to "Admin approved users are pre-authorized" means only users you assign through a profile or permission set can use the app.
Find out what is logging in
Before you change anything, see which API clients exist. Login history records the login type and the application used.
SELECT UserId, LoginTime, LoginType, Application, SourceIp, Status
FROM LoginHistory
WHERE LoginTime = LAST_N_DAYS:30
AND LoginType != 'Application'
ORDER BY LoginTime DESC
LIMIT 200This excludes ordinary browser logins, so what remains is mostly API and OAuth activity. Look for users who appear from unexpected IP addresses, and for named people whose accounts are used by scripts. Those scripts are candidates for a dedicated integration user.
Common errors
- Reusing a person's account for an integration. When that person leaves or their password expires, the integration breaks. Use a dedicated user instead.
- Enabling MFA for API logins on an integration user. The integration can't supply a code and fails. Use OAuth for those users.
- Forgetting password expiry. An integration user whose password expires stops working. OAuth flows with certificates avoid this dependency on a password.
- Granting a broad profile. An integration user with System Administrator rights turns one leaked secret into a full compromise.
Exercise
A nightly integration uses a named employee's username and password to call the REST API from a fixed server. How would you improve its security?
Show answer
Create a dedicated integration user with the API Only User permission and a least-privilege permission set. Switch the integration to an OAuth flow such as JWT bearer through a connected app, so it no longer uses a password. Restrict the user's profile to the server's login IP range. Don't enable MFA for API logins on this user, because an unattended job can't supply a code.