LoginSignup
2
0

More than 1 year has passed since last update.

【IBM Security Verify】ユーザーの登録・変更・削除イベントをSlackに通知する。

Last updated at Posted at 2023-05-12

はじめに

IBM Security Verifyで管理者がユーザーの作成・変更・削除・パスワードリセットを行った際に、Slackに通知するという設定を行ってみました。
少し前にリリースされた通知Webhook機能を利用して設定を行っています。
機能のマニュアルについては下部の参考情報を参照ください。
qiita-webhook (17).png

1.通知Webhook設定概要

マニュアルだけだと理解が難しかったため、設定内容を整理してみました。
IBM Security Verifyの通知Webhook設定には、大きく3つの設定があります。

qiita-webhook (21).png

それぞれの設定について簡単に紹介します。

項目 管理画面のGUI上の表記 説明 設定方法 対応するAPIのBodyパラメータ
通知先の設定 接続の詳細 呼び出し先URL(SlackのIncomming WebhookのURL)を設定する。
通知先によっては認証方法や認証ヘッダーの情報も設することができる。
GUI/APIいずれでも設定可能 urls/name/type/purposeなど
通知イベントの設定 イベント・サブスクリプション IBM Security Verifyのどのイベントを通知するか設定できる。
事前定義のイベントや、カスタムで設定できる。
今回は、管理イベントを対象として設定する。
GUI/APIいずれでも設定可能 notification-interests
イベントデータ変換設定 (GUI上は表記無し) IBM Security Verifyのイベントペイロードを、Slackのmessage payloadのフォーマットに変換する。 GUIでは設定できない。
APIで設定が必要
transform-outgoing

2.SlackのIncomming Webhook設定について

①Slackにログインします。
https://slack.com/intl/ja-jp/

②Security Verifyというワークスペースと、webhookというchannelを用意します。
qiita-webhook (8).png

③Incomming webhookの設定を行います。下記URLにアクセスします。
https://api.slack.com/

④Create an appを選択します。
qiita-webhook (9).png

⑤From Scratchを選択します。
qiita-webhook (10).png

⑥AppNameとワークスペース名を設定して、「Create App」をクリックします。
qiita-webhook (11).png

⑦Incomming WebhookをONに設定します。
qiita-webhook (13).png

⑧channelを指定してAllowをクリックします。
qiita-webhook (14).png

⑨表示されたWebhookのURLをコピーします。
https://hooks.slack.com/services/xxxx/xxxx/xxxx

⑩Slackに通知できるかテストします。

curl -X POST -H "Content-type: application/json" --data "{\"text\":\"Hello, World!\"}" https://hooks.slack.com/services/xxxx/xxxx/xxxx

⑪テストメッセージが表示されることを確認します。
qiita-webhook (16).png

3.IBM Security Verifyの通知Webhook設定について

Slack側の準備ができたので、IBM Security Verify側の設定を行います。
POST /config/v1.0/webhooks/で、通知Webhookの設定を登録します。
JSONのdataは以下の通りです。

{
    "name": "user_management_webhook",
    "type": "notification",
    "transform": {
        "outgoing": "statements:\r\n- context: \"isEventType1 := (body.data.resource == 'user')&&(body.data.action == 'created')\"\r\n- context: \"isEventType2 := (body.data.resource == 'user')&&(body.data.action == 'modified')\"\r\n- context: \"isEventType3 := (body.data.resource == 'user')&&(body.data.action == 'deleted')\"\r\n- context: \"isEventType4 := (body.data.resource == 'user')&&(body.data.action == 'reset password')\"\r\n- if:\r\n    match: context.isEventType1 \r\n    block:\r\n      - context: \"d := body['data']\"\r\n      - return: \"{'body': {'text': '<!channel> :new: ユーザーが作成されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }\"\r\n- if:\r\n    match: context.isEventType2 \r\n    block:\r\n      - context: \"d := body['data']\"\r\n      - return: \"{'body': {'text': '<!channel> :sound: ユーザーが変更されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }\"\r\n- if:\r\n    match: context.isEventType3 \r\n    block:\r\n      - context: \"d := body['data']\"\r\n      - return: \"{'body': {'text': '<!channel> :warning: ユーザーが削除されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }\"\r\n- if:\r\n    match: context.isEventType4 \r\n    block:\r\n      - context: \"d := body['data']\"\r\n      - return: \"{'body': {'text': '<!channel> :unlock: ユーザーのパスワードがリセットされました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }\"\r\n- return: \"{'body':  {'text':'other'}}\""
    },
    "urls": [
        "https://hooks.slack.com/services/xxxx/xxxx/xxxx"
    ],
    "purpose": [
        "notifications"
    ],
    "notification": {
        "interests": [
            {
                "name": "management events",
                "description": "",
                "clauses": [
                    {
                        "operation": "include",
                        "key": "data.resource",
                        "value": "user"
                    }
                ]
            }
        ],
        "enabled": true
    }
}

データ変換にあたる、"transform"-"outgoing"は、Common Expression Language (CEL) 形式で記載します。記載方法については、API を使用した Webhook の管理 - 変換や、複数行ルール実行プログラムを参照ください。
以下は改行など省いて見やすくしたデータ変換ルールになります。

statements:
- context: "isEventType1 := (body.data.resource == 'user')&&(body.data.action == 'created')"
- context: "isEventType2 := (body.data.resource == 'user')&&(body.data.action == 'modified')"
- context: "isEventType3 := (body.data.resource == 'user')&&(body.data.action == 'deleted')"
- context: "isEventType4 := (body.data.resource == 'user')&&(body.data.action == 'reset password')"
- if:
    match: context.isEventType1
        block:
            - context: "d := body['data']"
            - return: "{'body': {'text': '<!channel> :new: ユーザーが作成されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }"
- if:
   match: context.isEventType2
       block:
             - context: "d := body['data']"
             - return: "{'body': {'text': '<!channel> :sound: ユーザーが変更されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }"
- if:
    match: context.isEventType3
       block:
             - context: "d := body['data']"
             - return: "{'body': {'text': '<!channel> :warning: ユーザーが削除されました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }"
- if:
    match: context.isEventType4 
       block:
             - context: "d := body['data']"
             - return: "{'body': {'text': '<!channel> :unlock: ユーザーのパスワードがリセットされました '+'対象ユーザー:'+context.d.target+' 実施者:'+context.d.performedby_username} }"
- return: "{'body':  {'text':'other'}}"h

絵文字については、Emoji Cheat Sheetを参考にしました。

4.通知Webhookの動作確認

IBM Security Verifyの管理画面で、ユーザーの作成・変更・削除、パスワードリセット操作を行い、Slackに通知されることを確認します。
qiita-webhook (17).png

5.Webhook機能の制約事項について

マニュアルには、Webhook の制限が記載されています。
image.png

すべてのイベントを取得するような使い方の場合は、イベントAPI( Get all events for a tenant. )のほうが適して言います。

参考情報

IBM Security Verifyの通知Webhook機能

Slackのincomming Webhook機能

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0