12 Aģenta pārbaužu ierobežošana

Pārskats

Jūs varat kontrolēt, kurus vienumu atslēgu nosaukumus Zabbix aģents vai aģents 2 drīkst vai nedrīkst izmantot, izpildot vienumu pārbaudes, attālinātās komandas vai skriptus.

Lai to izdarītu, izmantojiet šos aģenta konfigurācijas parametrus, lai definētu atļaušanas/aizliegšanas noteikumus:

  • AllowKey=<pattern>
  • DenyKey=<pattern>
  • AllowKeyRegexp=<pattern>
  • DenyKeyRegexp=<pattern>

<pattern> jāietver viena vienuma atslēga.
Parametriem AllowKey un DenyKey <pattern> atbalsta aizstājējzīmes (*). Aizstājējzīme atbilst jebkuram jebkādu rakstzīmju skaitam savā pozīcijā, un to var izmantot, lai atbilstinātu vienumu atslēgas vai parametrus (piem., vfs.file.*[*]).
Parametriem AllowKeyRegexp un DenyKeyRegexp <pattern> atbalsta regulārās izteiksmes. Regulārās izteiksmes paraugu var izmantot, lai atbilstinātu vienumu atslēgas un to parametru virknes. Skatiet arī pareizas atsoļošanas piemērus.
Lūdzu, ņemiet vērā, ka Zabbix aģents un Zabbix aģents 2 var atbalstīt atšķirīgu regulāro izteiksmju sintaksi.

Lai uzlabotu drošību, ieteicams AllowKey un DenyKey vietā izmantot precīzas vienumu atslēgas, nevis aizstājējzīmes. Tāpat ieteicams AllowKeyRegexp un DenyKeyRegexp izmantot pēc iespējas specifiskākus regulāro izteiksmju paraugus. Sīkāku informāciju skatiet sadaļā Allow/deny noteikumu aizsardzība.

Atšķirībā no citiem aģenta konfigurācijas parametriem, jūs varat norādīt neierobežotu skaitu AllowKey, DenyKey, AllowKeyRegexp vai DenyKeyRegexp parametru.

Svarīgas piezīmes

  • Visi system.run vienumi pēc noklusējuma ir atspējoti (pat ja DenyKey un DenyKeyRegexp ir tukši), it kā būtu iestatīts DenyKey=system.run[*] vai DenyKeyRegexp=^system\.run\[.*\]$pēdējais noteikums. Tāpēc varat atļaut konkrētus system.run vienumus, nepārprotami nenoraidot citus system.run vienumus.

  • Ja iespējams, izmantojiet AllowKey/AllowKeyRegexp, lai atļautu tikai nepieciešamos vienumus un noraidītu visu pārējo. Dažus atslēgu nosaukumus var izmantot ļaunprātīgi, lai, izmantojot ceļa pārlūkošanu, nolasītu neparedzētus failus (piem., vfs.file.contents["../../../../etc/passwd"]), un jaunās Zabbix aģents versijas var ieviest atslēgas, kuras jūsu DenyKey/DenyKeyRegexp noteikumi nesedz.

  • AllowKey, DenyKey, AllowKeyRegexp un DenyKeyRegexp konfigurācija neietekmē HostnameItem, HostMetadataItem vai HostInterfaceItem aģents parametrus.

  • Noraidītie vienumi kļūst neatbalstīti bez jebkādām norādēm vai kļūdas ziņojumiem; piemēram:

    • Zabbix aģents komandrindas parametrs --print (-p) nerādīs noraidīto vienumu atslēgas.
    • Zabbix aģents komandrindas parametrs --test (-t) noraidītajām vienumu atslēgām atgriezīs "Unsupported item key.".
    • Kad reģistrēšana ir aktivizēta (LogRemoteCommands=1), Zabbix aģents žurnālfailā netiks reģistrētas noraidītās attālās komandas.

Atļaušanas/noraidīšanas noteikumu secība

