可以通过创建监控项来限制agent端的检查 黑名单、白名单或白名单/黑名单的组合。
为此,使用两个agent的组合 configuration 参数:
AllowKey=<pattern> - 允许执行哪些检查;<pattern>是 使用通配符(*)表达式指定
DenyKey=<pattern> - 哪些检查被拒绝; <pattern>是
specified using a wildcard (*) expression
请注意:
所有 system.run[*] 监控项(远程命令、脚本)默认被禁用 默认情况下,即使未指定任何拒绝密钥;
自Zabbix 5.0.2起,EnableRemoteCommands agent参数为:
因此,要允许远程命令,需指定 AllowKey=system.run[<command>,*] 对于每个允许的命令,* 代表等待和非等待模式。也可以指定 AllowKey=system.run[*] 参数用于允许所有带有wait和nowait模式的命令。要禁止特定的远程命令,需添加带有system.run[]的DenyKey参数 在AllowKey=system.run[*]参数之前的命令。
You can specify an unlimited number of AllowKey or DenyKey rules, though their order matters.
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.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.
Allow Zabbix agent to execute scripts on hosts via all available methods:
system.run[myscript.sh] key)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]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:
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:
test.bat script can be executed with any arguments, including unintended ones.vfs.file.* pattern matches only item keys without parameters; however, all vfs.file items require parameters.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、第三个参数为'abc'且第二个参数可为任意值(包括空值)的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] | 匹配 vfs.file.contents,其中第一个参数匹配/etc/passwd,第二个参数匹配'utf8'且无其他参数。 |
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 |