Skip to content

feat(updateplatform): Add Helper support for machineID retrieval and policy check interval configuration#291

Merged
electricface merged 1 commit into
linuxdeepin:intranet_updatefrom
electricface:swt/dev-updateplatform1
Jan 20, 2026
Merged

feat(updateplatform): Add Helper support for machineID retrieval and policy check interval configuration#291
electricface merged 1 commit into
linuxdeepin:intranet_updatefrom
electricface:swt/dev-updateplatform1

Conversation

@electricface
Copy link
Copy Markdown
Member

  • Added CheckPolicyInterval and GetHardwareIdByHelper fields to
    the configuration structure;
  • Added SetCheckPolicyInterval and SetStartCheckRange methods to
    support dynamic adjustment of policy check configurations;
  • Updated UpdatePlatformManager to support retrieving the machineID
    via Helper, and added task ID management and event reporting
    capabilities;
  • Implemented the UpdateSourceList method for maintaining private
    repository source files;
  • Modified the hardware ID retrieval logic to add functionality
    for obtaining the hardware ID via the DBus sync helper;
  • Updated the Token configuration file generation logic to support
    the new hardware ID retrieval method;
  • Synchronized Token generation updates in the GatherInfo and
    CheckPolicy tools to ensure authentication consistency;
  • Added read/write methods for the cached task ID file to ensure
    task information persistence and reading accuracy.

Task: https://pms.uniontech.com/task-view-385321.html

@electricface electricface force-pushed the swt/dev-updateplatform1 branch from f326a30 to e65a45e Compare January 19, 2026 10:08
and policy check interval configuration

- Added CheckPolicyInterval and GetHardwareIdByHelper fields to
the configuration structure;
- Added SetCheckPolicyInterval and SetStartCheckRange methods to
support dynamic adjustment of policy check configurations;
- Updated UpdatePlatformManager to support retrieving the machineID
via Helper, and added task ID management and event reporting
capabilities;
- Implemented the UpdateSourceList method for maintaining private
repository source files;
- Modified the hardware ID retrieval logic to add functionality
for obtaining the hardware ID via the DBus sync helper;
- Updated the Token configuration file generation logic to support
the new hardware ID retrieval method;
- Synchronized Token generation updates in the GatherInfo and
CheckPolicy tools to ensure authentication consistency;
- Added read/write methods for the cached task ID file to ensure
task information persistence and reading accuracy.

Task: https://pms.uniontech.com/task-view-385321.html
@electricface electricface force-pushed the swt/dev-updateplatform1 branch from e65a45e to 8b6d390 Compare January 19, 2026 10:16
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这份代码主要增加了通过DBus从helper服务获取硬件ID的功能,引入了策略检查时间间隔的配置,并增加了任务ID和事件上报的相关逻辑。以下是我的审查意见:

1. 语法与逻辑

  • 类型断言安全:在 getConfigFromDSettings 中,对 dSettingsKeyCheckPolicyInterval 的处理进行了类型断言检查(int64),这是很好的做法。但对于 dSettingsKeyGetHardwareIdByHelper,直接使用了 v.Value().(bool)。如果配置类型不匹配,虽然会触发panic,但建议统一风格,也加上 ok 检查,或者确保配置源类型绝对正确。

    // 建议修改
    if val, ok := v.Value().(bool); ok {
        c.GetHardwareIdByHelper = val
    } else {
        logger.Warningf("dSettings key %s: value is not bool", dSettingsKeyGetHardwareIdByHelper)
    }
  • IsPrivateLastore 变量初始化:在 system.go 中定义了 var IsPrivateLastore bool 并标记了 TODO。如果在 UpdateSourceList 等函数中使用此变量,必须确保在使用前已被正确赋值,否则可能导致逻辑错误。建议将其封装为配置项的一部分或在初始化时明确赋值,避免全局变量的不确定性。

  • PostProcessEventMessage 中的字符串截断:代码中 if len(body.EventContent) >= 950 进行了硬编码截断。虽然逻辑上没问题,但建议将 950 定义为常量(例如 MaxEventContentLength),便于维护和理解。

