Polkit授权管理

Polkit的配置:

  • 查看polkit服务:

           

一个是agent,一个是polkit服务;

polkit.addRule(function(action,subject)
{
if(subject.isInGroup("wheel")&&(action.id.indexOf("com.")==0))
{
    return polkit.Result.YES;
}
});

让所有的属于wheel组的用户且Action ID前缀为"com."的操作都不用输入密码。更详细的例子可以查看此目录下的规则文件。

  • 行为(Actions),在/usr/share/polkit-1/actions目录下,
org.freedesktop.consolekit.policy ——关机
org.freedesktop.NetworkManager.policy ——网络配置
org.freedesktop.policykit.policy ——决定pkexec的密码需求
org.freedesktop.udisks2.policy ——磁盘挂载
org.freedesktop.upower.policy ——挂起和休眠

文件中对每个action都有详细注解,要修改的地方主要是:

<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_self</allow_active>

 
设置取值有:
 
 
no不通过验证
yes通过验证(不用输入密码)
auth_self
以任意本地用户来验证
auth_admin以管理员身份来验证
auth_self_keep
同auth_self,但在一段时间内保持认证(如5分钟)
auth_admin_keep
同auth_admin,但在一段时间内保持认证(如5分钟)

如下图所示(来自StartOS设备管理器的Actions文件):

 

注:整理自http://blog.sina.com.cn/s/blog_6640da97010155pk.html

PolicyKit百科:http://wiki.linux.org.hk/w/PolicyKit

------------------------------------------------------

看看系统进程,
zhentu actions # pgrep polkit -lf
4303 /usr/lib/polkit-1/polkitd --no-debug
4585 /usr/libexec/polkit-gnome-authentication-agent-1
有两个进程,一个是agent,另一个是polkit服务。 agent包含监听接口和一个用户界面(对话窗口),允许用户输入密码。 Authentication Agent API Reference是polkit提供的agent开发接口。
polkit的配置
"polkit — Authorization Manager"是其官方注解,可以翻译为“授权管理”。包含开发接口,有时间需要研究一下thunar/udisk、nm-applet的实现逻辑。
常用的是polkit的配置修改:
1,AUTHORIZATION RULES,利用javascript脚本实现,/usr/share/polkit-1/rules.d
   用于让应用程序添加授权规则,比如下面的network manager的:
// Let users in plugdev group modify NetworkManager
polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.NetworkManager.settings.modify.system" &&
       subject.isInGroup("plugdev") && subject.active) {
       return "yes";
    }
});      //把用户加入plugdev组就不用输入密码了
 和程序开发的关系较大,系统使用者不要修改,可以参考。
2,ACTIONS
 和用户关系很大,/usr/share/polkit-1/actions/*.policy
org.freedesktop.consolekit.policy  ——关机
org.freedesktop.NetworkManager.policy ——网络配置
org.freedesktop.policykit.policy    —— run a program as another user,决定pkexec的密码需求
org.freedesktop.udisks2.policy   —— 磁盘挂载
org.freedesktop.upower.policy  —— Hibernate  and suspend
org.freedesktop.upower.qos.policy —— latency
org.gnome.gconf.defaults.policy  —— gnome gconf
文件中对每个action都详细的注解,一看便知。可能需要修改的地方是这些:
<allow_any>auth_admin</allow_any>
 <allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_self</allow_active>

设置取值有:

no

Not authorized.

yes

Authorized.

auth_self

Authentication by the owner of the session that the client originates from is required.

auth_admin

Authentication by an administrative user is required.

auth_self_keep

Like auth_self but the authorization is kept for a brief period (e.g. five minutes).

auth_admin_keep

Like auth_admin but the authorization is kept for a brief period (e.g. five minutes).


典型的场景是把allow_active的设置从auth_admin(root密码)改成auth_self(当前用户密码)或者yes(不要密码)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值