IBM Cloud Internet ServicesのLogpush機能でログをIBM Cloud Object Storageに保管する


目的

IBM Cloud Internet Services(以下、CIS)に新規実装されたLogpush機能を使って、CISのログをIBM Cloud Object Storage(以下、ICOS)に自動保管できるようになりました。実際にやってみましたので、ご参考まで。

前提

  • CISのプランはEnterprise Usage以上(おそらく)
  • IBM Cloud CLIのCISプラグイン1.5.0以上をインストール済
  • ICOSインスタンスおよびバケットは作成済

手順

基本的には以下のとおりです。

https://cloud.ibm.com/docs/infrastructure/cis?topic=cis-logpush&locale=en

[email protected]の招待と権限付与

対象アカウントのユーザとして[email protected]を招待します。次に、該当バケットへのWriter権限を付与します。

CISにlogpush-jobの作成

IBM Cloud CLIのCISプラグインを使って、logpush-jobを作成します。

$ ibmcloud cis instance-set <CISインスタンス名>
$ ibmcloud cis logpush-job-create <DNSドメインID> \
  --destination 'cos://<バケット名>/{DATE}?region=<リージョン名>&instance-id=<ICOSインスタンスID>' \
  --name <ジョブ名> \
  --fields all \
  --enable true

バケット名: バケット名
DNSドメインID: ibmcloud cis domains コマンドでIDを確認できる
リージョン名: jp-tokなど、バケット作成時に指定したもの
ICOSインスタンスID: ibmcloud resource service-instances --long | grep -E "GUID|<オブジェクトストレージ名>" でGUIDを確認できるのでそれを指定
ジョブ名: 任意

先の権限設定がうまくできていると次のようにチャレンジファイルがバケットに保管されます。

Checking logpush job in domain '***************************' ...
OK
Issue ownership challenge ...
OK
A challenge token was written to file '20190525/cloudflare-ownership-challenge-********.txt' in your IBM Cloud Object Storage bucket, please copy and paste it.
Challenge Token >

ファイルをダウンロードし、中のテキストをコマンドプロンプトにペーストし、エンターしてください。うまくいけば次のように正常終了します。

Validate ownership ...
OK
Creating logpush job in domain '**************************' ... 
OK

ID              ####
Enabled         true
Name            logpush
Fields          allClientRequestHost,ClientRequestProtocol,ClientSSLProtocol,WAFRuleMessage,ClientIP,OriginResponseHTTPExpires,RayID,WAFRuleID,ClientASN,EdgePathingOp,EdgeRateLimitID,EdgeResponseStatus,CacheCacheStatus,EdgeRequestHost,EdgeStartTimestamp,WorkerSubrequestCount,ClientSrcPort,OriginSSLProtocol,CacheResponseBytes,OriginResponseBytes,OriginResponseHTTPLastModified,ParentRayID,SecurityLevel,WAFAction,ZoneID,ClientCountry,ClientRequestPath,ClientSSLCipher,EdgeColoID,OriginIP,EdgeResponseBytes,OriginResponseStatus,WorkerSubrequest,ClientIPClass,ClientRequestUserAgent,EdgeEndTimestamp,EdgeResponseCompressionRatio,WAFMatchedVar,ClientRequestURI,EdgeResponseContentType,WAFProfile,WorkerCPUTime,EdgeServerIP,OriginResponseTime,WorkerStatus,WAFFlags,CacheResponseStatus,CacheTieredFill,ClientRequestBytes,ClientRequestReferer,EdgePathingSrc,EdgePathingStatus,EdgeRateLimitAction,ClientDeviceType,ClientRequestMethod
Destination     cos://**************/{DATE}?region=jp-tok&instance-id=****************************
Last complete
Last error
Error message

この例では--enable trueでジョブを作成したので、しばらくしてバケットを確認すると、ログのアップロードが自動的に始まっています。

アップロードは5分おきに行われるようです。オブジェクト数がすごいことになるのでご注意を。

以上です。