fix(auth): unify caller authentication to isTrustedSender and remove binary path identification#428
fix(auth): unify caller authentication to isTrustedSender and remove binary path identification#428Fire-dtx wants to merge 1 commit into
Conversation
…binary path identification Replace binary path-based caller identification (getExecutablePathAndCmdline, mapMethodCaller, checkInvokePermission) with isTrustedSender + polkit authentication for DistUpgradePartly and PrepareDistUpgradePartly interfaces. Remove caller authentication from RemovePackage interface. Add appstore_intranet.list to trusted source list. Remove deprecated deny-exec-whitelist and install-package-support-auth config items. Introduce manager_auth.go with allow-caller registration, lightdm trusted UID support, and persistent runtime state under /run/lastore. Export SetAllowCaller D-Bus method for deepin-security-loader integration. Add D-Bus access rules for SetAllowCaller deny and deepin-daemon group policy. Configure RuntimeDirectory with 0700 mode and preserve semantics.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Fire-dtx 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 |
deepin pr auto review这份 Git Diff 对 整体来看,该重构显著提升了系统的安全性和架构的合理性,但也引入了一些潜在的并发、一致性和边界场景问题。以下是详细的审查意见: 一、 语法与逻辑
二、 代码质量
三、 代码性能
四、 代码安全
改进建议代码示例针对 1. 修复 func (m *Manager) checkInvokePermission(sender dbus.Sender) error {
uid, err := m.service.GetConnUID(string(sender))
if err != nil {
return fmt.Errorf("failed to get sender conn uid:%v", err)
}
// 必须在调用可能阻塞的 Polkit 前释放锁
isTrusted := func() bool {
m.PropsMu.RLock()
defer m.PropsMu.RUnlock()
return m.isTrustedSender(uid, sender)
}()
if !isTrusted {
err = polkit.CheckAuth(polkitActionChangeOwnData, string(sender), nil)
if err != nil {
logger.Warning(err)
return dbusutil.ToError(err)
}
}
return nil
}
// isTrustedSender 内部不再加锁,由调用方控制
func (m *Manager) isTrustedSender(uid uint32, sender dbus.Sender) bool {
if uid == 0 {
return true
}
if _, ok := m.trustedCallerUIDs[uid]; ok {
return true
}
return m.allowCallServiceList.Contains(string(sender))
}2. 为 func (m *Manager) RemovePackage(sender dbus.Sender, jobName string, packages string) (job dbus.ObjectPath, busErr *dbus.Error) {
m.service.DelayAutoQuit()
// 必须补充鉴权!
if err := m.checkInvokePermission(sender); err != nil {
return "/", dbusutil.ToError(err)
}
jobObj, err := m.removePackage(sender, jobName, packages)
if err != nil {
return "/", dbusutil.ToError(err)
}
return jobObj.getPath(), nil
}3. 简化 func (m *Manager) InstallPackage(sender dbus.Sender, jobName string, packages string) (job dbus.ObjectPath, busErr *dbus.Error) {
m.service.DelayAutoQuit()
// 直接使用统一的鉴权入口
if err := m.checkInvokePermission(sender); err != nil {
return "/", dbusutil.ToError(err)
}
jobObj, err := m.installPackage(sender, jobName, packages)
if err != nil {
return "/", dbusutil.ToError(err)
}
return jobObj.getPath(), nil
}4. 修复 err = terminate()
if err != nil {
// 如果上述方法出错,需要采用重启lightdm方案,此时所有图形session也都会退出
_, err = m.systemd.RestartUnit(0, "display-manager.service", "replace")
if err != nil {
logger.Warning(err)
return dbusutil.ToError(err)
}
// 将日志移入条件分支内
logger.Info("RestartUnit display-manager")
}
return nil |
| # StateDirectory=lastore is not set because it would conflict with the ownership of smartmirror-daemon and build-system-info services, which need to be owned by deepin-daemon, and enabling this would set the owner to root. | ||
|
|
||
| BusName=org.deepin.dde.Lastore1 | ||
| CacheDirectory=lastore |
|
|
||
| // execPath和cmdLine可以有一个为空,其中一个存在即可作为判断调用者的依据 | ||
| // getExecutablePathAndCmdline 获取调用者进程的可执行路径和命令行,供 PowerOff 等接口鉴权使用。 | ||
| func getExecutablePathAndCmdline(service *dbusutil.Service, sender dbus.Sender) (string, string, error) { |
Replace binary path-based caller identification (getExecutablePathAndCmdline, mapMethodCaller, checkInvokePermission) with isTrustedSender + polkit authentication for DistUpgradePartly and PrepareDistUpgradePartly interfaces. Remove caller authentication from RemovePackage interface. Add appstore_intranet.list to trusted source list. Remove deprecated deny-exec-whitelist and install-package-support-auth config items.
Introduce manager_auth.go with allow-caller registration, lightdm trusted UID support, and persistent runtime state under /run/lastore. Export SetAllowCaller D-Bus method for deepin-security-loader integration. Add D-Bus access rules for SetAllowCaller deny and deepin-daemon group policy. Configure RuntimeDirectory with 0700 mode and preserve semantics.