2. 代码质量

  • 废弃包的使用:在 message_report.go 中引入了 io/ioutil。Go 1.16+ 已废弃 io/ioutil,推荐使用 ioos 包中的替代函数。

    • ioutil.WriteFile 应替换为 os.WriteFile
  • 代码注释:部分函数(如 ReplaceVersionCache)增加了中文注释,这很好。但 ProcessEvent 结构体和常量定义(如 CheckEnv, GetUpdateEvent)缺少注释,建议补充说明这些事件类型的含义和用途。

  • 错误处理一致性:在 getHardwareIdByHelper 函数中,DBus调用失败时返回空字符串 ""。调用方(如 GetHardwareId)会继续执行 hhardware.GenMachineID()。这种降级策略是合理的,但建议在日志中明确记录降级行为,例如 "Failed to get hardware id by helper, fallback to local generation"。

3. 代码性能

  • DBus 调用开销getHardwareIdByHelper 涉及跨进程的 DBus 调用,比本地计算慢。考虑到 GetHardwareId 可能在高频路径上被调用(如生成Token、上报状态),建议在内存中缓存获取到的 Hardware ID,除非配置发生变化或系统重启,否则避免重复调用 DBus。

  • 文件 I/OsaveTaskIdgetTaskId 频繁读写文件 /var/lib/lastore/os-task-info。如果这两个函数调用频率较高,建议在内存中维护 taskID,仅在初始化读取和关键变更时写入磁盘,减少 I/O 开销。

4. 代码安全

  • 敏感信息日志:在 PostProcessEventMessage 中,logger.Debugf("upgrade post process event msg is %v", string(jsonData)) 打印了完整的请求体 JSON。虽然 EventContent 被截断了,但如果 JSON 中包含其他敏感信息,直接打印日志可能存在风险。建议在日志中仅打印非敏感字段或摘要。

  • Token 文件权限:在 UpdateTokenConfigFile 中,有一行注释 // TODO: may need to use chattr command to set tokenPath as immutable。Token 文件 /etc/apt/apt.conf.d/99lastore-token.conf 包含认证信息,目前的权限是 0644(所有者可读写,组和其他用户只读)。

    • 如果 Token 非常敏感,建议设置为 0600(仅所有者可读写)。
    • 关于 chattr +i(不可变属性),这可以防止意外删除或修改,但也会导致正常的更新(如 UpdateTokenConfigFile)失败。如果使用,需要在写入前临时移除属性,写入后再添加,这增加了复杂度。需权衡安全性需求。
  • DBus 交互getHardwareIdByHelper 依赖 com.deepin.sync.Helper 服务。如果该服务被恶意替换或劫持,可能返回伪造的 Hardware ID。虽然这是系统层面的信任问题,但代码中应假设服务是可信的。

5. 其他建议

  • manager_unit.go 中的定时器逻辑

    • CheckPolicyCron (Cron 格式) 改为了 CheckPolicyInterval (秒数间隔)。
    • 代码使用了 systemd-run--on-active--on-unit-active 参数。这会创建一个临时 systemd service 来执行任务。
    • 潜在问题:如果 checkpolicy 命令执行时间超过了 CheckPolicyInterval,systemd 可能会根据配置(默认是并发)启动下一个实例,或者排队。建议确认是否需要 --timer-property=AccuracySec= 来控制精度,或者确保 checkpolicy 是幂等且线程安全的。
  • PostStatusMessageforceUpload 参数

    • 新增了 forceUpload 参数,用于在私有环境(IsPrivateLastore)下强制上报。
    • 逻辑是:if system.IsPrivateLastore && !forceUpload { return }
    • 这意味着默认情况下私有环境不上报状态。这符合私有部署的需求,但需确保在关键错误(如升级失败)时,确实传入了 true。目前代码中部分失败场景传了 true,部分传了 false,建议统一标准,明确哪些级别的错误需要强制上报。

总结

代码整体逻辑清晰,功能扩展合理。主要改进点在于:

  1. 增强类型断言的安全性。
  2. 更新废弃的 API (io/ioutil)。
  3. 优化 DBus 调用和文件 I/O 的性能(考虑缓存)。
  4. 注意日志中的敏感信息泄露风险。
  5. 明确 Token 文件的安全策略。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: electricface, zhaohuiw42

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@electricface electricface merged commit f93d14c into linuxdeepin:intranet_update Jan 20, 2026
15 of 16 checks passed
@electricface electricface deleted the swt/dev-updateplatform1 branch January 20, 2026 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants