LoginSignup
4
2

More than 3 years have passed since last update.

CIS(Cloud Internet Service)アクセスログをICOSへ定期的にLogpush

Last updated at Posted at 2019-06-25

1. はじめに

CIS(Cloud Internet Service)のEdge ServerでのアクセスログをICOSにpushする機能が最近GAされたので、この記事でやり方を紹介いたします。
ログを出力するだけだれば、Logpullでも同様のことはできるのですが、本機能は自動的にICOSに保管してくれるという観点で非常に便利です。このbucketにExpiration ruleを設定し、例えば1年間保管)とかを設定しておくとかで、効率的なログ運用ができると思われます。
本機能は、CIS Enterprise planであることが必須です。

2. ICOSへのログ書き込み用ユーザーの作成

まずCustomer Portalにcislogp@us.ibm.comというユーザーを追加し、ICOSへのWrite権限を付与します。現時点ではこのユーザー名でしかCISからICOSへの書き込みユーザーとして許可されていないようです。
このユーザーへのアクセス権限は最低限のものに限るべきですので、下図のようにService Instance名にまで制限しておいた方がいいでしょう。

image.png

さらにアクセス権を制限したいのであれば、Resource Typebucketという文字列を、Resource IDにbucket名を入力することでbucket名レベルまで絞ったアクセス制御可能です。
image.png

3. ICOSの確認

コマンド実行のためには、ICOSのInstance IDが必要です。先ほどのIAMでの設定画面からも分かりますが(2c66d594-86d5-xxxxxの箇所)、下記画面からも分かります。CRN名は以下のフォーマットになっているため赤枠の部分がICOSのInstance IDです。

crn:v1:bluemix:public:<service-name>:<region>:a/<account-id>:<resource-instance-GUID>:<resource-type>:<resource>
image.png

3. Logpushの設定

ibmcloudコマンドの最新化
# ibmcloud update
# ibmcloud plugin install cloud-internet-services
# ibmcloud plugin update --all
ICOSへLogpushするCISドメインの特定
# ibmcloud login
# ibmcloud cis domains
サービス・インスタンス 'CIS-Enterprise-Usage1' のドメインをリスト中...
OK
ID                                 名前                   状況         一時停止
a4135402d38fff24e32ef13c82c1ab4a   cisibm.tk              アクティブ   false
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx   cistest.tk             アクティブ   
false

Logpushコマンドのフォーマットは以下のようになっています。
ibmcloud cis logpush-job-create DNS_DOMAIN_ID --destination BUCKET_PATH --name JOB_NAME --fields all --enable true

--destinationのフォーマットは以下のような感じになっています。
cos://mybucket/cislog/{DATE}?region=xxxx&instance-id=xxx

Logpushコマンドの実施
# ibmcloud cis logpush-job-create a4135402d38fff24e32ef13c82c1ab4a --destination "cos://mybucket104/cislog/{DATE}?region=jp-tok&instance-id=2c66d594-86d5-4a50-ba34-cedb18fe3126" --name logpushcisibmtk --fields all --enable true
ドメイン 'a4135402d38fff24e32ef13c82c1ab4a' 内のログプッシュ・ジョブを確認中...
OK
所有権チャレンジの発行 ...
OK
チャレンジ・トークンが IBM Cloud Object Storage バケット内のファイル 'cislog/20190625/ownership-challenge-11601019.txt' に書き込まれました。これをコピー・アンド・ペーストしてください。
チャレンジ・トークン >

ここでチャレンジトークンがICOSに書き込まれるので、下記画面からそのファイルを取得して、ファイル内に記載されたトークンを上記のコマンドに貼り付けます。

image.png

所有権の検証 ...
OK
ドメイン 'a4135402d38fff24e32ef13c82c1ab4a' 内にログプッシュ・ジョブを作成中...
OK

ID                   6073
有効                 true
名前                 logpushcisibmtk
Fields               allOriginIP,WAFRuleMessage,ClientRequestUserAgent,EdgePathingStatus,EdgeStartTimestamp,ClientRequestBytes,OriginResponseHTTPExpires,WorkerSubrequestCount,EdgeResponseStatus,FirewallMatchesActions,OriginResponseStatus,ClientRequestProtocol,ClientRequestReferer,EdgeRateLimitID,OriginResponseBytes,OriginResponseTime,ParentRayID,ClientRequestHost,ClientRequestMethod,ClientSrcPort,EdgeResponseCompressionRatio,WAFAction,ClientCountry,EdgeColoID,EdgeRateLimitAction,EdgeEndTimestamp,CacheResponseBytes,ClientASN,ClientIP,RayID,CacheCacheStatus,ClientIPClass,EdgeServerIP,CacheTieredFill,EdgeRequestHost,WorkerSubrequest,ClientRequestPath,ClientRequestURI,WAFRuleID,ClientSSLProtocol,OriginResponseHTTPLastModified,WAFFlags,WorkerStatus,ZoneID,ClientDeviceType,EdgeResponseContentType,OriginSSLProtocol,FirewallMatchesRuleIDs,WAFMatchedVar,CacheResponseStatus,ClientSSLCipher,EdgeResponseBytes,EdgePathingSrc,FirewallMatchesSources,WorkerCPUTime,EdgePathingOp,SecurityLevel,WAFProfile
宛先                 cos://mybucket104/cislog/{DATE}?region=jp-tok&instance-id=2c66d594-86d5-4a50-ba34-cedb18fe3126
前回の完了
前回のエラー
エラー・メッセージ

