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

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

Преглед

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

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

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

Important rules

  • A whitelist without a deny rule is only allowed for system.run[*] items. For all other items, AllowKey parameters are not allowed without a DenyKey parameter; in this case Zabbix agent will not start with only AllowKey parameters.
  • The order matters. The specified parameters are checked one by one according to their appearance order in the configuration file:
    • As soon as an item key matches an allow/deny rule, the item is either allowed or denied; and rule checking stops. So if an item matches both an allow rule and a deny rule, the result will depend on which rule comes first.
    • The order affects also EnableRemoteCommands parameter (if used).
  • Unlimited numbers of AllowKey/DenyKey parameters is supported.
  • AllowKey, DenyKey rules do not affect HostnameItem, HostMetadataItem, HostInterfaceItem configuration parameters.
  • Key pattern is a wildcard expression where the wildcard (*) character matches any number of any characters in certain position. It might be used in both the key name and parameters.
  • If a specific item key is disallowed in the agent configuration, the item will be reported as unsupported (no hint is given as to the reason);
  • Zabbix agent with --print (-p) command line option will not show keys that are not allowed by configuration;
  • Zabbix agent with --test (-t) command line option will return "Unsupported item key." status for keys that are not allowed by configuration;
  • Denied remote commands will not be logged in the agent log (if LogRemoteCommands=1).

Случајеви употребе

Одбиј специфичну проверу
  • Ставите на црну листу одређену проверу помоћу параметра DenyKey. Одговарајући кључеви биће забрањено. Сви неподударни кључеви ће бити дозвољени, осим system.run[] ставке.

на пример:

# Забраните сигуран приступ подацима
       DenyKey=vfs.file.contents[/etc/passwd,*]

Црна листа можда није добар избор, јер а нова Zabbix верзија може имати нове кључеве који нису експлицитно ограничени по постојећој конфигурацији. Ово може изазвати сигурност мана.

Одбиј одређену команду, дозволи другима
  • Ставите на црну листу одређену команду са параметром DenyKey. Бела листа свих друге команде, са параметром AllowKey.
# Забрани одређену команду
       DenyKey=system.run[ls -l /]
        
       # Дозволи друге скрипте
       AllowKey=system.run[*]
Дозволи посебне провере, одбиј друге
  • Бели списак специфичних провера са AllowKey параметрима, одбијте друге са DenyKey=*

на пример:

# Дозволи читање дневника:
       AllowKey==vfs.file.*[/var/log/*]
       
       # Дозволи провере по локалном времену
       AllowKey=system.localtime[*]
       
       # Одбијте све друге кључеве
       DenyKey=*
Дозволи скрипту са размацима у путањи и аргументима
  • Стави на белу листу скрипту која се налази у путањи која садржи размаке и дозволи прослеђивање аргумената њој. У оперативном систему Windows, избегавајте размаке користећи ^ приликом навођења путање.

На пример:

# Дозволи покретање test.bat са или без аргумената AllowKey=system.run["C:^ Files^ Agent^ 2.bat*"]

За тестирање:

PS C:\Program Files\Zabbix Agent 2> .\zabbix_get.exe -s 127.0.0.1 -k system.run["C:\Program^ Files\Zabbix^ Agent^ 2\scripts\test.bat caret"]

Ова конфигурација омогућава извршавање скрипте без обзира на то да ли су прослеђени аргументи (као што је caret) и осигурава да је system.run дозвољено чак и ако путања скрипте садржи размаке.

Pattern examples

Pattern Description Matches No match
* Matches all possible keys with or without parameters. Any None
vfs.file.contents Matches vfs.file.contents without parameters. vfs.file.contents vfs.file.contents[/etc/passwd]
vfs.file.contents[] Matches vfs.file.contents with empty parameters. vfs.file.contents[] vfs.file.contents
vfs.file.contents[*] Matches vfs.file.contents with any parameters; will not match vfs.file.contents without square brackets. vfs.file.contents[]
vfs.file.contents[/path/to/file]
vfs.file.contents
vfs.file.contents[/etc/passwd,*] Matches vfs.file.contents with first parameters matching /etc/passwd and all other parameters having any value (also empty). 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*] Matches vfs.file.contents with first parameter matching *passwd* and no other parameters. vfs.file.contents[/etc/passwd] vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd, utf8]
vfs.file.contents[*passwd*,*] Matches vfs.file.contents with only first parameter matching *passwd* and all following parameters having any value (also empty). 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] Matches vfs.file.contents with first parameter matching /var/log/zabbix_server.log, third parameter matching 'abc' and any (also empty) second parameter. 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] Matches vfs.file.contents with first parameter matching /etc/passwd, second parameter matching 'utf8' and no other arguments. vfs.file.contents[/etc/passwd,utf8] vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf16]
vfs.file.* Matches any keys starting with vfs.file. without any parameters. vfs.file.contents
vfs.file.size
vfs.file.contents[]
vfs.file.size[/var/log/zabbix_server.log]
vfs.file.*[*] Matches any keys starting with vfs.file. with any parameters. vfs.file.size.bytes[]
vfs.file.size[/var/log/zabbix_server.log, utf8]
vfs.file.size.bytes
vfs.*.contents Matches any key starting with vfs. and ending with .contents without any parameters. vfs.mount.point.file.contents
vfs..contents
vfs.contents

system.run и AllowKey

Хипотетичка скрипта попут 'myscript.sh' може се извршити на хосту путем Zabbix агента на неколико начина:

  1. Као кључ ставке у пасивној или активној провери, на пример:
  • system.run[myscript.sh]
  • system.run[myscript.sh,wait]
  • system.run[myscript.sh,nowait]

Овде корисник може додати "wait", "nowait" или изоставити други аргумент да би користио његову подразумевану вредност у system.run[].

  1. Као глобална скрипта (покренута од стране корисника у корисничком интерфејсу или API-ју).

Корисник конфигурише ову скрипту у УпозорењаСкрипте, поставља "Execute on: Zabbix agent" и ставља "myscript.sh" у поље за унос "Commands" скрипте. Када се позове са корисничког интерфејса или API-ја, Zabbix сервер шаље агенту:

  • system.run[myscript.sh,wait] - до Zabbix 5.0.4
  • system.run[myscript.sh] - од 5.0.5

Овде корисник не контролише параметре "wait"/"nowait".

3. Као удаљена команда из акције. Zabbix сервер шаље агенту:

  • system.run[myscript.sh,nowait]

Овде поново корисник не контролише параметре "wait"/"nowait".

То значи да ако подесимо AllowKey као:

AllowKey=system.run[myscript.sh]

онда

  • system.run[myscript.sh] - биће дозвољено
  • system.run[myscript.sh,wait], system.run[myscript.sh,nowait] неће бити дозвољено - скрипта се неће покренути ако се позове као корак акције

Да бисте дозволили све описане варијанте, можете додати:

AllowKey=system.run[myscript.sh,*] DenyKey=system.run[*]

параметрима agent/agent2.