この文書は自動機械翻訳技術を使用して翻訳されています。 正確な翻訳を提供するように努めておりますが、翻訳された内容の完全性、正確性、信頼性については一切保証いたしません。 相違がある場合は、元の英語版 英語 が優先され、正式なテキストとなります。

API監査ログを有効にしてシステムイベントを記録する

個々のユーザーによって開始されたシステムイベントのシーケンスを記録するために、API監査ログを有効にすることができます。何が起こったのか、いつ起こったのか、誰がそれを開始したのか、どのクラスターに影響を与えたのかを知ることができます。この機能を有効にすると、Rancher APIへのすべてのリクエストとそのすべてのレスポンスがログに記録されます。

Rancherのインストールまたはアップグレード中にAPI監査を有効にすることができます。

API監査ログを有効にする

監査ログは有効化され、Rancherサーバーコンテナに環境変数を渡すことで構成されます。インストール時に有効にする方法については、以下を参照してください。

API監査ログオプション

以下の使用法は、監査ログが記録すべき内容と含めるべきデータに関するルールを定義します:

パラメータ 説明

AUDIT_LOG_ENABLED

false - 監査ログを無効にします(デフォルト設定)。

true - 監査ログを有効にします。

AUDIT_LEVEL

0 - リクエストおよびレスポンスのメタデータをログに記録します(デフォルト設定)。
1 - リクエストおよびレスポンスのヘッダーをログに記録します。
2 - リクエストボディをログに記録します。
3 - レスポンスボディをログに記録します。各ログレベルは累積的であり、各次のレベルは前のレベルのデータをログに記録します。リクエスト/レスポンスペアの各ログトランザクションは、同じ`auditID`値を使用します。

各設定がログに記録する内容を表示する表については、監査レベルログ記録を参照してください。

AUDIT_LOG_PATH

Rancher Server APIのログパスです。デフォルトのパスは`/var/log/auditlog/rancher-api-audit.log`です。ログディレクトリをホストにマウントできます。

使用例: AUDIT_LOG_PATH=/my/custom/path/

AUDIT_LOG_MAXAGE

古い監査ログファイルを保持する最大日数を定義しました。デフォルトは10日です。

AUDIT_LOG_MAXBACKUP

保持する監査ログファイルの最大数を定義します。デフォルトは10です。

AUDIT_LOG_MAXSIZE

監査ログファイルがローテーションされる前の最大サイズ(メガバイト)を定義します。デフォルトのサイズは100Mです。

監査ログレベル

以下の表は、各AUDIT_LEVEL設定に対してAPIトランザクションのどの部分がログに記録されるかを示しています。

AUDIT_LEVEL 設定 メタデータ リクエストヘッダー レスポンスヘッダー リクエストボディ レスポンスボディ

0

1

2

3

監査ログポリシー

監査ログポリシーにより、エンドユーザーは`AuditPolicy`クラスター範囲のCRを用いて、デフォルトのマスキングとフィルターに加えてマスキング設定を構成できます。

すべての構成された監査ログポリシーは加算的です。

ヘッダーのマスキングポリシーは、正規表現(regex)エンジンを使用してヘッダーをマスキングし、リクエスト/レスポンスヘッダーの場合はJSONPathエンジンを使用してマスキングします。

JSONPathエンジンは、スクリプトやフィルター式をサポートしていません。JSONPath式の使い始めに関しては、 スタファン・ゲスナーのJSONPathに関する記事が良いリソースです。

監査ポリシーCRの構造は次のとおりです:

apiVersion: auditlog.cattle.io/v1
kind: AuditPolicy
spec:
  enabled : true # true/false
  # list of API request filters
  filters:
    - action: allow # allow/deny
        # would allow logs sent to "/foo/some/endpoint" but not "/foo" or "/foobar".
      requestURI: "/foo/.*"
  # additionalRedactions allows configuration of redactions on headers using `jsonpath` expressions
  additionalRedactions:
    # redacts headers based on regex expressions
    - headers:
      - "Cache.*"
      # paths redacts information from request and response bodies based on json path expressions
      paths:
      - "$.gitCommit"
  verbosity:
    level : 0 # matches the levels in the above audit log table
    # request allows fine-grained control over which request data
    # gets included. This overrides the behaviour of the generic verbosity.level
    request:
      headers : true # true/false
      body : true # true/false
    # response allows fine-grained control over which response data
    # gets included. This overrides the behaviour of the generic verbosity.level
    response:
      headers : true # true/false
      body: true # true/false

