3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rancherの監査ログをCUIで取得する

Posted at

Docker環境の管理ツールであるRancherで
監査ログをCUIから取得する方法を整理する。

目的

  • Rancherで生成される監査ログをCUIから取得する方法を整理する。
  • 書く書く詐欺の解消

Rancher meetup#2で喋った内容の補足
http://www.slideshare.net/recruitcojp/rancherdevops

手順

APIキーの取得

RancherのUIにログインしたらAPIラベルを選択する

image

Add Account API Keyボタンをクリックする

image

APIキーの名前と説明を記述してCreateボタンをクリック
image

AccesskeyとSecret Keyを記録。
ここでは、検証用の環境でこのあと潰すので公開していますが、
Secret Keyは名前の通り、秘密なので他者への公開はしないようにしてください。

image

リクエストを投げる

監査ログ取得のためのリクエスト
curl -u 2FC7A0D4F5BD3826748F:18xj27yUkg8m9mChPdr6nYysY2SNawL6rCwyX4NT 'http://192.168.0.10:8080/v2-beta/auditlogs?limit=100&sort=id&order=desc'-H 'content-type: application/json'

ベーシック認証のユーザ名部分にAccess Key, パスワード部分にSecret Keyを指定することでログを取得できます。
なお、この方法は他のAPIを叩く場合も同様です。
(Rancher CLIで対応したものがある場合はそちらを利用したほうが楽です)

上記リクエストの場合は100件のログを操作のIDにそって降順にならべたものが取得できます。以下に1件の情報を取得した例を載せます。

監査ログ1レコードの取得例
{
  "type": "collection",
  "resourceType": "auditLog",
  "links": {
    "self": "http://192.168.0.10:8080/v2-beta/auditlogs"
  },
  "createTypes": {},
  "actions": {},
  "data": [
    {
      "id": "1al32",
      "type": "auditLog",
      "links": {
        "self": "http://192.168.0.10:8080/v2-beta/auditlogs/1al32",
        "account": "http://192.168.0.10:8080/v2-beta/auditlogs/1al32/account",
        "authenticatedAsAccount": "http://192.168.0.10:8080/v2-beta/auditlogs/1al32/authenticatedasaccount",
        "resource": "http://192.168.0.10:8080/v2-beta/apikeys/1c3",
        "authenticatedAsIdentity": "http://192.168.0.10:8080/v2-beta/identities/1i!rancher_id:1"
      },
      "actions": {},
      "baseType": "auditLog",
      "accountId": "1a1",
      "authType": "TokenAuth",
      "authenticatedAsAccountId": "1a1",
      "authenticatedAsIdentityId": "1i!rancher_id:1",
      "clientIp": "192.168.0.4",
      "created": "2017-01-21T17:05:23Z",
      "createdTS": 1485018323000,
      "description": null,
      "eventType": "api.apiKey.create",
      "kind": "auditLog",
      "requestObject": "{\"accountId\":1,\"name\":\"sample_api_key\",\"description\":\"サンプルのAPIキー\",\"kind\":\"apiKey\",\"publicValue\":\"2FC7A0D4F5BD3826748F\",\"secretValue\":\"SHA256:0fe5fa6e9e1cba23146d:323664499f0e49272b229be60232da32b3857d1f127af60fedad5d37c767e763\"}",
      "resourceId": "1c3",
      "resourceType": "apiKey",
      "responseCode": 201,
      "responseObject": "{\"id\":\"1c3\",\"type\":\"apiKey\",\"links\":{\"self\":\"http:\\/\\/192.168.0.10:8080\\/v2-beta\\/apikeys\\/1c3\",\"account\":\"http:\\/\\/192.168.0.10:8080\\/v2-beta\\/apikeys\\/1c3\\/account\",\"images\":\"http:\\/\\/192.168.0.10:8080\\/v2-beta\\/apikeys\\/1c3\\/images\",\"instances\":\"http:\\/\\/192.168.0.10:8080\\/v2-beta\\/apikeys\\/1c3\\/instances\",\"certificate\":\"http:\\/\\/192.168.0.10:8080\\/v2-beta\\/apikeys\\/1c3\\/certificate\"},\"actions\":{\"activate\":\"http:\\/\\/192.168.0.10:8080\\/v2-beta\\/apikeys\\/1c3\\/?action=activate\",\"remove\":\"http:\\/\\/192.168.0.10:8080\\/v2-beta\\/apikeys\\/1c3\\/?action=remove\",\"deactivate\":\"http:\\/\\/192.168.0.10:8080\\/v2-beta\\/apikeys\\/1c3\\/?action=deactivate\"},\"baseType\":\"credential\",\"name\":\"sample_api_key\",\"state\":\"registering\",\"accountId\":\"1a1\",\"created\":\"2017-01-21T17:05:23Z\",\"createdTS\":1485018323000,\"data\":{},\"description\":\"サンプルのAPIキー\",\"kind\":\"apiKey\",\"publicValue\":\"2FC7A0D4F5BD3826748F\",\"removeTime\":null,\"removed\":null,\"secretValue\":\"18xj27yUkg8m9mChPdr6nYysY2SNawL6rCwyX4NT\",\"transitioning\":\"yes\",\"transitioningMessage\":\"In Progress\",\"transitioningProgress\":null,\"uuid\":\"2777e5a4-c3e5-4b25-9e3d-a6a77b3f7f06\"}"
    }
  ],
  "sortLinks": {
    "accountId": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=accountId",
    "authType": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=authType",
    "authenticatedAsAccountId": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=authenticatedAsAccountId",
    "authenticatedAsIdentityId": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=authenticatedAsIdentityId",
    "clientIp": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=clientIp",
    "created": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=created",
    "description": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=description",
    "eventType": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=eventType",
    "id": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=id",
    "kind": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=kind",
    "resourceId": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=resourceId",
    "resourceType": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=resourceType",
    "runtime": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=runtime"
  },
  "pagination": {
    "first": null,
    "previous": null,
    "next": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=id&order=desc&marker=m1",
    "limit": 1,
    "total": null,
    "partial": true
  },
  "sort": {
    "name": "id",
    "reverse": "http://192.168.0.10:8080/v2-beta/auditlogs?limit=1&sort=id&order=asc",
    "order": "desc"
  },
  "filters": {
    "accountId": null,
    "authType": null,
    "authenticatedAsAccountId": null,
    "authenticatedAsIdentityId": null,
    "clientIp": null,
    "created": null,
    "description": null,
    "eventType": null,
    "id": null,
    "kind": null,
    "resourceId": null,
    "resourceType": null,
    "runtime": null
  },
  "createDefaults": {}
}

dataの中に監査対象となった各種操作の配列が含まれている。
今回の例だと、eventTypeの値(api.apiKey.create)から判断するに
APIキーの新規作成したことがわかる。

他にもいろいろな情報が含まれているので、必要に応じて利用してください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?