Jūs varat norādīt neierobežotu skaitu AllowKey, DenyKey, AllowKeyRegexp vai DenyKeyRegexp noteikumu, lai gan to secībai ir nozīme.

  • Noteikumi tiek izvērtēti pa vienam, no augšas uz leju.
  • Kad vienuma atslēga atbilst noteikumam, tā tiek vai nu atļauta, vai noraidīta, un noteikumu izvērtēšana tiek pārtraukta.

Piemēram, izvērtējot vfs.file.contents[/etc/passwd], noteikumi tiek apstrādāti šādi:

AllowKey=vfs.file.contents[/tmp/app.log]    # Vienuma atslēgas paraugs neatbilst, aģents pāriet uz nākamo noteikumu.
AllowKey=vfs.file.contents[/etc/passwd]     # Vienuma atslēgas paraugs atbilst; aģents atļauj vienuma pārbaudi un pārtrauc noteikumu izvērtēšanu.
DenyKey=vfs.file.*[*]                       # Aģents ignorē noteikumu, jo izvērtēšana jau ir pārtraukta.

Šāda noteikumu secība noraidīs vienuma pārbaudi:

DenyKey=vfs.file.*[*]                       # Vienuma atslēgas paraugs atbilst; aģents noraida vienuma pārbaudi un pārtrauc noteikumu izvērtēšanu.
AllowKey=vfs.file.contents[/etc/passwd]     # Aģents ignorē noteikumu, jo izvērtēšana jau ir pārtraukta.
AllowKey=vfs.file.contents[/tmp/app.log]    # Aģents ignorē noteikumu, jo izvērtēšana jau ir pārtraukta.

Piemēri

Tālāk redzamie piemēri parāda biežāk sastopamos konfigurācijas modeļus AllowKey, DenyKey, AllowKeyRegexp un DenyKeyRegexp.

Konkrētu pārbažu un komandu atļaušana

Atļaujiet tikai divas vfs.file vienums pārbaudes un divas system.run komandas:

izmantojot AllowKey un DenyKey:

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

izmantojot AllowKeyRegexp un DenyKeyRegexp:

AllowKeyRegexp=^vfs\.file\.(contents|size)\[/tmp/app\.log\]$
AllowKeyRegexp=^system\.run\[/usr/bin/(uptime|df -h /)\]$
DenyKeyRegexp=^vfs\.file\..*\[.*\]$

Iestatījums DenyKey=system.run[*] vai DenyKeyRegexp=^system\.run\[.*\]$ nav nepieciešams, jo visas pārējās system.run komandas pēc noklusējuma tiek liegtas.

Skriptu atļaušana

Atļaujiet Zabbix aģentam izpildīt skriptus uz hosts, izmantojot visas pieejamās metodes:

  • Globālie skripti, kurus var izpildīt lietotāja saskarnē vai caur API (šī metode vienmēr izmanto system.run[myscript.sh] atslēgu)
  • Attālinātās komandas no darbību operācijām (šī metode vienmēr izmanto system.run[myscript.sh,nowait] atslēgu)
  • system.run Zabbix aģenta vienumi ar skriptu, piemēram:
    • system.run[myscript.sh]
    • system.run[myscript.sh,wait]
    • system.run[myscript.sh,nowait]
AllowKey=system.run[myscript.sh,*]

vai

AllowKeyRegexp=^system\.run\[myscript\.sh,.*\]$

Lai kontrolētu wait/nowait parametru, jums jāiestata atšķirīgs noteikums. Piemēram, varat atļaut tikai system.run[myscript.sh,wait] vienumus, tādējādi izslēdzot citas metodes:

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

vai

AllowKeyRegexp=^system\.run\[myscript\.sh,wait\]$
Drošības nodrošināšana allow/deny noteikumiem

Šie piemēri parāda, kā nodrošināt pārlieku atļaujošus AllowKey/AllowKeyRegexp vai DenyKey/DenyKeyRegexp noteikumus.

