13 הגבלת בדיקות סוכן

סקירה כללית

ניתן להגביל צ'קים בצד הסוכן על ידי יצירת פריט רשימה שחורה, רשימת לבנה או שילוב של רשימה לבנה/רשימה שחורה.

לשם כך השתמש בשילוב של שני סוכן configuration פרמטרים:

  • AllowKey=<pattern> - אילו בדיקות מותרות; <pattern> הוא צוין באמצעות ביטוי תו כללי (*).
  • DenyKey=<pattern> - אילו בדיקות נדחות; <pattern> הוא צוין באמצעות ביטוי תו כללי (*).

ציין זאת:

  • כל פריטי system.run[*] (פקודות מרחוק, סקריפטים) מושבתים על ידי ברירת מחדל, גם כאשר לא צוינו מפתחות הכחשה;
  • מאז Zabbix 5.0.2 הפרמטר EnableRemoteCommands agent הוא:
<!-- -->
    * הוצא משימוש על ידי סוכן Zabbix
    * לא נתמך על ידי סוכן Zabbix2

לכן, כדי לאפשר פקודות מרחוק, ציין AllowKey=system.run[<command>,*] עבור כל פקודה מותרת, * מייצג מצב wait and nowait. אפשר גם לציין פרמטר AllowKey=system.run[*] כדי לאפשר את כל הפקודות עם מצבי המתנה ועכשיו. כדי לא לאפשר פקודות מרוחקות ספציפיות, הוסף פרמטרים של DenyKey עם פקודות system.run[] לפני הפרמטר AllowKey=system.run[*].

כללים חשובים

  • רשימת היתרים ללא כלל דחייה מותרת רק עבור 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]

דוגמאות לתבניות

דפוס תיאור התאמות אין התאמה
* מתאים את כל המפתחות האפשריים עם או בלי פרמטרים. כל ללא
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]<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]
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[]< br>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. תוכן