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

概要

アイテムチェック、リモートコマンド、またはスクリプトの実行時に、Zabbix エージェントまたはエージェント 2 が使用を許可または禁止されるアイテムキーを制御できます。

そのためには、許可/拒否ルールを定義するために、次の agent configuration パラメータを使用します。

  • AllowKey=<pattern>
  • DenyKey=<pattern>
  • AllowKeyRegexp=<pattern>
  • DenyKeyRegexp=<pattern>

<pattern> には単一のアイテムキーを含める必要があります。
AllowKeyDenyKey では、<pattern> はワイルドカード (*) をサポートします。 ワイルドカードは、その位置にある任意の数の任意の文字に一致し、アイテムキーまたはパラメータの一致に使用できます(例: vfs.file.*[*])。
AllowKeyRegexpDenyKeyRegexp では、<pattern>正規表現 をサポートします。 正規表現パターンは、アイテムキーおよびそのパラメータ文字列の一致に使用できます。 正しいエスケープ の例も参照してください。
Zabbix エージェントと Zabbix エージェント 2 では、サポートされる正規表現の構文が異なる場合があることに注意してください。

セキュリティを向上させるため、AllowKeyDenyKey ではワイルドカードではなく正確なアイテムキーを使用することを推奨します。 また、AllowKeyRegexpDenyKeyRegexp では、できるだけ具体的な正規表現パターンを使用することを推奨します。 詳細は、許可/拒否ルールの保護 を参照してください。

他のエージェント設定パラメータとは異なり、AllowKeyDenyKeyAllowKeyRegexpDenyKeyRegexp パラメータは無制限に指定できます。

重要な注意事項

  • すべてのsystem.runアイテムはデフォルトで無効です(DenyKeyDenyKeyRegexp が空の場合でも)。これは、DenyKey=system.run[*] または DenyKeyRegexp=^system\.run\[.*\]$最後のルールとして設定されている場合と同じです。 そのため、他の system.run アイテムを明示的に拒否しなくても、特定の system.run アイテムのみを許可できます。

  • 可能であれば、AllowKey/AllowKeyRegexp を使用して必要なアイテムのみを許可し、それ以外はすべて拒否してください。 一部のキーは、パストラバーサルを通じて意図しないファイルを読み取るために悪用される可能性があります(例: vfs.file.contents["../../../../etc/passwd"])。また、新しい Zabbix エージェントのバージョンでは、DenyKey/DenyKeyRegexp ルールでカバーされていないキーが追加される場合があります。

  • AllowKeyDenyKeyAllowKeyRegexp、および DenyKeyRegexp の設定は、HostnameItemHostMetadataItem、または HostInterfaceItem のエージェントパラメータには影響しません。

  • 拒否されたアイテムは、何のヒントやエラーメッセージもなくサポート対象外になります。たとえば、次のとおりです。

    • Zabbix エージェントの--print (-p)コマンドラインパラメータでは、拒否されたアイテムキーは表示されません。
    • Zabbix エージェントの--test (-t)コマンドラインパラメータでは、拒否されたアイテムキーに対して "Unsupported item key." が返されます。
    • ログ記録が有効化されている場合(LogRemoteCommands=1)、Zabbix エージェントのログファイルには拒否されたリモートコマンドは記録されません。

許可/拒否ルールの順序

AllowKeyDenyKeyAllowKeyRegexp、または DenyKeyRegexp のルールは無制限に指定できますが、順序が重要です。

  • ルールは上から下へ、1つずつ評価されます。
  • アイテムキーがあるルールに一致すると、そのアイテムは許可または拒否され、ルールの評価は停止します。

たとえば、vfs.file.contents[/etc/passwd] を評価する場合、ルールは次のように処理されます。

AllowKey=vfs.file.contents[/tmp/app.log]    # アイテムキーのパターンは一致せず、エージェントは次のルールへ進みます。
AllowKey=vfs.file.contents[/etc/passwd]     # アイテムキーのパターンが一致し、エージェントはアイテムチェックを許可してルール評価を停止します。
DenyKey=vfs.file.*[*]                       # 評価はすでに停止しているため、エージェントはこのルールを無視します。

次のルール順では、アイテムチェックは拒否されます。

DenyKey=vfs.file.*[*]                       # アイテムキーのパターンが一致し、エージェントはアイテムチェックを拒否してルール評価を停止します。
AllowKey=vfs.file.contents[/etc/passwd]     # 評価はすでに停止しているため、エージェントはこのルールを無視します。
AllowKey=vfs.file.contents[/tmp/app.log]    # 評価はすでに停止しているため、エージェントはこのルールを無視します。

