OAuth ベアラー・トークン
OAuth ベアラー・トークンは、アプリケーションが特定の QRadar リソースにアクセスすることを許可するアクセス・トークンです。
QRadar OAuth アプリケーションは、OAuth ベアラー・トークンを使用して、QRadar REST API 呼び出しを行うことができます。
以下の図は、例で使用される OAuth アプリケーションのフォルダーおよびファイルの構造を示しています。図 1. OAuth ベアラー・トークン・アプリケーション
以下の例は、バックグラウンド・サービスであるアプリケーションがベアラー・トークンを取得し、そのトークンを使用して QRadar REST API 呼び出しを行うための許可を得る方法を示しています。
- manifest.json ファイルには、アプリケーションを OAuth アプリケーションとして識別して構成するための認証エントリーが含まれており、Flask Web サーバーにロードしないように指示します。
{ "name": "OAuth background process", "version": "1.0", "description": "Simple background process app that calls QRadar REST API using OAuth", "uuid": "a7e67388-95e1-436e-bdbd-df9c53230728", "load_flask": "false", "authentication": { "oauth2": { "authorisation_flow": "CLIENT_CREDENTIALS", "requested_capabilities": ["ADMIN"] } } } - src_deps/init/launch_background_process.sh スクリプトが実行されます。
#!/bin/bash nohup python /app/background_process.py >/store/log/background_process.log 2>&1 & - src_deps/init/launch_background_process.sh スクリプトは、app/background_process.py Python モジュールを呼び出します。
#!/usr/bin/python from qpylib import qpylib from qpylib import oauth_qpylib import requests import json import time qpylib.create_log() rest_url = 'https://' + qpylib.get_console_address() + '/api/ariel/databases' request_headers = {} oauth_qpylib.add_oauth_header(request_headers) while True: time.sleep(30) try: response = requests.get(rest_url, headers=request_headers, verify=False) qpylib.log('response=' + json.dumps(response.json())) except Exception as e: qpylib.log('Error: ' + str(e))background_process.py モジュールは、QRadar REST API エンドポイントを呼び出す連続ループを実行し、結果をログに記録します。
- OAuth ベアラー・トークンを取得する方法
-
add_oauth_header関数は、Python 要求対応のヘッダー・オブジェクトを受け入れ、アプリケーションの OAuth ベアラー・トークンを含む許可ヘッダーを追加します。
以下の URL は、OAuth サービスへの GET トークン要求の例です。
http://qoauth.service.consul:<Port_number>/token?grant_type=client_credentials&client_id=<Client_ID>&client_secret=<Client_secret>
-
以下の例のようなベアラー・トークンが JSON 応答の
access_tokenフィールド内に保持されます。{"access_token": "example_token_34j3fdde", "token_type": "Bearer", "scope": "ADMIN"}