次の例は、リクエストパスに`login`を含むリクエストのみを監査ログパスに記録することを示しています:

apiVersion: auditlog.cattle.io/v1
kind: AuditPolicy
metadata:
  name: filters
spec:
  filters:
    - action: deny
      requestUri: ".*"
    - action: allow
      requestUri: ".*login.*"

次の例は、リクエスト/レスポンスボディに`gitCommint`を含む特定のフィールドをマスキングする方法を示しています。

apiVersion: auditlog.cattle.io/v1
kind: AuditPolicy
metadata:
  name: redactions
spec:
  additionalRedactions:
    - paths:
      - "$.gitCommit"

デフォルトのマスキングおよびフィルター

監査ログコントローラーには、一般的な機密情報に対するデフォルトのビルトインマスキングが付属しています。

マスキングされたヘッダー

一般的なヘッダー:

  • Cookie

  • Set-Cookie

  • X-Api-Set-Cookie-Header

  • Authorization

  • X-Api-Tunnel-Params

  • X-Api-Tunnel-Token

  • X-Api-Auth-Header

  • X-Amz-Security-Token

マスキングされたボディフィールド

一般的なボディフィールド:

  • credentials

  • applicationSecret

  • oauthCredential

  • serviceAccountCredential

  • spKey

  • spCert

  • certificate

  • privateKey

  • secretsEncryptionConfig

  • manifestUrl

  • insecureWindowsNodeCommand

  • insecureNodeCommand

  • insecureCommand

  • command

  • nodeCommand

  • windowsNodeCommand

  • clientRandom

一般的なボディ正規表現マスクツール:

  • ".([pP]assword|[Kk]ube[Cc]onfig|[Tt]oken)."

クラスター ドライバー

デフォルトでは、クラスター ドライバーに関連付けられたフィールドを持つAPIリクエストでは、`public*`または`optional*`以外のフィールドが監査ログコントローラーによってマスキングされます。

マスキングされたURI

secrets`または`configmaps`を含むエンドポイントは、リクエストおよびレスポンスボディの両方から関連フィールドがマスキングされます。さらに、/v3/imports/*`を含むエンドポイントでは、そのURIがマスキングされます。

API監査ログの表示

Dockerのインストール

AUDIT_LOG_PATH`ディレクトリ(デフォルト:/var/log/auditlog`)をホストシステムと共有します。ログは標準CLIツールで解析することができるか、Fluentd、Filebeat、Logstashなどのログ収集ツールに転送することができます。

Kubernetesのインストール

HelmチャートインストールでAPI監査ログを有効にすると、Rancherポッドに`rancher-audit-log`サイドカーコンテナが作成されます。このコンテナはログを標準出力(stdout)にストリーミングします。コンテナのログと同様に、ログを表示することができます。

`rancher-audit-log`コンテナは`rancher`ポッドの`cattle-system`ネームスペース内の一部です。

CLI

kubectl -n cattle-system logs -f rancher-84d886bdbb-s4s69 rancher-audit-log

監査ログの送信

クラスター向けに、Rancherのビルトインログ収集と送信を有効にすると、監査ログやその他のサービスのログをサポートされている収集エンドポイントに送信できます。詳細についてはRancherツール - ロギングを参照してください。

監査ログサンプル

監査を有効にすると、各APIリクエストまたはレスポンスはRancherによってJSON形式でログに記録されます。以下の各コードサンプルは、各APIトランザクションを特定する方法の例を提供します。

メタデータレベル

`AUDIT_LEVEL`を`0`に設定すると、RancherはすべてのAPIリクエストのメタデータヘッダーをログに記録しますが、ボディやリクエストおよびレスポンスヘッダーは記録しません。メタデータは、トランザクションID、トランザクションの発起者、発生した時間など、APIトランザクションに関する基本情報を提供します。

