Hi when setting up slack alert from elementary oss...
# ask-elementary-ai
c
Hi when setting up slack alert from elementary oss to slack. It states that when creating a slack token one should: 1. Create a Slack token Go to the “OAauth & Permissions” page for your newly-created app, and add the following scopes under “Bot Token Scopes”: •
channels:join
- Join public channels in a workspace •
channels:read
- View basic information about public channels in a workspace •
chat:write
- Send messages as <app> •
files:write
- Upload, edit, and delete files as <app> •
users:read
- View people in a workspace •
users:read.email
- View email addresses of people in a workspace •
groups:read
- View basic information about private channels that your slack app has been added to These permissions have been questioned by my Info-sec team regarding if these permissions all are necessary. Especially the users:read.email , we are a huge company, and this is very sensitive data. Why is that needed?
👀 1
k
A message from kapa.ai
New message text here
c
So what of all these permissions is actually needed then to just post alerts and report summaries? @kapa.ai
k
A message from kapa.ai
New message text here
c
I've updated my Elementary App in slack to only permit it using oauth scopes chat:write and files:write. I add the slack app manually to the channel following the links you provided. When i run the command:
Copy code
poetry run edr send-report --profiles-dir dbt/.dbt-profiles/ -t dev --env dev --days-back 1 --gcs-bucket-name <bucket_name> --slack-token <slack-token> --slack-channel-name <channel_name/channel_id>
locally i get:
Copy code
INFO:elementary.monitor.data_monitoring.report.data_monitoring_report:Sent test results summary to Slack
Traceback (most recent call last):
  File "/workspaces/dbt-analytics/.venv/bin/edr", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/elementary/cli/cli.py", line 66, in invoke
    return super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/elementary/monitor/cli.py", line 750, in send_report
    sent_report_successfully = data_monitoring.send_report(
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/elementary/monitor/data_monitoring/report/data_monitoring_report.py", line 230, in send_report
    self.send_report_attachment(local_html_path=local_html_path)
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/elementary/monitor/data_monitoring/report/data_monitoring_report.py", line 236, in send_report_attachment
    send_succeeded = self.slack_client.send_report(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/ratelimit/decorators.py", line 113, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/ratelimit/decorators.py", line 80, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/elementary/clients/slack/client.py", line 142, in send_report
    send_succeed = self.send_file(
                   ^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/ratelimit/decorators.py", line 113, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/ratelimit/decorators.py", line 80, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/elementary/clients/slack/client.py", line 125, in send_file
    channel_id = self._get_channel_id(channel_name)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/elementary/clients/slack/client.py", line 186, in _get_channel_id
    channels, cursor = self._get_channels(cursor)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/ratelimit/decorators.py", line 113, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/ratelimit/decorators.py", line 80, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/elementary/clients/slack/client.py", line 168, in _get_channels
    return self.list_conversations(cursor=cursor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/elementary/clients/slack/client.py", line 173, in list_conversations
    response = self.client.conversations_list(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/slack_sdk/web/client.py", line 3327, in conversations_list
    return self.api_call("conversations.list", http_verb="GET", params=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/slack_sdk/web/base_client.py", line 169, in api_call
    return self._sync_send(api_url=api_url, req_args=req_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/slack_sdk/web/base_client.py", line 200, in _sync_send
    return self._urllib_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/slack_sdk/web/base_client.py", line 331, in _urllib_api_call
    ).validate()
      ^^^^^^^^^^
  File "/workspaces/dbt-analytics/.venv/lib/python3.11/site-packages/slack_sdk/web/slack_response.py", line 197, in validate
    raise e.SlackApiError(message=msg, response=self)
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: <https://slack.com/api/conversations.list>)
The server responded with: {'ok': False, 'error': 'missing_scope', 'needed': 'channels:read,groups:read,mpim:read,im:read', 'provided': 'chat:write,files:write'}
@kapa.ai Can I do something to resolve this? I want to run this through my Orchestration, but I think this error may break it from successfully finishing up the workflow.
k
A message from kapa.ai
Your error is caused by missing Slack OAuth scopes. Specifically, the Elementary CLI is trying to call the
conversations.list
API, which requires the
channels:read
and
groups:read
scopes (and sometimes
mpim:read
,
im:read
for other channel types). Without these, the app cannot look up the channel ID needed to upload the report file as an attachment. Even if you manually add the app to the channel, Elementary still needs
channels:read
(for public channels) and
groups:read
(for private channels) to resolve the channel name to a channel ID
. This is confirmed in both the documentation and community discussions: - > "An app needs access to the channel info to post in it. This is why the command fails." [Slack scopes explanation](https://slack.com/archives/C02CTC89LAX/p1696335579019929) - > "If you omit
channels:read
or
groups:read
, the app will not be able to post in the respective channel types, and you may see errors about missing scopes if you try to do so." [Slack setup for Elementary CLI](https://docs.elementary-data.com/oss/deployment-and-configuration/slack) Resolution: You must add at least the following scopes to your Slack app for
edr send-report
to work: -
chat:write
-
files:write
-
channels:read
-
groups:read
If you are only posting to public channels,
channels:read
is required. For private channels,
groups:read
is also needed. The other scopes (
users:read
,
users:read.email
,
channels:join
) are optional unless you need user tagging or want the app to join channels automatically. Summary: Update your Slack app to include
channels:read
and
groups:read
in addition to
chat:write
and
files:write
. This will resolve the
missing_scope
error and allow Elementary to send reports to Slack as expected. If you need more details on why these scopes are required, see the linked explanations above.
c
The channel is public, but within a private workspace. So
channels:read
could be enough to add then you mean to resolve the issue ? @kapa.ai
k
A message from kapa.ai
Yes, if your Slack channel is public, then adding the
channels:read
scope should be sufficient for Elementary to resolve the channel and post the report or alert. The
groups:read
scope is only required for private channels. This is confirmed in the documentation and community discussions, which state that
channels:read
is needed to view and post to public channels, and
groups:read
is only necessary for private channels that the app has been added to [Slack setup for Elementary CLI](https://docs.elementary-data.com/oss/deployment-and-configuration/slack) [Slack scopes explanation](https://slack.com/archives/C02CTC89LAX/p1696335579019929). So, for your use case (public channel in a private workspace), you should add: -
chat:write
-
files:write
-
channels:read
This should resolve the
missing_scope
error you encountered. If you later need to post to private channels, you will need to add
groups:read
as well.