可以通过创建监控项来限制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[*]参数之前的命令。
使用DenyKey参数将特定检查项加入黑名单。匹配的键值
will be disallowed. All non-matching keys will be allowed, except system.run[] items.
例如:
黑名单可能不是最佳选择,因为 新版Zabbix version 可能包含未被现有配置明确限制的 新键值。这可能导致安全 漏洞。
使用DenyKey参数将特定命令加入黑名单。允许所有其他命令
other commands, with the AllowKey parameter.
DenyKey=*
拒绝其他所有项 DenyKey=*
例如:
# Allow reading logs:
AllowKey=vfs.file.*[/var/log/*]
# 允许localtime检查
AllowKey=system.localtime[*]
# 拒绝所有其他键值
DenyKey=*
模式 | 描述 | 匹配项 | 不匹配项 |
---|---|---|---|
* | 匹配所有带参数或不带参数的键。 | 任意 | 无 |
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 |
一个假设的脚本如'myscript.sh'可以通过以下几种方式在一个主机上通过Zabbix agent执行:
1. 作为被动或主动检查中的监控项键值,例如:
此处用户可以添加"wait"、"nowait"或省略第二个参数以使用system.run[]的默认值。
2. 作为全局脚本(由用户在前端或API中发起)。
用户在管理→脚本中配置此脚本,设置"执行于: Zabbix agent"并将"myscript.sh"放入脚本的"命令"输入字段。当从前端或API调用时,Zabbix服务器会向agent发送:
此处用户无法控制"wait"/"nowait"参数。
3. 作为来自动作的远程命令。Zabbix server会向agent发送:
同样地,此处用户也无法控制"wait"/"nowait"参数。
这意味着如果我们如下设置AllowKey:
那么
system.run[myscript.sh] - 将被允许
system.run[myscript.sh,wait], system.run[myscript.sh,nowait]
will not be allowed - the script will not be run if invoked as a step of action
要允许所有描述的变体,您可以添加:
到agent/agent2参数中。