{
  "auditID": "40bd4e40-875b-4020-933e-4c4f4c4db366",
  "requestURI": "/v3/schemas",
  "user": {
      "name": "user-6j5s6",
      "group": [
          "system:authenticated",
          "system:cattle:authenticated"
      ],
      "extra": {
          "principalid": [
              "local://user-6j5s6"
          ],
          "requesthost": [
              "localhost:8443"
          ],
          "requesttokenid": [
              "token-zs42h"
          ],
          "username": [
              "admin"
          ]
      }
  },
  "method": "GET",
  "remoteAddr": "127.0.0.1:58652",
  "responseCode": 200,
  "requestTimestamp": "2025-06-30T11:13:25-04:00",
  "responseTimestamp": "2025-06-30T11:13:25-04:00"
}

メタデータとヘッダーのレベル

`AUDIT_LEVEL`を`1`に設定すると、RancherはすべてのAPIリクエストのメタデータとリクエストおよびレスポンスヘッダーをログに記録します。

{
    "auditID": "f8c83dc6-a080-4e2e-ab43-552bddf01716",
    "requestURI": "/v1/apps.deployments?page=1&pagesize=100&sort=metadata.name&filter=metadata.namespace!=p-npsl5&filter=metadata.namespace!=p-nzp6c&filter=metadata.namespace!=cattle-fleet-clusters-system&filter=metadata.namespace!=cattle-fleet-system&filter=metadata.namespace!=cattle-global-data&filter=metadata.namespace!=cattle-impersonation-system&filter=metadata.namespace!=cattle-provisioning-capi-system&filter=metadata.namespace!=cattle-system&filter=metadata.namespace!=cattle-ui-plugin-system&filter=metadata.namespace!=cluster-fleet-local-local-1a3d67d0a899&filter=metadata.namespace!=fleet-default&filter=metadata.namespace!=fleet-local&filter=metadata.namespace!=kube-node-lease&filter=metadata.namespace!=kube-public&filter=metadata.namespace!=kube-system&exclude=metadata.managedFields",
    "user": {
        "name": "user-6j5s6",
        "group": [
            "system:authenticated",
            "system:cattle:authenticated"
        ],
        "extra": {
            "principalid": [
                "local://user-6j5s6"
            ],
            "requesthost": [
                "localhost:8443"
            ],
            "requesttokenid": [
                "token-zs42h"
            ],
            "username": [
                "admin"
            ]
        }
    },
    "method": "GET",
    "remoteAddr": "127.0.0.1:58833",
    "responseCode": 200,
    "requestTimestamp": "2025-06-30T11:17:04-04:00",
    "responseTimestamp": "2025-06-30T11:17:04-04:00",
    "requestHeader": {
        "Accept": [
            "application/json"
        ],
        "Accept-Encoding": [
            "gzip, deflate, br, zstd"
        ],
        "Accept-Language": [
            "en-US,en;q=0.5"
        ],
        "Connection": [
            "keep-alive"
        ],
        "Cookie": [
            "[redacted]"
        ],
        "Referer": [
            "https://localhost:8443/dashboard/c/local/explorer/apps.deployment"
        ],
        "Sec-Fetch-Dest": [
            "empty"
        ],
        "Sec-Fetch-Mode": [
            "cors"
        ],
        "Sec-Fetch-Site": [
            "same-origin"
        ],
        "User-Agent": [
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0"
        ],
        "X-Api-Csrf": [
            "fccc690cab7b0c169b3fc6527edadef3"
        ]
    },
    "responseHeader": {
        "Cache-Control": [
            "no-cache, no-store, must-revalidate"
        ],
        "Content-Encoding": [
            "gzip"
        ],
        "Content-Type": [
            "application/json"
        ],
        "Expires": [
            "Wed 24 Feb 1982 18:42:00 GMT"
        ],
        "X-Api-Cattle-Auth": [
            "true"
        ],
        "X-Api-Schemas": [
            "https://localhost:8443/v1/schemas"
        ],
        "X-Content-Type-Options": [
            "nosniff"
        ]
    }
}