Apsveriet šādus noteikumus:

izmantojot AllowKey un DenyKey:

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

izmantojot AllowKeyRegexp un DenyKeyRegexp:

AllowKeyRegexp=^system\.run\["C:\\Program\sFiles\\Zabbix\sAgent\s2\\scripts\\test\.bat.*"\]$
DenyKeyRegexp=^vfs\.file\..*$
DenyKeyRegexp=^system\.cpu\.load\[.*\]$

Operētājsistēmā Windows ceļā atstarpes ir jāekranē, izmantojot caret (^) AllowKey vai DenyKey gadījumā un \s AllowKeyRegexp vai DenyKeyRegexp gadījumā.

Šie noteikumi satur aizstājējzīmi (*) (vai .* regulāro izteiksmju bāzētiem paraugiem), ko var izmantot neatbilstoši:

  • test.bat skriptu var izpildīt ar jebkādiem argumentiem, tostarp ar neparedzētiem.
  • vfs.file.* (^vfs\.file\..*$) paraugs atbilst vienumu atslēgām gan ar parametriem, gan bez tiem; tomēr visiem vfs.file vienumiem ir nepieciešami parametri.
  • system.cpu.load[*] (^system\.cpu\.load\[.*\]$) paraugs atbilst tikai vienumu atslēgām ar parametriem; tomēr system.cpu.load vienumiem parametri nav nepieciešami.

Lai šos noteikumus padarītu drošus, skaidri atļaujiet test.bat izpildi tikai ar konkrētiem argumentiem un aizliedziet pareizus vienumu atslēgu paraugus; piemēram:

izmantojot AllowKey un DenyKey:

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

izmantojot AllowKeyRegexp un DenyKeyRegexp:

AllowKeyRegexp=^system\.run\["C:\\Program\sFiles\\Zabbix\sAgent\s2\\scripts\\test\.bat (status|version)"\]$
DenyKeyRegexp=^vfs\.file\..+\[.*\]$
DenyKeyRegexp=^system\.cpu\.load(\[.*\])?$

Varat pārbaudīt noteikumus, izpildot šādas komandas, kas atgriezīs 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]
Rakstu paraugi

Tālāk redzamajās tabulās ir parādīts, kā tiek salīdzināti vienuma atslēgu paraugi:

  • Atslēga atbilst paraugam tikai tad, ja tā atbilst visiem nosacījumiem kolonnā Matches.
  • Parametriem pilnībā jāatrodas kvadrātiekavās (piem., vfs.file.contents[* un vfs.file.contents*utf8] ir nederīgi paraugi).
  • Piemēri ilustrē tikai paraugu salīdzināšanu; faktiskajiem vienumiem ir nepieciešami parametri.

Attiecībā uz AllowKey un DenyKey:

Pattern Matches Examples
* Jebkura atslēga ar parametriem vai bez tiem
vfs.file.* Atslēga sākas ar vfs.file.
Ar parametriem vai bez tiem
Matches:
vfs.file.size
vfs.file.contents
vfs.file.contents[]
vfs.file.size[/var/log/app.log]
vfs.*.contents Atslēga sākas ar vfs.
Atslēga beidzas ar .contents
Bez parametriem
Matches:
vfs..contents
vfs.mount.point.file.contents

Does not match:
vfs.contents
vfs.file.contents[]
vfs.file.*[*] Atslēga sākas ar vfs.file.
Jebkuri vai tukši parametri
Matches
vfs.file.get.custom[]
vfs.file.size[/var/log/app.log, utf8]

Does not match:
vfs.file.get.custom
vfs.file.contents Atslēga ir vfs.file.contents
Bez parametriem
Matches:
vfs.file.contents

Does not match:
vfs.file.contents[/etc/passwd]
vfs.file.contents[] Atslēga ir vfs.file.contents[]
Tukši parametri
Matches:
vfs.file.contents[]

Does not match:
vfs.file.contents
vfs.file.contents[*] Atslēga ir vfs.file.contents
Jebkuri vai tukši parametri
Matches:
vfs.file.contents[/path/to/file]

Does not match:
vfs.file.contents
vfs.file.contents[/etc/passwd,*] Atslēga ir vfs.file.contents
Pirmais parametrs ir /etc/passwd
Jebkurš vai tukšs otrais parametrs
Matches:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[]
vfs.file.contents[/etc/passwd]
vfs.file.contents[*passwd*] Atslēga ir vfs.file.contents
Jebkuri parametri, vismaz viens satur passwd
Matches:
vfs.file.contents[/etc/passwd]
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]
vfs.file.contents[*passwd*,*] Atslēga ir vfs.file.contents
Pirmais parametrs satur passwd
Jebkurš vai tukšs otrais parametrs
Matches:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[/etc/passwd]
vfs.file.contents[/tmp/test]
vfs.file.contents[/etc/passwd,utf8] Atslēga ir vfs.file.contents
Pirmais parametrs ir /etc/passwd
Otrais parametrs ir utf8
Matches:
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf16]

Attiecībā uz AllowKeyRegexp un DenyKeyRegexp:

Pattern Matches Examples
^.*$ Jebkura atslēga ar parametriem vai bez tiem
^vfs\.file\..*$ Atslēga sākas ar vfs.file.
Ar parametriem vai bez tiem
Matches:
vfs.file.size
vfs.file.contents
vfs.file.contents[]
vfs.file.size[/var/log/app.log]
^vfs\..*\.contents$ Atslēga sākas ar vfs.
Atslēga beidzas ar .contents
Bez parametriem
Matches:
vfs..contents
vfs.mount.point.file.contents

Does not match:
vfs.contents
vfs.file.contents[]
^vfs\.file\..*\[.*\]$ Atslēga sākas ar vfs.file.
Jebkuri vai tukši parametri
Matches
vfs.file.get.custom[]
vfs.file.size[/var/log/app.log, utf8]

Does not match:
vfs.file.get.custom
^vfs\.file\.contents$ Atslēga ir vfs.file.contents
Bez parametriem
Matches:
vfs.file.contents

Does not match:
vfs.file.contents[/etc/passwd]
^vfs\.file\.contents\[\]$ Atslēga ir vfs.file.contents[]
Tukši parametri
Matches:
vfs.file.contents[]

Does not match:
vfs.file.contents
^vfs\.file\.contents\[.*\]$ Atslēga ir vfs.file.contents
Jebkuri vai tukši parametri
Matches:
vfs.file.contents[/path/to/file]

Does not match:
vfs.file.contents
^vfs\.file\.contents\[/etc/passwd,.*\]$ Atslēga ir vfs.file.contents
Pirmais parametrs ir /etc/passwd
Jebkurš vai tukšs otrais parametrs
Matches:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[]
vfs.file.contents[/etc/passwd]
^vfs\.file\.contents\[.*passwd.*\]$ Atslēga ir vfs.file.contents
Jebkuri parametri, vismaz viens satur passwd
Matches:
vfs.file.contents[/etc/passwd]
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]
^vfs\.file\.contents\[.*passwd.*,.*\]$ Atslēga ir vfs.file.contents
Pirmais parametrs satur passwd
Jebkurš vai tukšs otrais parametrs
Matches:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf8]

Does not match:
vfs.file.contents[/etc/passwd]
vfs.file.contents[/tmp/test]
^vfs\.file\.contents\[/etc/passwd,(utf8|windows-1252)\]$ Atslēga ir vfs.file.contents
Pirmais parametrs ir /etc/passwd
Otrais parametrs ir utf8 vai windows-1252
Matches:
vfs.file.contents[/etc/passwd,utf8]
vfs.file.contents[/etc/passwd,windows-1252]

Does not match:
vfs.file.contents[/etc/passwd,]
vfs.file.contents[/etc/passwd,utf16]