これにて完了です。
下記コマンドで、今回作成したlogpushのjobを確認することができます。

logpush-jobの確認
# ibmcloud cis logpush-job a4135402d38fff24e32ef13c82c1ab4a
ドメイン 'a4135402d38fff24e32ef13c82c1ab4a' のログプッシュ・ジョブを取得中...
OK

ID                   6073
有効                 true
名前                 logpushcisibmtk
Fields               allOriginIP,WAFRuleMessage,ClientRequestUserAgent,EdgePathingStatus,EdgeStartTimestamp,ClientRequestBytes,OriginResponseHTTPExpires,WorkerSubrequestCount,EdgeResponseStatus,FirewallMatchesActions,OriginResponseStatus,ClientRequestProtocol,ClientRequestReferer,EdgeRateLimitID,OriginResponseBytes,OriginResponseTime,ParentRayID,ClientRequestHost,ClientRequestMethod,ClientSrcPort,EdgeResponseCompressionRatio,WAFAction,ClientCountry,EdgeColoID,EdgeRateLimitAction,EdgeEndTimestamp,CacheResponseBytes,ClientASN,ClientIP,RayID,CacheCacheStatus,ClientIPClass,EdgeServerIP,CacheTieredFill,EdgeRequestHost,WorkerSubrequest,ClientRequestPath,ClientRequestURI,WAFRuleID,ClientSSLProtocol,OriginResponseHTTPLastModified,WAFFlags,WorkerStatus,ZoneID,ClientDeviceType,EdgeResponseContentType,OriginSSLProtocol,FirewallMatchesRuleIDs,WAFMatchedVar,CacheResponseStatus,ClientSSLCipher,EdgeResponseBytes,EdgePathingSrc,FirewallMatchesSources,WorkerCPUTime,EdgePathingOp,SecurityLevel,WAFProfile
宛先                 cos://mybucket104/cislog/{DATE}?region=jp-tok&instance-id=2c66d594-86d5-4a50-ba34-cedb18fe3126
前回の完了           2019-06-25T06:05:00Z
前回のエラー
エラー・メッセージ

image.png

ログの中身を確認してみると、例えば以下のようなログが出力されることがわかります。

{"CacheCacheStatus":"hit","CacheResponseBytes":1583,"CacheResponseStatus":404,"CacheTieredFill":false,"ClientASN":18289,"ClientCountry":"jp","ClientDeviceType":"desktop","ClientIP":"203.141.91.14","ClientIPClass":"noRecord","ClientRequestBytes":1326,"ClientRequestHost":"www.cisibm.tk","ClientRequestMethod":"GET","ClientRequestPath":"/favicon.ico","ClientRequestProtocol":"HTTP/2","ClientRequestReferer":"","ClientRequestURI":"/favicon.ico","ClientRequestUserAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Firefox/60.0","ClientSSLCipher":"ECDHE-ECDSA-AES128-GCM-SHA256","ClientSSLProtocol":"TLSv1.2","ClientSrcPort":12456,"EdgeColoID":22,"EdgeEndTimestamp":1561442961711000000,"EdgePathingOp":"wl","EdgePathingSrc":"macro","EdgePathingStatus":"nr","EdgeRateLimitAction":"","EdgeRateLimitID":0,"EdgeRequestHost":"www.cisibm.tk","EdgeResponseBytes":608,"EdgeResponseCompressionRatio":1.2,"EdgeResponseContentType":"text/html","EdgeResponseStatus":404,"EdgeServerIP":"","EdgeStartTimestamp":1561442961661000000,"FirewallMatchesActions":[],"FirewallMatchesSources":[],"FirewallMatchesRuleIDs":[],"OriginResponseBytes":0,"OriginResponseHTTPExpires":"","OriginResponseHTTPLastModified":"","OriginResponseStatus":0,"OriginResponseTime":0,"OriginSSLProtocol":"unknown","ParentRayID":"00","RayID":"4ec4c5ae6f7d94e5","SecurityLevel":"med","WAFAction":"unknown","WAFFlags":"0","WAFMatchedVar":"","WAFProfile":"unknown","WAFRuleID":"","WAFRuleMessage":"","WorkerCPUTime":0,"WorkerStatus":"unknown","WorkerSubrequest":false,"WorkerSubrequestCount":0,"ZoneID":126666217}

その他制約

IBM Cloud docsに記載されているとおり、5分置き30秒置きにICOSにpushされるようです。この間隔は変更できないようです。

※2020/09/17追記
IBM Cloud Docsには5分置きと書かれてしますが、「30秒置きもしくは10万レコードごとのどちらかに達した時点で logpush される」ように仕様変更されたとのことです。IBM Cloud docsは近日中に更新される予定です。

4
2
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
4
2