Sub topic 13
Rotating Credentials and Reviewing Access
This chapter covers upkeep of the integration user after it goes live. You gave the user the least privilege it needed on day one, but that access drifts. Certificates expire, features get added, and permission sets pick up extra rights. A scheduled routine of rotation and review keeps the user at least privilege over time.
This chapter assumes the earlier chapters' setup. You have an integration user with a minimal profile, a permission set, and OAuth JWT bearer authentication through a connected app (or an external client app). It also assumes you can run SOQL and use the Salesforce CLI (sf), and that you have a sandbox where you can practice the rotation before you touch production.
Why access decays
Nothing about a working integration forces anyone to revisit its access. Four things tend to go wrong over time:
- Credentials age. A private key or certificate that never changes gives an attacker an unlimited window if it leaks. Certificates also expire, which causes an outage if nobody notices.
- Permissions accumulate. A developer adds a field permission during an incident and never removes it. Each change looks harmless, but the total grows past what the integration needs.
- Requirements shrink. The integration stops using an object, but the permission stays.
- People leave. Whoever created the key may no longer work at the company, and copies of the key may still exist on their machines or in old build logs.
Rotation limits how long a leaked credential is useful. Review limits how much damage a working credential can do.
What to rotate
The integration user has several secrets and settings. Each has its own lifetime.
| Item | Where it lives | Suggested cadence | Rotation effect |
|---|---|---|---|
| JWT private key and certificate | Integration server or secret store, certificate in the connected app | Before expiry, and at least yearly | Needs a coordinated cutover |
| Consumer secret | Connected app, integration config | Yearly, or after any suspected leak | Breaks flows that use it until updated |
| User password | Salesforce user record | Not used for login, but set it to a long random value and do not store it | None if nobody uses it |
| Login IP ranges | Profile or permission-set-related login settings | Review each quarter | Wrong ranges block the integration |
| Permission set assignments | User record | Review each quarter | Removing rights can break calls |
The password row surprises people. A JWT bearer user never types a password, so no one should know it. Leave it unknown and treat the key as the only way in.
Rotating the JWT key and certificate
A connected app holds one certificate for the JWT bearer flow. When you swap it, any server still signing with the old key fails immediately. Plan the cutover as a short sequence instead of a surprise.
Step 1: Generate a new pair
Create a new private key and a self-signed certificate. Keep the file names distinct from the current ones so you do not overwrite a working key.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout server-new.key \
-out server-new.crt \
-subj "/CN=integration-sandbox"
chmod 600 server-new.keyThe -days 365 value sets the certificate lifetime. A shorter lifetime forces more frequent rotation, which is the point. Choose a period your team can actually keep up with.
Step 2: Test in a sandbox first
Upload server-new.crt to the sandbox copy of the connected app. Then confirm that the new key logs in and that the user still sees only what it should.
sf org login jwt \
--client-id "$SF_CLIENT_ID" \
--jwt-key-file server-new.key \
--username [email protected] \
--instance-url https://test.salesforce.com \
--alias integration-sandbox-rotated
sf data query \
--target-org integration-sandbox-rotated \
--query "SELECT Id, Name, Industry FROM Account LIMIT 5"If the login fails with an invalid-grant or audience error, check the username, the --instance-url, and that the certificate you uploaded matches the key you used. A mismatch between certificate and key is the most common cause.
Step 3: Cut over in production
Repeat the upload in the production connected app during a quiet window, then deploy the new key to the server's secret store. Do not paste the key into a ticket, chat message, or repository. Use a secret manager or your platform's encrypted variables.
Keep the old key until the new one has been verified. If the login fails, re-upload the old certificate and restore the old key. Only after a successful login and a successful query should you destroy the old key.
Step 4: Record the dates
Write the rotation date and the certificate expiry date somewhere your team will see them, such as a calendar reminder or a ticket with a due date. Set the reminder for 30 days before expiry. An expired certificate stops all API access for the integration, and the first sign is usually a failing production job.
Rotating the consumer secret
If any part of your integration uses the consumer secret, treat it like a password. A JWT bearer flow authenticates with the signed assertion, so the secret may be unused. If so, record that fact and make sure it is not stored where it need not be. Where the secret is in use, generate a new one through the connected app's consumer details if your org's setup page offers it. Update the integration's configuration at the same moment, because the old secret stops working. Test in a sandbox first.
Reviewing access on a schedule
A review compares what the user can do now against the requirements list you wrote at the start. Run it every quarter, and also after any incident, major release, or team change.
Check assignments
List everything assigned to the user. Any permission set you do not recognize needs an explanation or a removal.
SELECT PermissionSet.Name, PermissionSet.Label, PermissionSet.IsOwnedByProfile
FROM PermissionSetAssignment
WHERE AssigneeId = '005XXXXXXXXXXXXXXX'Check object rights
For each permission set, look for rights the requirements list does not justify. Delete, View All, and Modify All deserve the most attention.
SELECT SobjectType, PermissionsRead, PermissionsCreate, PermissionsEdit, PermissionsDelete, PermissionsViewAllRecords, PermissionsModifyAllRecords
FROM ObjectPermissions
WHERE Parent.Name = 'Integration_Account_Read'Also scan for objects that should not be listed at all. An object appearing here that the integration never queries is a candidate for removal.
Check what the integration actually uses
Permissions that exist but are never used are the safest to remove. The OAuth token record shows when each connected app last issued a token to the user.
SELECT AppName, LastUsedDate, UseCount
FROM OauthToken
WHERE UserId = '005XXXXXXXXXXXXXXX'
ORDER BY LastUsedDate DESCAn app name you do not recognize means a second authorization exists for this user. Find out who created it. Revoke it from the user's OAuth connected apps list in Setup if nobody can justify it.
Check recent logins
Confirm that logins come from expected addresses and applications.
SELECT LoginTime, SourceIp, LoginType, Status, Application
FROM LoginHistory
WHERE UserId = '005XXXXXXXXXXXXXXX'
ORDER BY LoginTime DESC
LIMIT 20Look for failed attempts, unfamiliar addresses, and a login type other than the OAuth type you expect.
Check for changes made by people
The setup audit trail records configuration changes, including permission and user edits. Look for changes to your integration's objects in the last quarter and compare them against change tickets.
SELECT CreatedDate, CreatedBy.Name, Action, Section, Display
FROM SetupAuditTrail
WHERE CreatedDate = LAST_N_DAYS:90
ORDER BY CreatedDate DESC
LIMIT 200Filter the results for the words "permission set" or your integration user's name. A change with no matching ticket is a finding to follow up.
Remove what the review turns up
Apply fixes in the permission set, not on the user. For example, if the review finds that Delete was added to Account, edit the permission set to remove it, test the integration in a sandbox, then deploy the change. The metadata file from earlier chapters makes this a small, reviewable diff in version control. A review that results in a commit is easier to audit than one done by clicking in Setup.
Stale and orphaned integration users
Integrations get retired and their users remain. An active user with no recent logins is an unused entry point. Find them with a query on login date.
SELECT Id, Username, LastLoginDate, IsActive
FROM User
WHERE IsActive = true AND LastLoginDate < LAST_N_DAYS:90
ORDER BY LastLoginDateThe query also returns human users who are on leave, so check each row. For a confirmed retired integration, freeze the user first, then deactivate it later. Freezing blocks login without changing assignments, which keeps the option to undo it. The UserLogin object has an IsFrozen field for this, and you can also use the Freeze button on the user record.
Checklist for each review
- The requirements list still matches what the integration does.
- Only the expected permission sets are assigned.
- No Delete, View All, or Modify All right exists without a written reason.
- Login IP ranges match the integration's current hosts.
- The certificate expiry date is more than 30 days away, or rotation is scheduled.
- Recent logins and OAuth tokens show only known sources.
- The review date and findings are recorded.
Common mistakes
- Rotating without a rollback. Destroying the old key before verifying the new one turns a failed upload into an outage.
- Rotating only in production. Skipping the sandbox test hides certificate and username mismatches until the change window.
- Trusting the permission set name. A set called "Read Only" can still contain write rights. Query the actual permissions.
- Fixing access on the user instead of the set. Direct changes are hard to track and often lost when the user is refreshed in a sandbox.
- No owner. If nobody is named for the integration, nobody runs the review. Assign a person or team and put the cadence on their calendar.
Exercise
Your connected app's certificate expires in 20 days. Describe the order of steps to rotate it safely, and name the point at which you destroy the old key.
Show answer
Generate a new key and certificate, test them against the sandbox connected app with sf org login jwt and a query, then schedule a change window. Upload the new certificate to the production connected app, deploy the new private key to the integration server, and verify that login and a query succeed. If verification fails, re-upload the old certificate and restore the old key. Destroy the old key only after verification passes, and record the new rotation and expiry dates.
Exercise
A quarterly review finds that the integration's permission set grants Delete on Account, but the requirements list says the integration only reads Accounts. What do you do, and where do you make the change?
Show answer
Remove the Delete right in the permission set, not on the user, so every assignee and the version-controlled metadata stay consistent. Test the integration in a sandbox to confirm that reads still work, then deploy the change. Check the setup audit trail to find who added the right and why, and record the finding in the review notes.
Exercise
You find an active integration user whose last login was 120 days ago and no team claims it. What should you do first, and why?
Show answer
Freeze the user through the UserLogin record's IsFrozen field or the Freeze button. Freezing blocks login immediately and keeps all assignments, so you can reverse it if an owner appears. After a waiting period with no complaints, deactivate the user and remove its connected app authorizations.