Rob*_*inJ 26
PolicyKit 更具可配置性,但pkexec不利用这种可配置性。此外,pkexec向用户显示将启动的程序的完整路径,让用户更确定会发生什么。PolicyKit 的所谓“policies”可用于设置更多高级设置。例如,是否应该记住密码。
我从pkexec手册中得到的东西:
PROGRAM 将运行它的环境将设置为最小的已知和安全环境,以避免通过 LD_LIBRARY_PATH 或类似机制注入代码。此外,PKEXEC_UID 环境变量设置为调用 pkexec 的进程的用户 ID。结果,pkexec 将不允许您以另一个用户身份运行例如 X11 应用程序,因为 $DISPLAY 环境变量未设置。
关于更多信息,政策或行动的定义从pkexec手册:
Run Code Online (Sandbox Code Playgroud)To specify what kind of authorization is needed to execute the program /usr/bin/pk-example-frobnicate as another user, simply write an action definition file like this <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> <policyconfig> <vendor>Examples for the PolicyKit Project</vendor> <vendor_url>http://hal.freedesktop.org/docs/PolicyKit/</vendor_url> <action id="org.freedesktop.policykit.example.pkexec.run-frobnicate"> <description>Run the PolicyKit example program Frobnicate</description> <description xml:lang="da">Kør PolicyKit eksemplet Frobnicate</description> <message>Authentication is required to run the PolicyKit example program Frobnicate</message> <message xml:lang="da">Autorisering er påkrævet for at afvikle PolicyKit eksemplet Frobnicate</message> <icon_name>audio-x-generic</icon_name> <defaults> <allow_any>no</allow_any> <allow_inactive>no</allow_inactive> <allow_active>auth_self_keep</allow_active> </defaults> <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/pk-example-frobnicate</annotate> </action> </policyconfig> and drop it in the /usr/share/polkit-1/actions directory under a suitable name (e.g. matching the namespace of the action). Note that in addition to specifying the program, the authentication message, description, icon and defaults can be specified. For example, for the action defined above, the following authentication dialog will be shown: [IMAGE][2] +----------------------------------------------------------+ | Authenticate [X] | +----------------------------------------------------------+ | | | [Icon] Authentication is required to run the PolicyKit | | example program Frobnicate | | | | An application is attempting to perform an | | action that requires privileges. Authentication | | is required to perform this action. | | | | Password: [__________________________________] | | | | [V] Details: | | Command: /usr/bin/pk-example-frobnicate | | Run As: Super User (root) | | Action: org.fd.pk.example.pkexec.run-frobnicate | | Vendor: Examples for the PolicyKit Project | | | | [Cancel] [Authenticate] | +----------------------------------------------------------+ If the user is using the da_DK locale, the dialog looks like this: [IMAGE][3] +----------------------------------------------------------+ | Autorisering [X] | +----------------------------------------------------------+ | | | [Icon] Autorisering er påkrævet for at afvikle | | PolicyKit eksemplet Frobnicate | | | | Et program forsøger at udføre en handling der | | kræver privilegier. Autorisering er påkrævet. | | | | Kodeord: [___________________________________] | | | | [V] Detaljer: | | Bruger: Super User (root) | | Program: /usr/bin/pk-example-frobnicate | | Handling: org.fd.pk.example.pkexec.run-frobnicate | | Vendor: Examples for the PolicyKit Project | | | | [Annullér] [Autorisering] | +----------------------------------------------------------+ Note that pkexec does no validation of the ARGUMENTS passed to PROGRAM. In the normal case (where administrator authentication is required every time pkexec is used), this is not a problem since if the user is an administrator he might as well just run pkexec bash to get root. However, if an action is used for which the user can retain authorization (or if the user is implicitly authorized), such as with pk-example-frobnicate above, this could be a security hole. Therefore, as a rule of thumb, programs for which the default required authorization is changed, should never implicitly trust user input (e.g. like any other well-written suid program).
Pau*_*sch 15
使用 sudo,您可以为每个用户和每个程序设置有关是否在 sudo 上下文中保留或重置调用者环境的策略。env_reset 策略是默认设置的。
您不能通过 pkexec 运行图形应用程序,而无需对其进行显式配置。因为这仅仅是环境重置的结果,所以 sudo 显然也是如此。但是请注意,无论是 pkexec 还是 sudo 都无法阻止恶意应用程序以 root 身份运行以从显示管理器或用户 X11-cookie 文件中检索所有必要的信息。后者,两者或类似,甚至可以根据情况由非 root 应用程序完成。
Sudo 不需要明确的用户列表。可以列出任何用户组,甚至可以为所有用户设置权限。target_pw 指令允许这些用户在他们想要运行应用程序的上下文中使用用户的凭据进行身份验证,即 root。除此之外,同样传统的 su (su / gtksu / kdesu) 程序可用于执行相同的操作,无需特殊配置。
sudo 也允许用户在指定时间内保持身份验证。该选项名为超时,可全局配置、每个用户或每个应用程序。身份验证可以保留每个 tty 或全局每个用户。
虽然 pkexec 可能不对传递给 PROGRAM 的 ARGUMENTS 进行验证,但 sudo 确实具有此功能。虽然承认,你很容易搞砸这个,通常不会这样做。
您可以通过 pkexec 稍微调整一下您希望程序如何运行:图标、要显示的文本,您甚至可以拥有本地化的东西等等。根据情况,这确实很漂亮。可悲的是,有人觉得有必要为这个功能重新发明轮子。这可能是要放入图形 gtksudo/kdesu 包装器中的内容。
Policykit 只是一个集中的配置框架。不幸的是不是一个漂亮的。PKs XML 文件比任何应用程序可以提供的原生二进制文件都复杂得多。没有人会这么疯狂地使用二进制......哦gconf......没关系。
与它的前端有何pkexec不同sudo:
pkexec没有明确配置它,您就无法运行图形应用程序。pkexec:图标、要显示的文本、是否记住密码、是否允许它以图形方式运行等等。sudo您必须在sudoers文件中列为admin。 gksudo在要求输入密码时锁定键盘、鼠标和焦点,而pkexec不是。在这两种情况下,击键都是可嗅探的。pkexec您一起在一个稍微消毒的环境中工作。尝试例如:
cd /etc/init.d
sudo cat README
# and now the same with pkexec
pkexec cat README
# nice, huh?
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33489 次 |
| 最近记录: |