以下の例では、AllowKeyDenyKeyAllowKeyRegexpDenyKeyRegexp の一般的な設定パターンを示します。

特定のチェックとコマンドを許可する

2つの vfs.file アイテムチェックと2つの system.run コマンドのみを許可します。

AllowKeyDenyKey を使用する場合:

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.*[*]

AllowKeyRegexpDenyKeyRegexp を使用する場合:

AllowKeyRegexp=^vfs\.file\.(contents|size)\[/tmp/app\.log\]$
AllowKeyRegexp=^system\.run\[/usr/bin/(uptime|df -h /)\]$
DenyKeyRegexp=^vfs\.file\..*\[.*\]$

DenyKey=system.run[*] または DenyKeyRegexp=^system\.run\[.*\]$ を設定する必要はありません。その他すべての system.run コマンドはデフォルトで拒否されるためです。

スクリプトの許可

Zabbix エージェントが、利用可能なすべての方法でホスト上のスクリプトを実行できるようにします。

  • Webインターフェースまたは API から実行できる グローバルスクリプト(この方法では常に system.run[myscript.sh] キーを使用します)
  • アクションのオペレーション からのリモートコマンド(この方法では常に system.run[myscript.sh,nowait] キーを使用します)
  • スクリプトを含む system.run Zabbix エージェントアイテム。たとえば、次のようになります。
    • system.run[myscript.sh]
    • system.run[myscript.sh,wait]
    • system.run[myscript.sh,nowait]
AllowKey=system.run[myscript.sh,*]

または

AllowKeyRegexp=^system\.run\[myscript\.sh,.*\]$

wait/nowait パラメーターを制御するには、別のルールを設定する必要があります。
たとえば、system.run[myscript.sh,wait] アイテムのみを許可し、他の方法を除外できます。

AllowKey=system.run[myscript.sh,wait]

または

AllowKeyRegexp=^system\.run\[myscript\.sh,wait\]$
Allow/deny ルールの保護

これらの例では、過度に許可範囲の広い AllowKey/AllowKeyRegexp または DenyKey/DenyKeyRegexp ルールを安全にする方法を示します。

次のルールを考えます。

AllowKeyDenyKey を使用する場合:

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

AllowKeyRegexpDenyKeyRegexp を使用する場合:

AllowKeyRegexp=^system\.run\["C:\\Program\sFiles\\Zabbix\sAgent\s2\\scripts\\test\.bat.*"\]$
DenyKeyRegexp=^vfs\.file\..*$
DenyKeyRegexp=^system\.cpu\.load\[.*\]$

Windows では、AllowKey または DenyKey ではパス内のスペースをキャレット (^) で、AllowKeyRegexp または DenyKeyRegexp では \s でエスケープする必要があります。

これらのルールにはワイルドカード (*)(正規表現ベースのパターンでは .*)が含まれており、悪用される可能性があります。

  • test.bat スクリプトは、意図しないものを含む任意の引数で実行できます。
  • vfs.file.* (^vfs\.file\..*$) パターンは、パラメータの有無にかかわらずアイテムキーに一致します。ただし、すべての vfs.file アイテムにはパラメータが必要です。
  • system.cpu.load[*] (^system\.cpu\.load\[.*\]$) パターンは、パラメータ付きのアイテムキーにのみ一致します。ただし、system.cpu.load アイテムにはパラメータは不要です。

これらのルールを安全にするには、test.bat の実行を特定の引数に対してのみ明示的に許可し、正しいアイテムキーのパターンを拒否します。例えば、次のようにします。

AllowKeyDenyKey を使用する場合:

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[*]

AllowKeyRegexpDenyKeyRegexp を使用する場合:

AllowKeyRegexp=^system\.run\["C:\\Program\sFiles\\Zabbix\sAgent\s2\\scripts\\test\.bat (status|version)"\]$
DenyKeyRegexp=^vfs\.file\..+\[.*\]$
DenyKeyRegexp=^system\.cpu\.load(\[.*\])?$

次のコマンドを実行してルールをテストできます。これらは 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]
パターンの例

以下の表は、アイテムキーのパターンがどのように一致するかを示しています。

  • キーがパターンに一致するのは、Matches 列の すべて の条件を満たす場合のみです。
  • パラメータは必ず角括弧で完全に囲む必要があります(例: vfs.file.contents[*vfs.file.contents*utf8] は無効なパターンです)。
  • これらの例はパターン一致のみを示しており、実際のアイテムにはパラメータが必要です。

AllowKeyDenyKey の場合:

Pattern Matches Examples
* パラメータの有無にかかわらず、任意のキー
vfs.file.* キーが vfs.file. で始まる
パラメータの有無にかかわらず
Matches:
vfs.file.size
vfs.file.contents
vfs.file.contents[]
vfs.file.size[/var/log/app.log]
vfs.*.contents キーが vfs. で始まる
キーが .contents で終わる
パラメータなし
Matches:
vfs..contents
vfs.mount.point.file.contents

Does not match:
vfs.contents
vfs.file.contents[]
vfs.file.*[*] キーが vfs.file. で始まる
任意のパラメータ、または空のパラメータ
Matches
vfs.file.get.custom[]
vfs.file.size[/var/log/app.log, utf8]

Does not match:
vfs.file.get.custom
vfs.file.contents キーが vfs.file.contents である
パラメータなし
Matches:
vfs.file.contents

Does not match:
vfs.file.contents[/etc/passwd]
vfs.file.contents[] キーが vfs.file.contents[] である
空のパラメータ
Matches:
vfs.file.contents[]

Does not match:
vfs.file.contents
vfs.file.contents[*] キーが vfs.file.contents である
任意のパラメータ、または空のパラメータ
Matches:
vfs.file.contents[/path/to/file]

Does not match:
vfs.file.contents
vfs.file.contents[/etc/passwd,*] キーが vfs.file.contents である
1つ目のパラメータが /etc/passwd
2つ目のパラメータは任意、または空
Matches:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[]
vfs.file.contents[/etc/passwd]
vfs.file.contents[*passwd*] キーが vfs.file.contents である
任意のパラメータで、少なくとも1つに passwd を含む
Matches:
vfs.file.contents[/etc/passwd]
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]
vfs.file.contents[*passwd*,*] キーが vfs.file.contents である
1つ目のパラメータに passwd を含む
2つ目のパラメータは任意、または空
Matches:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[/etc/passwd]
vfs.file.contents[/tmp/test]
vfs.file.contents[/etc/passwd,utf8] キーが vfs.file.contents である
1つ目のパラメータが /etc/passwd
2つ目のパラメータが utf8
Matches:
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf16]

AllowKeyRegexpDenyKeyRegexp の場合:

Pattern Matches Examples
^.*$ パラメータの有無にかかわらず、任意のキー
^vfs\.file\..*$ キーが vfs.file. で始まる
パラメータの有無にかかわらず
Matches:
vfs.file.size
vfs.file.contents
vfs.file.contents[]
vfs.file.size[/var/log/app.log]
^vfs\..*\.contents$ キーが vfs. で始まる
キーが .contents で終わる
パラメータなし
Matches:
vfs..contents
vfs.mount.point.file.contents

Does not match:
vfs.contents
vfs.file.contents[]
^vfs\.file\..*\[.*\]$ キーが vfs.file. で始まる
任意のパラメータ、または空のパラメータ
Matches
vfs.file.get.custom[]
vfs.file.size[/var/log/app.log, utf8]

Does not match:
vfs.file.get.custom
^vfs\.file\.contents$ キーが vfs.file.contents である
パラメータなし
Matches:
vfs.file.contents

Does not match:
vfs.file.contents[/etc/passwd]
^vfs\.file\.contents\[\]$ キーが vfs.file.contents[] である
空のパラメータ
Matches:
vfs.file.contents[]

Does not match:
vfs.file.contents
^vfs\.file\.contents\[.*\]$ キーが vfs.file.contents である
任意のパラメータ、または空のパラメータ
Matches:
vfs.file.contents[/path/to/file]

Does not match:
vfs.file.contents
^vfs\.file\.contents\[/etc/passwd,.*\]$ キーが vfs.file.contents である
1つ目のパラメータが /etc/passwd
2つ目のパラメータは任意、または空
Matches:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[]
vfs.file.contents[/etc/passwd]
^vfs\.file\.contents\[.*passwd.*\]$ キーが vfs.file.contents である
任意のパラメータで、少なくとも1つに passwd を含む
Matches:
vfs.file.contents[/etc/passwd]
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]
^vfs\.file\.contents\[.*passwd.*,.*\]$ キーが vfs.file.contents である
1つ目のパラメータに passwd を含む
2つ目のパラメータは任意、または空
Matches:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[/etc/passwd]
vfs.file.contents[/tmp/test]
^vfs\.file\.contents\[/etc/passwd,(utf8|windows-1252)\]$ キーが vfs.file.contents である
1つ目のパラメータが /etc/passwd
2つ目のパラメータが utf8 または windows-1252
Matches:
vfs.file.contents[/etc/passwd,utf8]
vfs.file.contents[/etc/passwd,windows-1252]

Does not match:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf16]