This is a translation of the original English documentation page. Help us make it better.

13 agent チェックの制限

概要

item のブラックリスト、ホワイトリスト、またはホワイトリストとブラックリストの組み合わせを作成することで、agent 側で
チェックを制限することができます。

そのためには、2 つの agent configuration パラメータを組み合わせて使用します。

  • AllowKey=<pattern> - どの検査を許可するか、<pattern> はワイルドカード (*) 式を使用して指定します。
  • DenyKey=<pattern> - どの検査を拒否するか、<pattern> はワイルドカード (*) 式を使用して指定します。

なお:

  • denyキーが指定されていない場合でも、すべてのsystem.run[*]`アイテム(リモートコマンド、スクリプト)はデフォルトで 無効化されます。
  • Zabbix 5.0.2以降、EnableRemoteCommands agent パラメータは:
   * Zabbix agent では非推奨
          * Zabbix agent 2ではサポートされていません

そのため、リモートコマンドを許可するには、許可するコマンドごとに AllowKey=system.run[<command>,*] を指定します
( * は wait および nowait モードを表します)。AllowKey=system.run[*] パラメータを指定すると、wait および nowait
モードを持つすべてのコマンドを許可することも可能です。特定のリモートコマンドを許可しないようにするには、
AllowKey=system.run[ *] パラメータの前に system.run[] コマンドを含む DenyKey パラメータを追加してください。

重要ルール

  • deny ルールのないホワイトリストは、system.run[ *] アイテムに対してのみ許可されます。その他のアイテムでは、 DenyKey パラメータがない場合、AllowKey パラメータを使用することはできません。
  • 順番は重要です。指定されたパラメータは、設定ファイル内の表示順に従って1つずつチェックされます:
    • item キーが allow / deny ルールに一致すると、item は許可または拒否され、ルールチェックは停止されます。 したがって、ある item が allow ルールと deny ルールの両方にマッチした場合、どちらのルールが先に来るかによって 結果が異なります。
    • この順序は、EnableRemoteCommands パラメータにも影響します。(使用する場合)
  • AllowKey / DenyKey パラメータは無制限に使用できます。
  • AllowKey、DenyKeyルールは、HostnameItem、HostMetadataItem、HostInterfaceItem 構成パラメータには影響しません。
  • キーパターンは、ワイルドカード (*) 文字が特定の位置にある任意の数の文字と一致するワイルドカード式です。 キー名とパラメーターの両方で使用することができます。
  • 特定の item キーが agent 構成で許可されていない場合、その item はサポートされていないと報告されます。 (理由のヒントは与えられません)。
  • Zabbix agent に --print (-p) コマンドラインオプションを指定すると、設定により許可されていないキーは表示されません。
  • Zabbix agent の--test(-t)コマンドラインオプションを使用すると、設定で許可されていないキーに対して "Unsupported item key."というステータスが返されます。
  • 拒否されたリモートコマンドは agent ログに記録されません。(LogRemoteCommands=1 の場合)

使用例

特定のチェックを拒否する
  • DenyKeyパラメータで特定のチェックをブラックリスト化します。一致するキーは許可されません。一致しないキーは すべて許可されます。ただし、system.run[] 項目を除きます。

例えば:

# セキュアデータアクセスを拒否する
       DenyKey=vfs.file.contents[/etc/passwd,*]

Zabbixの新しいバージョンでは、既存の設定で明示的に制限されていない新しいキーが使用される可能性があるため、
ブラックリストは良い選択とは言えないかもしれません。これはセキュリティ上の欠陥を引き起こす可能性があります。

特定のコマンドを拒否し、他のコマンドを許可する
  • 特定のコマンドをブラックリスト化するには、DenyKeyパラメータを使用します。AllowKey パラメータを使用して、 他のすべてのコマンドをホワイトリストに登録します。
# 特定のコマンドを許可しない
       DenyKey=system.run[ls -l /]
        
       # 他のスクリプトを許可する
       AllowKey=system.run[*]
特定のチェックを許可し、他のチェックを拒否する
  • AllowKey パラメータで特定のチェックをホワイトリスト化し、DenyKey=*で他のチェックを拒否する。

例:

# Allow reading logs:
       AllowKey=vfs.file.*[/var/log/*]
       
       # Allow localtime checks
       AllowKey=system.localtime[*]
       
       # Deny all other keys
       DenyKey=*

パターンの例

パターン 説明 一致 非一致
* Matches all possible keys with or without parameters. Any None
vfs.file.contents Matches vfs.file.contents without parameters. vfs.file.contents vfs.file.contents[/etc/passwd]
vfs.file.contents[] Matches vfs.file.contents with empty parameters. vfs.file.contents[] vfs.file.contents
vfs.file.contents[*] Matches vfs.file.contents with any parameters; will not match vfs.file.contents without square brackets. vfs.file.contents[]
vfs.file.contents[/path/to/file]
vfs.file.contents
vfs.file.contents[/etc/passwd,*] Matches vfs.file.contents with first parameters matching /etc/passwd and all other parameters having any value (also empty). vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]
vfs.file.contents[/etc/passwd]
vfs.file.contents[/var/log/zabbix_server.log]
vfs.file.contents[]
vfs.file.contents[*passwd*] Matches vfs.file.contents with first parameter matching *passwd* and no other parameters. vfs.file.contents[/etc/passwd] vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd, utf8]
vfs.file.contents[*passwd*,*] Matches vfs.file.contents with only first parameter matching *passwd* and all following parameters having any value (also empty). vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd, utf8]
vfs.file.contents[/etc/passwd]
vfs.file.contents[/tmp/test]
vfs.file.contents[/var/log/zabbix_server.log,*,abc] Matches vfs.file.contents with first parameter matching /var/log/zabbix_server.log, third parameter matching 'abc' and any (also empty) second parameter. vfs.file.contents[/var/log/zabbix_server.log,,abc]
vfs.file.contents[/var/log/zabbix_server.log,utf8,abc]
vfs.file.contents[/var/log/zabbix_server.log,,abc,def]
vfs.file.contents[/etc/passwd,utf8] Matches vfs.file.contents with first parameter matching /etc/passwd, second parameter matching 'utf8' and no other arguments. vfs.file.contents[/etc/passwd,utf8] vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf16]
vfs.file.* Matches any keys starting with vfs.file. without any parameters. vfs.file.contents
vfs.file.size
vfs.file.contents[]
vfs.file.size[/var/log/zabbix_server.log]
vfs.file.*[*] Matches any keys starting with vfs.file. with any parameters. vfs.file.size.bytes[]
vfs.file.size[/var/log/zabbix_server.log, utf8]
vfs.file.size.bytes
vfs.*.contents Matches any key starting with vfs. and ending with .contents without any parameters. vfs.mount.point.file.contents
vfs..contents
vfs.contents

system.run と AllowKey

myscript.shのような仮想スクリプトは、Zabbix agent を介してホスト上でいくつかの方法で実行することができます:

1. passive チェック や active チェックの item キーとして、例えば :

  • system.run[myscript.sh]
  • system.run[myscript.sh,wait]
  • system.run[myscript.sh.nowait]

ここで、"wait"、"nowait "を追加するか、第2引数を省略し、system.run[ ]のデフォルト値を使用することができる。

2. グローバルスクリプトとして(フロントエンドまたはAPIでユーザーによって開始される)

ユーザはこのスクリプトを AdministrationScripts で "Commands" 入力フィールドに "myscript.sh" を入力し、
"Execute on: Zabbix agent" を設定します。フロントエンドまたはAPIから呼び出されると、Zabbixサーバは agent に以下を
送信します。:

  • system.run[myscript.sh,wait] - Zabbix 5.0.4 以前
  • system.run[myscript.sh] - 5.0.5から

ここでは、ユーザーは "wait"/"nowait "パラメータを制御しません。

3. アクションからのリモートコマンドとして Zabbix server は agent に送信します:

  • system.run[myscript.sh,nowait]

ここでも、ユーザーは "wait"/"nowait "パラメータを制御しません。

どういうことかというと、AllowKeyを次のように設定した場合です。:

AllowKey=system.run[myscript.sh]

では

  • system.run[myscript.sh] - 許可されます。
  • system.run[myscript.sh,wait], system.run[myscript.sh,nowait] 許可されません - アクションのステップとして起動された場合、スクリプトは実行されません。

上記のすべてのバリエーションを許可するには:

AllowKey=system.run[myscript.sh,*] 
       DenyKey=system.run[*]

を agent / agent 2 パラメータに設定します。