Esta é uma tradução da página de documentação original em inglês. Ajude-nos a torná-la melhor.

13 Restringindo verificações de agentes

Visão geral

É possível restringir as verificações do lado do agente criando um item lista negra, uma lista branca ou uma combinação de lista branca/lista negra.

Para fazer isso, use uma combinação de dois agentes configuração parâmetros:

  • AllowKey=<pattern> - quais verificações são permitidas; <padrão> é especificado usando uma expressão curinga (*)
  • DenyKey=<pattern> - quais verificações são negadas; <padrão> é especificado usando uma expressão curinga (*)

Observe que:

  • Todos os itens system.run[*] (comandos remotos, scripts) são desabilitados por padrão, mesmo quando nenhuma chave de negação é especificada;
  • Desde o Zabbix 5.0.2 o parâmetro do agente EnableRemoteCommands é:
   * obsoleto pelo agente Zabbix
          * não suportado pelo agente Zabbix2

Portanto, para permitir todos os comandos remotos, especifique um parâmetro AllowKey=system.run[*]. Para permitir apenas alguns comandos remotos, crie uma lista branca de comandos específicos do system.run[]. Para não permitir comandos remotos específicos, adicione parâmetros DenyKey com system.run[] comandos antes do parâmetro AllowKey=system.run[*].

Regras importantes

  • Uma lista branca sem uma regra de negação só é permitida para system.run[*] Itens. Para todos os outros itens, os parâmetros AllowKey não são permitidos sem um parâmetro DenyKey; neste caso o agente Zabbix não irá start apenas com parâmetros AllowKey.
  • A ordem importa. Os parâmetros especificados são verificados um a um de acordo com sua ordem de aparência no arquivo de configuração:
    • Assim que uma chave de item corresponder a uma regra de permissão/negação, o item será permitido ou negado; e a verificação de regras pára. Então, se um item corresponde a uma regra de permissão e uma regra de negação, o resultado será depende de qual regra vem primeiro.
    • A ordem afeta também o parâmetro EnableRemoteCommands (se usado).
  • Números ilimitados de parâmetros AllowKey/DenyKey são suportados.
  • As regras AllowKey, DenyKey não afetam HostnameItem, Parâmetros de configuração HostMetadataItem, HostInterfaceItem.
  • O padrão de chave é uma expressão curinga em que o curinga (*) caractere corresponde a qualquer número de caracteres em determinada posição. Pode ser usado tanto no nome da chave quanto nos parâmetros.
  • Se uma chave de item específica não for permitida na configuração do agente, o item será relatado como não suportado (nenhuma dica é dada quanto ao razão);
  • O agente Zabbix com a opção de linha de comando --print (-p) não será exibido chaves que não são permitidas pela configuração;
  • O agente Zabbix com a opção de linha de comando --test (-t) retornará "Chave de item não compatível." status para chaves que não são permitidas por configuração;
  • Comandos remotos negados não serão registrados no log do agente (se 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.

Casos de uso

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]

Exemplos de padrões

Padrão Descrição Correspondências Sem correspondência
* Corresponde a todas as chaves possíveis com ou sem parâmetros. Qualquer Nenhum
vfs.file.contents Corresponde a vfs.file.contents sem parâmetros. vfs.file.contents vfs.file.contents[/etc/passwd]
vfs.file.contents[] Corresponde vfs.file.contents com parâmetros vazios. vfs.file.contents[] vfs.file.contents
vfs.file.contents[*] Corresponde vfs.file.contents com quaisquer parâmetros; não corresponderá a vfs.file.contents sem colchetes. vfs.file.contents[]
vfs.file.contents[/path/to/file]
vfs.file.contents
vfs.file.contents[/etc/passwd,*] Corresponde vfs.file.contents com os primeiros parâmetros correspondentes a /etc/passwd e todos os outros parâmetros com qualquer valor (também vazio). 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*] Corresponde vfs.file.contents com o primeiro parâmetro correspondente a *passwd* e nenhum outro parâmetro. vfs.file.contents[/etc /passwd] vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd, utf8]
vfs.file.contents[*passwd*,*] Corresponde a vfs.file.contents apenas com o primeiro parâmetro correspondente a *passwd* e todos os parâmetros seguintes com qualquer valor (também vazio) . vfs.file.contents[/etc/passwd,]
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] Corresponde vfs.file.contents com o primeiro parâmetro correspondente a /var/log/zabbix_server.log , terceiro parâmetro correspondente a 'abc' e qualquer segundo parâmetro (também vazio). 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] Corresponde vfs.file.contents com o primeiro parâmetro correspondente a /etc/passwd, segundo parâmetro correspondente a 'utf8' e nenhum outro argumento. vfs. file.contents[/etc/passwd,utf8] vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf16]
vfs.file.* Corresponde a qualquer chave que comece com vfs.file. sem nenhum parâmetro. vfs.file.contents
vfs.file.size
vfs.file.contents[]< br>vfs.file.size[/var/log/zabbix_server.log]
vfs.file.*[*] Corresponde a qualquer chave que comece com vfs.file. com quaisquer parâmetros. vfs.file.size.bytes[]
vfs.file. size[/var/log/zabbix_server.log, utf8]
vfs.file.size.bytes
vfs.*.contents Corresponde a qualquer chave começando com vfs. e terminando com .contents sem nenhum parâmetro. vfs.mount.point.file.contents
vfs..contents
vfs. conteúdo