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

12 Ограничавање провера агената

Преглед

Могуће је ограничити провере на страни агента креирањем ставке црна листа, бела листа или комбинација беле листе/црне листе.

Да бисте то урадили, користите комбинацију два средства конфигурација параметри:

  • AllowKey=<pattern> - које провере су дозвољене; <pattern> је наведен коришћењем џокер (*) израза
  • DenyKey=<pattern> - које провере су одбијене; <pattern> је наведен коришћењем џокер (*) израза

Имајте на уму да:

  • Све ставке system.run[*] (удаљене команде, скрипте) су подразумевано онемогућене, чак и када нису наведени кључеви за одбијање, требало би претпоставити да је DenyKey=system.run[*] имплицитно додат.
  • Од Zabbix 5.0.2 параметар агента EnableRemoteCommands је:
    • застарео Zabbix агент
    • Zabbix агент2 не подржава

Стога, да бисте дозволили удаљене команде, наведите AllowKey=system.run[<command>,*] за сваку дозвољену команду, * означава режим чекања и сада чекај. Такође је могуће навести AllowKey=system.run[*] параметар да дозволи све команде са режимима чекања и сада. Да бисте онемогућили одређене даљинске команде, додајте DenyKey параметре са system.run[] команде испред параметра AllowKey=system.run[*].

Важна правила

– Бела листа без правила одбијања је дозвољена само за систем.рун[*] ставке. За све остале ставке, AllowKey параметри нису дозвољени без DenyKey параметра; у овом случају Zabbix агент неће почни само са параметрима AllowKey. - Ред је битан. Наведени параметри се проверавају један по један према њиховом редоследу појављивања у конфигурационој датотеци: – Чим се кључ ставке поклопи са правилом за дозвољавање/одбијање, ставка је дозвољено или одбијено; и провера правила престаје. Дакле, ако ставка одговара и правилу дозволи и правилу одбијања, резултат ће зависи од тога које правило је прво. - Редослед утиче и на параметар EnableRemoteCommands (ако се користи). - Подржан је неограничен број параметара AllowKey/DenyKey. - AllowKey, DenyKey правила не утичу на HostnameItem, Конфигурациони параметри HostMetadataItem, HostInterfaceItem. - Кључни образац је џокер израз где је џокер (*) карактер одговара било ком броју било ког карактера на одређеној позицији. Може се користити и у називу кључа и у параметрима. - Ако је одређени кључ ставке недозвољен у конфигурацији агента, ставка ће бити пријављена као неподржана (не даје се наговештај за разлог); - Zabbix агент са --print (-p) опцијом командне линије се неће приказати кључеви који нису дозвољени конфигурацијом; - Zabbix агент са опцијом командне линије --test (-t) ће се вратити "Неподржани кључ ставке." статус за кључеве који нису дозвољени од конфигурација; - Одбијене даљинске команде неће бити евидентиране у дневнику агента (ако 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]

Примери шаблона

Pattern Description Matches No match
* Одговара свим могућим кључевима са или без параметара. Било који Ниједан
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,*] Одговара vfs.file.contents са првим параметрима који одговарају /etc/passwd и свим осталим параметрима који имају било коју вредност (такође празно). 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*] Подудара се са vfs.file.contents са првим параметром који се подудара са *passwd* и ниједним другим параметри. vfs.file.contents[/etc/passwd] vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd, utf8]
vfs.file.contents[*passwd*,*] Одговара vfs.file.contents са само првим параметром који одговара *passwd* и свим следећим параметрима који имају било коју вредност (такође празно). 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] Одговара vfs.file.contents са првим параметром који се подудара са /var/log/zabbix_server.log, трећи параметар који се подудара са 'abc' и било којим (такође празним) другим параметар. 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