Sub topic 2
Least Privilege Applied to Salesforce Access
This chapter assumes you know basic Salesforce administration (users, profiles, objects, fields), the REST API and SOQL, and the basics of OAuth 2.0. You need admin rights in a sandbox or Developer Edition org to follow along.
What least privilege means here
Least privilege means a user gets the minimum access needed to do its job, and nothing more. For an integration user, "its job" is a fixed list of API calls against specific objects and fields. Unlike a human, the integration never needs to explore the UI, run reports, or edit records it does not own.
In Salesforce, access is not one switch. It is the result of several layers that each narrow or widen what the user can do.
| Layer | What it controls | Typical over-privilege |
|---|---|---|
| User license and profile | The base set of features and objects | Cloning System Administrator |
| Permission sets | Object, field, and system permissions | Delete, View All, or Modify All granted "just in case" |
| Field-level security | Which fields are readable or editable | Granting a whole object when one field is needed |
| Sharing model | Which records the user can see | Using View All Records to avoid sharing design |
| Authentication and network | How and from where the user connects | Passwords with no IP limits |
Least privilege means choosing the narrowest setting at every layer. A user is only as restricted as its widest layer.
How Salesforce enforces it
Salesforce is additive. A user's permissions are the union of the profile and every assigned permission set. Nothing in a permission set can take away access granted elsewhere (muting permission sets inside permission set groups are the exception). So the safest design starts with a profile that grants almost nothing and adds access only through permission sets.
Three rules follow from this:
- Start from zero. Use a minimal profile, then add one purpose-built permission set.
- Grant by need, not by convenience. If the integration only reads Account records, grant Read on Account and nothing else.
- Treat View All and Modify All as exceptions. These flags bypass sharing rules and apply to every record of the object. "View All Data" and "Modify All Data" do this for the entire org.
A worked example
Suppose an integration reads Account names and industries to feed a reporting tool. Its needs are:
- API access
- Read on the Account object
- Read on the
Industryfield
The following permission set grants exactly that. Note the explicit false values and the absence of View All or Modify All.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<description>Read-only access to Account for the integration user</description>
<fieldPermissions>
<editable>false</editable>
<field>Account.Industry</field>
<readable>true</readable>
</fieldPermissions>
<hasActivationRequired>false</hasActivationRequired>
<label>Integration Account Read</label>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Account</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ApiEnabled</name>
</userPermissions>
</PermissionSet>The ApiEnabled permission lets the user call the API at all. Without it, every call fails even when object access is correct.
Common mistakes
- Reusing a human admin account. Its access is broad, tied to a person, and breaks when that person leaves.
- Cloning the System Administrator profile and removing a few items. You will miss some, and the remaining access is hard to audit.
- Granting object access and forgetting field-level security. The call may succeed but return fewer fields than expected, which is a sign that least privilege is working. Check what you actually need before widening it.
- Granting View All Records to solve a missing-record problem. First check the sharing model, covered in a later chapter.
Exercise
An integration must read Contact records but never change them. A teammate proposes giving the integration user Modify All Records on Contact "so it never hits sharing errors." Name two things wrong with this plan and what to do instead.
Show answer
Modify All Records grants write and delete access to every Contact, which exceeds the read-only need. It also bypasses sharing, so the user sees records it may not be meant to see. Instead, grant only Read on Contact through a permission set, grant read-only field access to the needed fields, and fix any missing-record problem by reviewing the sharing model or the user's role rather than widening object permissions.