メタデータ、ヘッダー、およびリクエストボディのレベル

`AUDIT_LEVEL`を`2`に設定すると、RancherはすべてのAPIリクエストのメタデータ、リクエストおよびレスポンスヘッダー、リクエストボディをログに記録します。

以下のコードサンプルは、メタデータ、ヘッダー、およびリクエストボディを含むAPIリクエストを示しています。

要求

以下のコードサンプルは、メタデータヘッダーとボディを含むAPIリクエストを示しています。

{
    "auditID": "d1088a09-2a13-4450-970e-0d44bd2c49ee",
    "requestURI": "/v3/projects",
    "user": {
        "name": "user-6j5s6",
        "group": [
            "system:authenticated",
            "system:cattle:authenticated"
        ],
        "extra": {
            "principalid": [
                "local://user-6j5s6"
            ],
            "requesthost": [
                "localhost:8443"
            ],
            "requesttokenid": [
                "token-zs42h"
            ],
            "username": [
                "admin"
            ]
        }
    },
    "method": "POST",
    "remoteAddr": "127.0.0.1:49966",
    "responseCode": 201,
    "requestTimestamp": "2025-06-30T12:32:13-04:00",
    "responseTimestamp": "2025-06-30T12:32:13-04:00",
    "requestHeader": {
        "Accept": [
            "application/json"
        ],
        "Accept-Encoding": [
            "gzip, deflate, br, zstd"
        ],
        "Accept-Language": [
            "en-US,en;q=0.5"
        ],
        "Connection": [
            "keep-alive"
        ],
        "Content-Length": [
            "214"
        ],
        "Content-Type": [
            "application/json"
        ],
        "Cookie": [
            "[redacted]"
        ],
        "Impersonate-Extra-Principalid": [
            "local://user-6j5s6"
        ],
        "Impersonate-Extra-Requesthost": [
            "localhost:8443"
        ],
        "Impersonate-Extra-Requesttokenid": [
            "token-zs42h"
        ],
        "Impersonate-Extra-Username": [
            "admin"
        ],
        "Impersonate-Group": [
            "system:authenticated",
            "system:cattle:authenticated"
        ],
        "Impersonate-User": [
            "user-6j5s6"
        ],
        "Origin": [
            "https://localhost:8443"
        ],
        "Priority": [
            "u=0"
        ],
        "Referer": [
            "https://localhost:8443/dashboard/c/local/explorer/management.cattle.io.project/create"
        ],
        "Sec-Fetch-Dest": [
            "empty"
        ],
        "Sec-Fetch-Mode": [
            "cors"
        ],
        "Sec-Fetch-Site": [
            "same-origin"
        ],
        "User-Agent": [
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0"
        ],
        "X-Api-Csrf": [
            "fccc690cab7b0c169b3fc6527edadef3"
        ]
    },
    "responseHeader": {
        "Cache-Control": [
            "no-cache, no-store, must-revalidate"
        ],
        "Content-Encoding": [
            "gzip"
        ],
        "Content-Type": [
            "application/json"
        ],
        "Expires": [
            "Wed 24 Feb 1982 18:42:00 GMT"
        ],
        "X-Api-Cattle-Auth": [
            "true"
        ],
        "X-Api-Schemas": [
            "https://localhost:8443/v3/project/schemas"
        ],
        "X-Content-Type-Options": [
            "nosniff"
        ]
    },
    "requestBody": {
        "annotations": {},
        "clusterId": "local",
        "containerDefaultResourceLimit": {},
        "creatorId": "local://user-6j5s6",
        "labels": {},
        "name": "example-project",
        "namespaceDefaultResourceQuota": {},
        "resourceQuota": {},
        "type": "project"
    }
}

メタデータ、ヘッダー、リクエストボディ、およびレスポンスボディレベル

`AUDIT_LEVEL`を`3`に設定すると、Rancherはメタデータ、リクエストおよびレスポンスヘッダー、リクエストボディおよびレスポンスをログに記録します。

