Attempt automatic Slack channel conversion on incident visibility change - #317
Merged
Merged
Conversation
When an incident's visibility changes, Firetower always posted a message telling users a Slack admin has to convert the channel manually. It never actually tried to convert the channel. Add SlackService.convert_channel_privacy(), which uses the Slack admin API (admin.conversations.convertToPublic/convertToPrivate) to attempt the conversion. If it succeeds, post a confirmation message instead of the manual-conversion notice. If it fails (e.g. missing admin scope, which is the likely reason this was never automated), fall back to the existing manual-conversion message so behavior is unchanged for orgs without the required Slack app scope. Fixes RELENG-1052. Co-Authored-By: Richard Gibert <richard.gibert@sentry.io>
Warden flagged that toggling incident visibility called the Slack admin convert APIs on the channel ID parsed from the incident's writable Slack external link, with no ownership check. Any authenticated user who can edit a visible incident could point that link at an arbitrary workspace channel and force it public/private once the bot has admin.conversations scope. Add _is_incidents_own_channel(), which fetches the channel's real name via Slack and requires it to match the incident's canonical channel name (build_channel_name) before allowing the admin conversion call. Falls back to the existing manual-conversion message when the channel doesn't match.
rgibert
marked this pull request as ready for review
September 9, 2026 18:46
rgibert
enabled auto-merge (squash)
September 17, 2026 15:18
spalmurray
approved these changes
Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes RELENG-1052.
Problem
When an incident's visibility (private/public) changes,
on_visibility_changed(and the equivalent path inon_incident_updated) always posted a message telling users a Slack admin has to convert the channel manually. It never actually attempted to convert the channel — that's why#inc-2518had to be fixed by hand.Fix
SlackService.convert_channel_privacy(channel_id, is_private), which calls Slack's admin API (admin.conversations.convertToPublic/admin.conversations.convertToPrivate) to attempt the conversion.admin.conversations:writescope — the likely reason this was never automated, matching Richard's diagnosis in #team-sre), fall back to the existing manual-conversion message, so behavior for orgs without that admin scope is unchanged.This requires the Slack app to have
admin.conversations:write(Enterprise Grid org-installed) to actually auto-convert; without it, Firetower degrades gracefully to today's manual-fallback behavior.Testing
uv run pytest— full suite passes except one pre-existing unrelated failure (TestOnIncidentCreated::test_creates_channel_and_link, also fails onmain).uv run ruff check/ruff format --check/mypy src— all clean.SlackService.convert_channel_privacy(success, no client, API error fallback) and updatedon_visibility_changedtests to cover both the conversion-succeeds and conversion-fails paths.via Richard Gibert.
--
View Junior Session [Sentry]