これは開発版のドキュメントを表示しています。内容が不完全な場合があります。
このページには自動翻訳されたコンテンツが含まれています。 誤りを見つけた場合は、その箇所を選択して Ctrl+Enter を押し、編集者に報告してください。

12 エージェントチェックの制限

概要

エージェント側でアイテムのブラックリスト、ホワイトリスト、またはホワイトリスト/ブラックリストの組み合わせを作成することで、チェックを制限することができます。

そのためには、2つのエージェント設定パラメータを組み合わせて使用します:

  • AllowKey=<pattern> - 許可するチェック; <pattern>はワイルドカード(*)式で指定
  • DenyKey=<pattern> - 拒否するチェック; <pattern>はワイルドカード(*)式で指定

注意点:

  • すべてのsystem.run[*]アイテム(リモートコマンド、スクリプト)はデフォルトで無効です。deny keyが指定されていない場合でも、DenyKey=system.run[*]が暗黙的に追加されていると考えてください。
  • Zabbix 5.0.2以降、EnableRemoteCommandsエージェントパラメータは:
    • Zabbix agentでは非推奨
    • Zabbix agent2ではサポートされていません

したがって、リモートコマンドを許可するには、許可する各コマンドに対して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 の場合)

Allow/deny rule order

You can specify an unlimited number of AllowKey or DenyKey rules, though their order matters.

  • Rules are evaluated one by one, from top to bottom.
  • When an item key matches a rule, it is either allowed or denied, and rule evaluation stops.

For example, when evaluating vfs.file.contents[/etc/passwd], the rules are processed as follows:

AllowKey=vfs.file.contents[/tmp/app.log]    # Item key pattern does not match, agent proceeds to the next rule.
       AllowKey=vfs.file.contents[/etc/passwd]     # Item key pattern matches; agent allows the item check and stops rule evaluation.
       DenyKey=vfs.file.*[*]                       # Agent ignores the rule, as the evaluation has stopped.

The following rule order will deny the item check:

DenyKey=vfs.file.*[*]                       # Item key pattern matches; agent denies the item check and stops rule evaluation.
       AllowKey=vfs.file.contents[/etc/passwd]     # Agent ignores the rule, as the evaluation has stopped.
       AllowKey=vfs.file.contents[/tmp/app.log]    # Agent ignores the rule, as the evaluation has stopped.

使用例

Allowing specific checks and commands

Allow only two vfs.file item checks and two system.run commands:

AllowKey=vfs.file.contents[/tmp/app.log]
       AllowKey=vfs.file.size[/tmp/app.log]
       AllowKey=system.run[/usr/bin/uptime]
       AllowKey=system.run[/usr/bin/df -h /]
       DenyKey=vfs.file.*[*]

Setting DenyKey=system.run[*] is unnecessary, because all other system.run commands are denied by default.

Allowing scripts

Allow Zabbix agent to execute scripts on hosts via all available methods:

  • Global scripts that can be executed in the frontend or via API (this method always uses the system.run[myscript.sh] key)
  • Remote commands from action operations (this method always uses the system.run[myscript.sh,nowait] key)
  • system.run Zabbix agent items with the script, for example:
    • system.run[myscript.sh]
    • system.run[myscript.sh,wait]
    • system.run[myscript.sh,nowait]
AllowKey=system.run[myscript.sh,*]

To control the wait/nowait parameter, you must set a different rule. For example, you can allow only system.run[myscript.sh,wait] items, thus excluding other methods:

AllowKey=system.run[myscript.sh,wait]
Securing allow/deny rules

This example shows how to secure overly permissive AllowKey or DenyKey rules.

Consider the following rules:

AllowKey=system.run["C:\Program^ Files\Zabbix^ Agent^ 2\scripts\test.bat*"]
       DenyKey=vfs.file.*
       DenyKey=system.cpu.load[*]

On Windows, you must escape spaces in the path using a caret (^).

These rules contain a wildcard (*), which can be misused:

  • The test.bat script can be executed with any arguments, including unintended ones.
  • The vfs.file.* pattern matches only item keys without parameters; however, all vfs.file items require parameters.
  • The system.cpu.load[*] pattern matches only item keys with parameters; however system.cpu.load items do not require parameters.

To secure these rules, explicitly allow executing test.bat only with specific arguments, and deny correct item key patterns; for example:

AllowKey=system.run["C:\Program^ Files\Zabbix^ Agent^ 2\scripts\test.bat status"]
       AllowKey=system.run["C:\Program^ Files\Zabbix^ Agent^ 2\scripts\test.bat version"]
       DenyKey=vfs.file.*[*]
       DenyKey=system.cpu.load
       DenyKey=system.cpu.load[*]

You can test the rules by running the following commands, which will return ZBX_NOTSUPPORTED.

cd "C:\Program Files\Zabbix Agent 2"
       zabbix_agent2.exe -t system.run["C:\Program^ Files\Zabbix^ Agent^ 2\scripts\test.bat debug"]
       zabbix_agent2.exe -t vfs.file.size["C:\ProgramData\MyApp\config.ini"]
       zabbix_agent2.exe -t vfs.file.contents["C:\Windows\System32\drivers\etc\hosts"]
       zabbix_agent2.exe -t system.cpu.load
       zabbix_agent2.exe -t system.cpu.load[all,avg1]

パターン例

パターン 説明 一致 不一致
* パラメータの有無にかかわらず、すべてのキーに一致します。 すべて なし
vfs.file.contents パラメータなしのvfs.file.contentsに一致します。 vfs.file.contents vfs.file.contents[/etc/passwd]
vfs.file.contents[] 空のパラメータを持つvfs.file.contentsに一致します。 vfs.file.contents[] vfs.file.contents
vfs.file.contents[*] 任意のパラメータを持つvfs.file.contentsに一致します。角括弧なしのvfs.file.contentsには一致しません。 vfs.file.contents[]
vfs.file.contents[/path/to/file]
vfs.file.contents
vfs.file.contents[/etc/passwd,*] 最初のパラメータが/etc/passwdに一致し、他のすべてのパラメータが任意の値(空も含む)であるvfs.file.contentsに一致します。 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*] 最初のパラメータが*passwd*に一致し、他のパラメータがないvfs.file.contentsに一致します。 vfs.file.contents[/etc/passwd] vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd, utf8]
vfs.file.contents[*passwd*,*] 最初のパラメータが*passwd*に一致し、以降のすべてのパラメータが任意の値(空も含む)であるvfs.file.contentsに一致します。 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] 最初のパラメータが/var/log/zabbix_server.log、3番目のパラメータが'abc'、2番目のパラメータが任意(空も含む)であるvfs.file.contentsに一致します。 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] 最初のパラメータが/etc/passwd、2番目のパラメータが'utf8'で、他の引数がないvfs.file.contentsに一致します。 vfs.file.contents[/etc/passwd,utf8] vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf16]
vfs.file.* パラメータなしでvfs.file.で始まる任意のキーに一致します。 vfs.file.contents
vfs.file.size
vfs.file.contents[]
vfs.file.size[/var/log/zabbix_server.log]
vfs.file.*[*] 任意のパラメータを持つvfs.file.で始まる任意のキーに一致します。 vfs.file.size.bytes[]
vfs.file.size[/var/log/zabbix_server.log, utf8]
vfs.file.size.bytes
vfs.*.contents vfs.で始まり.contentsで終わるパラメータなしの任意のキーに一致します。 vfs.mount.point.file.contents
vfs..contents
vfs.contents