[comment]: # translation:outdated

[comment]: # ({5024b934-780b1aa2})
# 12 Ограничавање провера агената

[comment]: # ({/5024b934-780b1aa2})

[comment]: # ({859d2fcd-9de656b2})
#### Преглед

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

Да бисте то урадили, користите комбинацију два параметра агента
[configuration](/manual/appendix/config/zabbix_agentd):

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

[comment]: # ({/859d2fcd-9de656b2})

[comment]: # ({3145c750-3145c750})
#### Важна правила

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

[comment]: # ({/3145c750-3145c750})

[comment]: # ({new-66ec4bb8})
#### 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:

```default
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:

```default
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.
```

[comment]: # ({/new-66ec4bb8})

[comment]: # ({253ad144-253ad144})
#### Случајеви употребе

[comment]: # ({/253ad144-253ad144})

[comment]: # ({new-19895d10})
##### Allowing specific checks and commands

Allow only two [`vfs.file`](/manual/config/items/itemtypes/zabbix_agent#vfs.file.cksum) item checks and two [`system.run`](/manual/config/items/itemtypes/zabbix_agent#system.run) commands:

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

::: noteclassic
Setting `DenyKey=system.run[*]` is unnecessary, because all other `system.run` commands are denied by default.
:::

[comment]: # ({/new-19895d10})

[comment]: # ({new-3cc5f239})
##### Allowing scripts

Allow Zabbix agent to execute scripts on hosts via all available methods:

-   [Global scripts](/manual/web_interface/frontend_sections/alerts/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](/manual/config/notifications/action/operation#operation-details) (this method always uses the `system.run[myscript.sh,nowait]` key)
-   [`system.run`](/manual/config/items/itemtypes/zabbix_agent#system.run) Zabbix agent items with the script, for example:
    -   `system.run[myscript.sh]`
    -   `system.run[myscript.sh,wait]`
    -   `system.run[myscript.sh,nowait]`

```default
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:

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

[comment]: # ({/new-3cc5f239})

[comment]: # ({new-1965a7d7})
##### Securing allow/deny rules

This example shows how to secure overly permissive `AllowKey` or `DenyKey` rules.

Consider the following rules:

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

::: noteclassic
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`](/manual/config/items/itemtypes/zabbix_agent#vfs.file.cksum) items require parameters.
-   The `system.cpu.load[*]` pattern matches only item keys with parameters; however [`system.cpu.load`](/manual/config/items/itemtypes/zabbix_agent#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:

```default
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`.

```bash
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]
```

[comment]: # ({/new-1965a7d7})

[comment]: # ({c560adaf-16bccaff})
#### Примери шаблона

|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\[\]<br>vfs.file.contents\[/путања/до/датотеке\]|vfs.file.contents|
|*vfs.file.contents\[/etc/passwd,\*\]*|Подудара се са `vfs.file.contents` са првим параметрима који се подударају са /etc/passwd и свим осталим параметрима који имају било коју вредност (такође празни).|vfs.file.contents\[/etc/passwd,\]<br>vfs.file.contents\[/etc/passwd,utf8\]|vfs.file.contents\[/etc/passwd\]<br>vfs.file.contents\[/var/log/zabbix\_server.log\]<br>vfs.file.contents\[\]|
|*vfs.file.contents\[\*passwd\*\]*|Подудара се са `vfs.file.contents` где је први параметр \*passwd\* и нема других параметара.|vfs.file.contents\[/etc/passwd\]|vfs.file.contents\[/etc/passwd,\]<br>vfs.file.contents\[/etc/passwd, utf8\]| 
|*vfs.file.contents\[\*passwd\*,\*\]*|Подудара се са `vfs.file.contents` где се само први параметар подудара са \*passwd\* и сви следећи параметри имају било коју вредност (такође празни).|vfs.file.contents\[/etc/passwd,\]<br>vfs.file.contents\[/etc/passwd, utf8\]|vfs.file.contents\[/etc/passwd\]<br>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\]<br>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,\]<br>vfs.file.contents\[/etc/passwd,utf16\]|
|*vfs.file.\**|Подудара се са било којим кључевима који почињу са `vfs.file.` без икаквих параметара.|vfs.file.contents<br>vfs.file.size|vfs.file.contents\[\]<br>vfs.file.size\[/var/log/zabbix\_server.log\]|
|*vfs.file.\*\[\*\]*|Подудара се са било којим кључем који почиње са `vfs.file.` са било којим параметрима.|vfs.file.size.bytes\[\]<br>vfs.file.size\[/var/log/zabbix\_server.log, utf8\]|vfs.file.size.bytes|
|*vfs.\*.contents*|Подудара се са било којим кључем који почиње са `vfs.` и завршава се са `.contents` без икаквих параметара.|vfs.mount.point.file.contents<br>vfs..contents|vfs.contents|

[comment]: # ({/c560adaf-16bccaff})