以下のコードサンプルは、その情報がログに記録されたAPIリクエストの例を示しています。

{
    "auditID": "a9549a5b-4351-4bd5-adcd-12f7ec667a6b",
    "requestURI": "/v3/projects",
    "user": {
        "name": "user-6j5s6",
        "group": [
            "system:authenticated",
            "system:cattle:authenticated"
        ],
        "extra": {
            "principalid": [
                "local://user-6j5s6"
            ],
            "requesthost": [
                "localhost:8443"
            ],
            "requesttokenid": [
                "token-zs42h"
            ],
            "username": [
                "admin"
            ]
        }
    },
    "method": "POST",
    "remoteAddr": "127.0.0.1:50454",
    "responseCode": 201,
    "requestTimestamp": "2025-06-30T12:42:24-04:00",
    "responseTimestamp": "2025-06-30T12:42:24-04:00",
    "requestHeader": {
        "Accept": [
            "application/json"
        ],
        "Accept-Encoding": [
            "gzip, deflate, br, zstd"
        ],
        "Accept-Language": [
            "en-US,en;q=0.5"
        ],
        "Connection": [
            "keep-alive"
        ],
        "Content-Length": [
            "214"
        ],
        "Content-Type": [
            "application/json"
        ],
        "Cookie": [
            "[redacted]"
        ],
        "Impersonate-Extra-Principalid": [
            "local://user-6j5s6"
        ],
        "Impersonate-Extra-Requesthost": [
            "localhost:8443"
        ],
        "Impersonate-Extra-Requesttokenid": [
            "token-zs42h"
        ],
        "Impersonate-Extra-Username": [
            "admin"
        ],
        "Impersonate-Group": [
            "system:authenticated",
            "system:cattle:authenticated"
        ],
        "Impersonate-User": [
            "user-6j5s6"
        ],
        "Origin": [
            "https://localhost:8443"
        ],
        "Priority": [
            "u=0"
        ],
        "Referer": [
            "https://localhost:8443/dashboard/c/local/explorer/management.cattle.io.project/create"
        ],
        "Sec-Fetch-Dest": [
            "empty"
        ],
        "Sec-Fetch-Mode": [
            "cors"
        ],
        "Sec-Fetch-Site": [
            "same-origin"
        ],
        "User-Agent": [
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0"
        ],
        "X-Api-Csrf": [
            "fccc690cab7b0c169b3fc6527edadef3"
        ]
    },
    "responseHeader": {
        "Cache-Control": [
            "no-cache, no-store, must-revalidate"
        ],
        "Content-Encoding": [
            "gzip"
        ],
        "Content-Type": [
            "application/json"
        ],
        "Expires": [
            "Wed 24 Feb 1982 18:42:00 GMT"
        ],
        "X-Api-Cattle-Auth": [
            "true"
        ],
        "X-Api-Schemas": [
            "https://localhost:8443/v3/project/schemas"
        ],
        "X-Content-Type-Options": [
            "nosniff"
        ]
    },
    "requestBody": {
        "annotations": {},
        "clusterId": "local",
        "containerDefaultResourceLimit": {},
        "creatorId": "local://user-6j5s6",
        "labels": {},
        "name": "example-project",
        "namespaceDefaultResourceQuota": {},
        "resourceQuota": {},
        "type": "project"
    },
    "responseBody": {
        "actions": {
            "exportYaml": "https://localhost:8443/v3/projects/local:p-qt6tq?action=exportYaml"
        },
        "annotations": {
            "authz.management.cattle.io/creator-role-bindings": "{\"required\":[\"project-owner\"]}"
        },
        "backingNamespace": "local-p-qt6tq",
        "baseType": "project",
        "clusterId": "local",
        "containerDefaultResourceLimit": {
            "type": "/v3/schemas/containerResourceLimit"
        },
        "created": "2025-06-30T16:42:24Z",
        "createdTS": 1751301744000,
        "creatorId": "user-6j5s6",
        "id": "local:p-qt6tq",
        "labels": {
            "cattle.io/creator": "norman"
        },
        "links": {
            "basicAuths": "https://localhost:8443/v3/projects/local:p-qt6tq/basicauths",
            "certificates": "https://localhost:8443/v3/projects/local:p-qt6tq/certificates",
            "configMaps": "https://localhost:8443/v3/projects/local:p-qt6tq/configmaps",
            "cronJobs": "https://localhost:8443/v3/projects/local:p-qt6tq/cronjobs",
            "daemonSets": "https://localhost:8443/v3/projects/local:p-qt6tq/daemonsets",
            "deployments": "https://localhost:8443/v3/projects/local:p-qt6tq/deployments",
            "dnsRecords": "https://localhost:8443/v3/projects/local:p-qt6tq/dnsrecords",
            "dockerCredentials": "https://localhost:8443/v3/projects/local:p-qt6tq/dockercredentials",
            "horizontalPodAutoscalers": "https://localhost:8443/v3/projects/local:p-qt6tq/horizontalpodautoscalers",
            "ingresses": "https://localhost:8443/v3/projects/local:p-qt6tq/ingresses",
            "jobs": "https://localhost:8443/v3/projects/local:p-qt6tq/jobs",
            "namespacedBasicAuths": "https://localhost:8443/v3/projects/local:p-qt6tq/namespacedbasicauths",
            "namespacedCertificates": "https://localhost:8443/v3/projects/local:p-qt6tq/namespacedcertificates",
            "namespacedDockerCredentials": "https://localhost:8443/v3/projects/local:p-qt6tq/namespaceddockercredentials",
            "namespacedSecrets": "https://localhost:8443/v3/projects/local:p-qt6tq/namespacedsecrets",
            "namespacedServiceAccountTokens": "[redacted]",
            "namespacedSshAuths": "https://localhost:8443/v3/projects/local:p-qt6tq/namespacedsshauths",
            "persistentVolumeClaims": "https://localhost:8443/v3/projects/local:p-qt6tq/persistentvolumeclaims",
            "pods": "https://localhost:8443/v3/projects/local:p-qt6tq/pods",
            "projectNetworkPolicies": "https://localhost:8443/v3/projects/local:p-qt6tq/projectnetworkpolicies",
            "projectRoleTemplateBindings": "https://localhost:8443/v3/projects/local:p-qt6tq/projectroletemplatebindings",
            "remove": "https://localhost:8443/v3/projects/local:p-qt6tq",
            "replicaSets": "https://localhost:8443/v3/projects/local:p-qt6tq/replicasets",
            "replicationControllers": "https://localhost:8443/v3/projects/local:p-qt6tq/replicationcontrollers",
            "secrets": "https://localhost:8443/v3/projects/local:p-qt6tq/secrets",
            "self": "https://localhost:8443/v3/projects/local:p-qt6tq",
            "serviceAccountTokens": "[redacted]",
            "services": "https://localhost:8443/v3/projects/local:p-qt6tq/services",
            "sshAuths": "https://localhost:8443/v3/projects/local:p-qt6tq/sshauths",
            "statefulSets": "https://localhost:8443/v3/projects/local:p-qt6tq/statefulsets",
            "subscribe": "https://localhost:8443/v3/projects/local:p-qt6tq/subscribe",
            "update": "https://localhost:8443/v3/projects/local:p-qt6tq",
            "workloads": "https://localhost:8443/v3/projects/local:p-qt6tq/workloads"
        },
        "name": "example-project",
        "namespaceDefaultResourceQuota": {
            "limit": {
                "type": "/v3/schemas/resourceQuotaLimit"
            },
            "type": "/v3/schemas/namespaceResourceQuota"
        },
        "namespaceId": null,
        "resourceQuota": {
            "limit": {
                "type": "/v3/schemas/resourceQuotaLimit"
            },
            "type": "/v3/schemas/projectResourceQuota",
            "usedLimit": {
                "type": "/v3/schemas/resourceQuotaLimit"
            }
        },
        "state": "active",
        "transitioning": "no",
        "transitioningMessage": "",
        "type": "project",
        "uuid": "b582603b-7826-4302-8393-792df2611265"
    }
}