feat: 添加D-Bus调用者白名单鉴权机制,org.deepin.dde.LocaleHelper1设置语言 - #197
Conversation
Reviewer's GuideImplements a D-Bus caller allowlist mechanism for locale-helper, wiring it into SetLocale/GenerateLocale authorization, persisting allowlisted callers across restarts, and tightening D-Bus/Polkit policy to shift trust to the server-side allowlist. Sequence diagram for allow-caller registration and locale setting authorizationsequenceDiagram
actor PrivilegedCaller
participant LocaleHelper as Helper
participant AllowRegistry as allowCallerRegistry
participant Polkit as polkit.Authority
PrivilegedCaller->>LocaleHelper: SetAllowCaller(uniqueName)
LocaleHelper->>AllowRegistry: addCaller(sender, uniqueName)
AllowRegistry-->>LocaleHelper: [caller registered]
LocaleHelper-->>PrivilegedCaller: dbusutil.ToError(nil)
loop later
actor AllowedCaller
AllowedCaller->>LocaleHelper: SetLocale(locale)
LocaleHelper->>AllowRegistry: authorize(sender)
alt allowlist hit
AllowRegistry-->>LocaleHelper: nil
LocaleHelper-->>AllowedCaller: [locale set]
else allowlist not enabled
AllowRegistry-->>LocaleHelper: errAllowCallerNotEnabled
LocaleHelper->>Polkit: checkAuth(sender)
alt polkit authorized
Polkit-->>LocaleHelper: (true, nil)
LocaleHelper-->>AllowedCaller: [locale set]
else polkit denied
Polkit-->>LocaleHelper: (false or error)
LocaleHelper-->>AllowedCaller: dbusutil.ToError(errAuthFailed)
end
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. 新增 allowCallerRegistry 模块实现调用者白名单注册与鉴权功能 2. 注册逻辑强制校验发起方权限仅允许 root 或 deepin-daemon 组进程注册其子 孙进程 3. 在 SetLocale 和 GenerateLocale 接口中集成白名单校验通过的进程可跳过后 续鉴权 4. 实现白名单状态通过 JSON 文件持久化并在重启时加载同时比对 BusID 防止跨 生命周期恢复 5. 监听 D-Bus NameOwnerChanged 信号实现连接断开时自动清理白名单条目 6. 将 Polkit 策略由 auth_admin_keep 改为 yes 将权限控制重心转移至服务端 白名单 7. 更新 D-Bus 总线配置严格限制 SetAllowCaller 方法仅对特权用户和组开放 Influence: 1. 验证 deepin-daemon 组内的父进程能否成功通过 SetAllowCaller 注册其子 进程 2. 验证已注册的子进程调用 SetLocale 和 GenerateLocale 时无需 Polkit 弹窗 且功能正常 3. 验证未在白名单中的普通进程调用上述方法时被正确拦截并返回错误 4. 测试非法注册请求的拒绝情况包括非特权组进程注册非子孙进程注册以及跨 UID 注册 5. 验证被注册的子进程异常退出后白名单是否能够自动清除对应条目 6. 验证 locale-helper 服务重启后白名单状态的正确恢复以及不同 BusID 下的 隔离失效 7. 验证 root 用户在注册和调用时的豁免逻辑是否正常工作 Task: https://pms.uniontech.com/task-view-393313.html
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 --- a/locale-helper/ifc.go
+++ b/locale-helper/ifc.go
@@ -93,6 +93,10 @@ func (h *Helper) generateLocale(sender dbus.Sender, locale string) error {
func (h *Helper) SetAllowCaller(sender dbus.Sender, uniqueName string) *dbus.Error {
h.service.DelayAutoQuit()
+ if !strings.HasPrefix(uniqueName, ":") {
+ return dbusutil.ToError(fmt.Errorf("invalid target unique name %q", uniqueName))
+ }
+
err := h.allowCallers.addCaller(sender, uniqueName)
if err != nil {
logger.Warningf("SetAllowCaller rejected sender %s for target %s: %v", sender, uniqueName, err) |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, xionglinlin The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Influence:
Task: https://pms.uniontech.com/task-view-393313.html
Summary by Sourcery
Introduce a D-Bus allow-caller whitelist mechanism for locale-helper and integrate it into locale-changing methods, shifting primary authorization from Polkit to a server-side registry.
New Features:
Enhancements:
Tests: