polkitd是一個在Linux系統中廣泛使用的授權管理守護進程,它的作用是輕鬆控制用戶進程對系統資源進行訪問和操作。
一、polkitd用戶
polkitd以系統用戶的身份運行,通常是以root或polkitd用戶身份運行。在CentOS 7中,polkitd用戶是由系統會話服務處理的,而在CentOS 8中,polkitd用戶則默認由polkitd包提供。
polkitd用戶通常是被設計用來運行polkitd守護進程的用戶,它擁有對系統資源的高權限訪問權,因此在保護系統安全方面具有重要作用。當用戶請求對系統資源進行訪問操作時,polkitd會檢查該用戶所屬組是否具有合適的權限,從而決定是否授權。
二、polkitd進程佔用CPU高
有時,用戶可能會發現polkitd進程會消耗很多CPU資源,這通常是由於polkitd正在進行授權檢查過程。為了避免這種情況,可以採取以下措施:
1、禁用polkitd的debug模式,這通常可以通過在/etc/polkit-1/polkitd.conf配置文件中修改debug選項來實現。警告:禁用debug模式可能導致polkitd運行異常,因此必須小心謹慎。
[debug] # Enable/disable debugging #debug=no debug=yes #改為no
2、盡量減少需要進行授權檢查的操作。這可以通過審查程序的代碼、減少程序的調用次數以及在可能的情況下緩存已通過授權檢查的結果等方式來實現。
三、polkitd相關配置
polkitd的配置文件通常位於/etc/polkit-1/目錄下。重要的配置文件包括:
1、polkitd.conf:polkitd的主配置文件,包括運行模式、授權驗證策略、debug選項等。
[General] # This is a comment # A comment can appear anywhere on a line # Comments start with a hash symbol. # Here, we define a new constant: # We use this constant later to check if a client is a member # of the wheel group, and we grant the client the admin # authentication level if it is. const=wheel_check,check_group(wheel) # Uncomment this to enforce the same authentication requirements for # every action #DefaultAuthentication=auth_admin # In addition to authentication, authorization is required to # execute privileged actions. In situations where authorization # precedes authentication, you can change the control flow by # setting this variable. #PrioritizeAuthorization=0 # Define the authentication agent(s) that will be used for obtaining # passwords or challenges. #DefaultAuthenticationAgent=pkexec # Define the authorization agent(s) that will be used for obtaining # authorization decisions. #DefaultAuthorizationAgent=org.freedesktop.policykit.exec # The following controls which users can access the system via Polkit # Please note that enabling this is not a good idea due to security # reasons. # AllowRoot=no
2、pkla:policy kit local authority的縮寫,一個XML格式的本地授權文件,用於允許或拒絕用戶執行特定的命令或操作。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE pklocalauthority PUBLIC "-//freedesktop//DTD pklocalauthority//EN" "http://www.freedesktop.org/software/polkit/pklocalauthority.dtd"> <pklocalauthority> <!-- Let unprivileged users reboot and shut down the system. --> <action id="org.freedesktop.consolekit.system.restart-allow-more"> <description>Restart allowed for everyone and multiple logind instances</description> <message>Authentication is required to restart the system</message> <defaults> <allow_any>no</allow_any> <allow_inactive>no</allow_inactive> <allow_active>auth_admin_keep</allow_active> </defaults> <annotate key="org.freedesktop.consolekit.system.restart-multiple-sessions" type="BOOL" value="true">Whether to allow restarting when multiple sessions are active</annotate> </action> </pklocalauthority>
3、policykit-default-privs:用於為所有系統提供通用行為的本地授權文件。
org.freedesktop.hal.detach-encrypted.partitions org.freedesktop.hal.power-management.hibernate org.freedesktop.hal.power-management.reboot org.freedesktop.hal.power-management.shutdown org.freedesktop.hal.power-management.suspend org.freedesktop.hal.power-management.suspend-hybrid
原創文章,作者:ZELDI,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/330103.html