Sub topic 4
Applying least privilege to an agent
Prerequisites and scope
This chapter assumes you can create permission sets in Setup and that you know how object permissions, field-level security, and sharing relate to each other. You should also know what an Agentforce agent, a topic, and an action are. Earlier chapters covered agent types and the agent user. This chapter covers how to decide what access that user should have. The next chapter covers how to build the permission set itself.
What least privilege means for an agent
Least privilege means giving an identity only the access it needs for its job, and nothing more. For a human employee, you can often be loose with this rule. The person has judgment, receives training, and can be held accountable. An agent has none of those protections. It follows instructions written in natural language, and a customer can try to talk it into doing something it should not do.
Instructions and topics shape what an agent tries to do. Permissions decide what it is able to do. If the agent user can delete orders, a clever prompt, a poorly written instruction, or a model mistake can lead to a deleted order. If the agent user cannot delete orders, the same failure ends with an error message. Least privilege makes permissions the layer that still holds when the other layers fail.
Three properties of agents make this more important than it is for a typical integration user:
- Input is open-ended. Customers type free text. You cannot list every request in advance.
- Behavior is probabilistic. The model chooses which topic and action to use. The same input may not produce the same choice every time.
- Access is broad by default. Admins often copy a profile or reuse an existing user to get started quickly. That user then carries far more access than the agent needs.
Start from the job, not from the profile
The most common mistake is to start from an existing user or profile and remove access until the agent stops being blocked. This approach leaves you with whatever the starting point included. Build up instead, starting from zero access.
Use this process:
- List the agent's topics. Each topic describes a job, such as "Order status."
- List the actions in each topic. Each action reads or changes something.
- For each action, identify the objects and fields it touches and whether it reads, creates, edits, or deletes.
- Write down the minimum permission for each object and field.
- Grant only that list, and test whether the agent can do its job.
The result is a short table that you can review with a security owner before you build anything.
| Topic | Action | Object | Fields | Operation needed |
|---|---|---|---|---|
| Order status | Get Order Status | Order | OrderNumber, Status | Read |
| Order status | Look up customer | Contact | Name | Read |
| Case intake | Create Case | Case | Subject, Description | Create |
Notice what the table leaves out. It has no delete, no edit, no "view all," and no fields that no action uses. If a row has no matching action, it does not belong in the permission set.
The permission dimensions to minimize
Salesforce access has several dimensions. Least privilege applies to each one separately.
Object permissions
Object permissions are Read, Create, Edit, and Delete. Give Read only when the agent only looks things up. Add Create or Edit only for an action that writes. Almost no customer-facing agent needs Delete.
Broad object permissions
View All Records and Modify All Records on an object bypass sharing for that object. View All Data and Modify All Data do the same across every object. Treat these as excluded by default for an agent user. If you grant View All Records, the agent can read every order in the org, including those belonging to other customers. This is the setting that most directly causes cross-customer data exposure.
Field permissions
Object Read does not give access to every field. Field-level security controls each field separately. Grant Read on the fields an action returns or uses in a filter. Leave out sensitive fields such as tax identifiers, internal notes, or credit limits unless an action needs them.
System permissions
System permissions such as "Export Reports," "Manage Users," "Author Apex," and "API Enabled" are easy to carry over from a copied profile. An agent user rarely needs any of them. Check the system permissions list of the profile you assign and remove anything you cannot tie to an action.
Record access
Even with the right object and field permissions, the agent user sees only the records that sharing allows. Organization-wide defaults, role hierarchy, sharing rules, and manual shares all apply. A later chapter covers sharing in detail. For this chapter, remember that a restrictive default such as Private on Order protects you only if you do not also grant View All Records.
Use a dedicated profile and additive permission sets
Assign the agent user a profile with the smallest baseline available, and layer permission sets on top. Permission sets can only add access. A minimal profile gives you a floor, and each permission set adds one capability.
A practical pattern is to create one permission set per capability, not one for the whole agent:
Agent Order Readfor reading orders.Agent Case Createfor creating cases.
This design has three benefits. You can review each set on its own. You can reuse a set across agents that share a capability. And you can remove a capability by unassigning one set, without editing a large one.
Here is a minimal permission set for reading orders. It grants Read on Order and on one field, and nothing else.
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<label>Agent Order Read</label>
<description>Read-only access to orders for the service agent user</description>
<hasActivationRequired>false</hasActivationRequired>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Order</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Order.Status</field>
<readable>true</readable>
</fieldPermissions>
</PermissionSet>Each flag is set to false unless the agent needs it. Explicit false values make the intent visible in a code review. A reviewer can see that Delete and View All were considered and refused, and not simply forgotten.
Match permissions to the agent's run-as context
Least privilege looks different depending on who the agent runs as.
- Agent that runs as a dedicated agent user. All customers share one identity. The permission set must cover the union of everything any customer interaction needs, so it is more important to keep that union small. Sharing cannot separate one customer from another, because the agent user is the same for everyone. Your actions must filter by the customer, for example by matching the order to the verified contact.
- Agent that runs as the logged-in user. The agent inherits that person's access. You cannot narrow it by editing an agent user, because there is none. Your control is the access of the people who use the agent, plus topics and actions. If employees have broad access, the agent has broad access when they use it.
In both cases, ask the same question: what is the most this identity could do if the agent behaved badly?
The first check depends on the model's judgment and can fail. The second and third checks are enforced by the platform. Least privilege strengthens the checks that cannot be argued with.
Edge cases and common errors
Reusing an existing integration or admin user
Reusing a user saves a few minutes and carries its entire access history with it. That user may hold permission sets added years ago for unrelated work. Create a new user for each agent, so its access is easy to audit.
Granting access "just in case"
A permission added for a future feature stays in place long after the plan changes. Grant access when an action needs it and not before. Adding a permission later takes minutes. Cleaning up after exposed data takes much longer.
Forgetting field-level security on new fields
When admins create a field, they may grant visibility to several profiles and permission sets. If your agent user's profile is among them, the agent can read the new field right away. Review field visibility when a field is created on an object the agent reads. Prefer permission sets that list fields explicitly over profile-level grants that expand on their own.
Assuming instructions replace permissions
An instruction like "Never share other customers' data" is useful, but it is not a control. If the agent user has View All Records on Order, the instruction is the only thing between a customer and other customers' orders. Enforce the rule with permissions and sharing, then repeat it in instructions as a second layer.
Granting write access to make an action "work"
If an action fails with an insufficient access error, the fix is not always to add permissions. First check whether the action is querying more than it needs, such as selecting extra fields. Remove the unneeded field before you widen access.
Over-restricting until the agent fails silently
Too little access also causes problems. A query run in user mode returns no rows when the user cannot see them. An agent may then say "I couldn't find that order," which looks like a data problem and hides a permission problem. When testing, check the failure case in both directions. Confirm that the agent works for allowed requests and that it stops for disallowed ones.
A review checklist
Before you activate an agent, check the following for the agent user:
- The profile is minimal, and the user was created for this agent only.
- Every permission set maps to a named capability.
- No View All Records, Modify All Records, View All Data, or Modify All Data.
- No Delete on any object unless a documented action requires it.
- Field permissions list only fields that actions use.
- System permissions are limited to what actions need.
- Organization-wide defaults for the objects involved are restrictive.
- Someone other than the builder has reviewed the list.
Exercise
An agent has one action, "Get Order Status," which queries Order and returns Status. The admin cloned a Service Cloud user to create the agent user. The clone has Read, Edit, and Delete on Order and View All Records on Order. List what you would change and explain why the instruction "Never share information about other customers" does not make the existing setup safe.
Show answer
Remove Edit and Delete on Order, because the action only reads. Remove View All Records, because it bypasses sharing and lets the agent read every customer's orders. Better still, replace the cloned user with a new user on a minimal profile, and assign a permission set such as Agent Order Read that grants Read on Order and Read on Order.Status only. Review the system permissions the clone carried over and remove any that are not needed. The instruction is not safe on its own because it relies on the model's judgment. With View All Records, a wrong action choice, a prompt injection, or a model error can return other customers' data, and nothing in the platform would stop it. Permissions and sharing are enforced by the platform, so they must carry the rule, with the instruction as a second layer.
Exercise
Why is it better to create one permission set per capability, such as "Agent Order Read" and "Agent Case Create," than to create one large permission set for the whole agent?
Show answer
Each small set can be reviewed on its own, reused by other agents that need the same capability, and removed by unassigning a single set. A single large set mixes unrelated access, makes reviews harder, and tends to grow over time without anyone noticing which parts are still needed.