Sub topic 13
Rotating Credentials and Reviewing Access
An integration user is not finished once it works. Keys expire, people leave, and permissions drift. This chapter covers how to rotate the integration's credentials and how to review its access on a schedule. It assumes you have already built the user, its permission set, and its OAuth setup in earlier chapters, and that you are comfortable with SOQL and the sf CLI.
Why maintenance matters
Least privilege decays over time. Someone adds a field permission "just for a test" and never removes it. A certificate stays valid for years. The server that holds the private key gets retired, but the key file is still on a backup. Regular rotation and review limit the damage from each of these.
What to rotate
With the JWT bearer flow, the integration has no password to change. The secrets are different:
| Credential | Where it lives | How to rotate |
|---|---|---|
| Private key and certificate | Integration server or secret store, and the connected app | Create a new key pair, upload the new certificate, deploy the new key, then remove the old certificate |
| Consumer key and secret | Connected app or external client app | Regenerate the secret if it is used, and update the integration's configuration |
| Refresh tokens | Salesforce, issued per authorization | Revoke them to force re-authorization |
Rotate on a fixed schedule, and also immediately when someone with access to the key leaves the team or you suspect exposure.
Rotating the JWT certificate without downtime
A connected app can hold only one certificate at a time, so plan for a short overlap. A safe order is:
- Generate a new private key and certificate on a trusted machine.
- In a sandbox, upload the new certificate and test the login with the new key.
- Store the new private key in your secret manager. Do not commit it to source control.
- In production, upload the new certificate during a quiet window and switch the integration to the new key immediately afterward.
- Delete the old key from every location where it was stored.
openssl req -x509 -nodes -newkey rsa:2048 -days 365 \
-keyout server-new.key \
-out server-new.crt \
-subj "/CN=integration-user"After the switch, confirm that the integration still logs in. This is the same login test you used during verification.
sf org login jwt \
--client-id "$SF_CLIENT_ID" \
--jwt-key-file server-new.key \
--username [email protected] \
--instance-url https://login.salesforce.com \
--alias integration-prodIf the login fails, the old certificate is still your fallback only if you have not yet deleted it from your records. Keep it until the new login succeeds.
Revoking sessions and tokens
If you suspect a leak, rotation alone is not enough, because existing sessions remain valid until they expire. In Setup, open the integration user's record and use the OAuth connected apps usage and session views to end active sessions and revoke tokens. You can also freeze the user (Setup, Users, Freeze) to stop logins immediately without deactivating the account, which gives you time to investigate.
Reviewing access on a schedule
A review answers one question: does this user have exactly what the integration needs today? Run the same queries you used for verification and compare the results with your requirements list.
First, list every permission set assigned to the user:
SELECT PermissionSet.Name, PermissionSet.Label, PermissionSet.IsOwnedByProfile
FROM PermissionSetAssignment
WHERE AssigneeId = '005XXXXXXXXXXXXXXX'Then inspect the object permissions of each one, looking for Delete, View All, or Modify All flags that should not be there:
SELECT SobjectType, PermissionsRead, PermissionsCreate, PermissionsEdit, PermissionsDelete, PermissionsViewAllRecords, PermissionsModifyAllRecords
FROM ObjectPermissions
WHERE Parent.Name = 'Integration_Account_Read'Finally, check recent logins for unexpected IP addresses or applications:
SELECT LoginTime, SourceIp, LoginType, Status, Application
FROM LoginHistory
WHERE UserId = '005XXXXXXXXXXXXXXX'
ORDER BY LoginTime DESC
LIMIT 20A review cycle
The cycle below can run quarterly, or after any change to the integration.
Common mistakes
- Deleting the old certificate before confirming the new one works.
- Leaving a copy of the old private key in backups or a shared drive.
- Reviewing only the permission set and forgetting the profile, permission set groups, or sharing changes.
- Skipping the review because the integration "has never failed."
Exercise
A developer who had access to the integration's private key has left the company. List the steps you take, in order.
Show answer
Generate a new key pair and certificate, test the new key in a sandbox, upload the new certificate to the production connected app, and switch the integration to the new key. Revoke existing tokens and sessions for the integration user, delete the old key from all storage locations, then review login history for the period before the departure and record the findings. If you suspect misuse, freeze the user first.