Skip to content

fix(slack): Link identities on install with the installer's user token - #132061

Open
sentry-junior[bot] wants to merge 1 commit into
masterfrom
fix/slack-link-identities-user-token
Open

sentry-junior[bot] wants to merge 1 commit into
masterfrom
fix/slack-link-identities-user-token

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Human description: We attempt to fetch users for org at the time of slack app installation but that piece doesn't work today because we drop the user token doing the installation. This PR fixes that issue


After a Slack install, link_slack_user_identities matches Slack members to Sentry org members by email and creates their Identity links. It called users.list with the bot token. The bot scopes (identity_oauth_scopes) have never included users:read.email, which is only in user_scopes. Slack leaves profile.email out of users.list for tokens without that scope, so format_slack_info_by_email dropped every member and the task linked nobody. The installer is the exception, because the install pipeline links them directly. The existing tests mocked users.list responses with emails included, which is why they never caught this.

The installer's user token does have users:read.email, and Slack returns it in authed_user.access_token during OAuth. This PR uses that token for the lookup:

  • build_integration passes the user token to post_install in post_install_data. It is never written to the integration metadata.
  • post_install encrypts the token with FernetKeyStore before queueing the task, so the plaintext token never appears in task arguments or error reports. This is the same approach sync_forge_installation uses for the Jira system token.
  • The task decrypts it with a one-hour TTL and calls users.list with it. SlackSdkClient gets an optional access_token override for this.
  • In these cases the task falls back to the bot token, which is the current behavior:
    • no encryption key is configured, which is typical for self-hosted
    • the user token has expired or can't be decrypted
    • the task was queued before this change, with the old arguments

The new task arguments are optional, so tasks queued before the deploy still run.

Adding users:read.email to the bot scopes is being handled separately. Workspaces only get a new bot scope when they reinstall, so this fix is what covers new installs on older app configurations.

via @sentaur-athena.

--

View Session [Sentry]

The post-install task that links Slack members to Sentry users by email called users.list with the bot token. The bot token has no users:read.email scope, so Slack returned members without emails and the task matched no one beyond the installer.

Pass the installer's user token, which has users:read.email, to the task instead. It is Fernet-encrypted with a one-hour TTL so it stays out of task arguments and error reports, and it is never stored on the integration. Without an encryption key (self-hosted) or once the token expires, the task falls back to the bot token as before.

Co-Authored-By: Athena Moghaddam <132939361+sentaur-athena@users.noreply.github.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 20, 2026
@sentaur-athena
sentaur-athena marked this pull request as ready for review November 20, 2026 21:34
@sentaur-athena
sentaur-athena requested a review from a team as a code owner November 20, 2026 21:34
@sentaur-athena
sentaur-athena requested review from a team and leeandher November 20, 2026 21:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant