Skip to content

fix(agent-sec-core): explicitly enable systemd user unit after install#1322

Closed
zhangtaibo wants to merge 1 commit into
alibaba:mainfrom
zhangtaibo:fix/agent-sec-core-systemd-enable-nightly-20260704
Closed

fix(agent-sec-core): explicitly enable systemd user unit after install#1322
zhangtaibo wants to merge 1 commit into
alibaba:mainfrom
zhangtaibo:fix/agent-sec-core-systemd-enable-nightly-20260704

Conversation

@zhangtaibo

Copy link
Copy Markdown
Contributor

Summary

Fixes #1320

The %systemd_user_post macro calls systemctl preset <unit>, which checks the system preset policy. Since no preset rule matches agent-sec-core.service, the default action is disable, leaving the unit disabled after package installation.

This PR adds an explicit systemctl --user enable agent-sec-core.service 2>/dev/null || true after %systemd_user_post in the %post -n agent-sec-cli section to ensure the security daemon is enabled on install.

Root Cause

%systemd_user_post expands to:

systemd-update-helper install-user-units agent-sec-core.service

This only copies the unit file to the user preset directory. It then calls systemctl preset, which checks /usr/lib/systemd/user-preset/90-systemd.preset. Since no rule in that file matches agent-sec-core.service, the default action is disable.

Fix

 %post -n agent-sec-cli
 %systemd_user_post agent-sec-core.service
+systemctl --user enable agent-sec-core.service 2>/dev/null || true

The 2>/dev/null || true ensures the scriptlet does not fail if the user session is not available during RPM install.

Verification

  • Applied patch on ECS (fresh clone of anolisa main 161859b9)
  • Build: source /root/.cargo/env && bash scripts/rpm-build.sh agent-sec-core → exit 0, all 8 RPMs produced
  • Verified %post script in built RPM contains systemctl --user enable agent-sec-core.service 2>/dev/null || true after the systemd-update-helper call

This PR was automatically generated by the nightly test pipeline (run nightly-20260704-020034).

%systemd_user_post calls systemctl preset, which checks the
preset policy. Since no preset rule matches agent-sec-core.service,
the default action is disable, leaving the unit disabled after
package installation.

Add explicit 'systemctl --user enable agent-sec-core.service' after
%systemd_user_post to ensure the security daemon is enabled on install.

Fixes alibaba#1320
@zhangtaibo zhangtaibo requested a review from yangdao479 as a code owner July 3, 2026 20:22
@github-actions github-actions Bot added the component:sec-core src/agent-sec-core/ label Jul 3, 2026
@yangdao479 yangdao479 requested a review from RemindD July 9, 2026 02:57
@yangdao479

Copy link
Copy Markdown
Collaborator

@RemindD PTAL

@RemindD RemindD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • RPM 脚本通常以 root 执行,不知道“哪个普通用户”要启用这个 user service。
  • systemctl --user 依赖用户会话和 user bus,安装阶段通常不可用。
  • 即使成功,也可能启用的是 root 的 user service,不是目标用户的。
  • RPM 打包习惯上安装 unit 文件,并通过 %systemd_user_post 触发 daemon-
    reload/preset 等发行版机制;是否启用由 preset、管理员策略或用户显式操作决
    定。

@zhangtaibo

Copy link
Copy Markdown
Contributor Author

[automated review] case 连续通过 6 次(在不含本 PR 的 main 上),原始 verdict=product_bug 但 main 已绿,PR 疑似 stale duplicate(修复已通过其他途径合入)。关闭 issue+PR。若 PR 仍需要,请重开并说明。

@zhangtaibo zhangtaibo closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:sec-core src/agent-sec-core/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[agent-sec-core] systemd user unit not enabled after RPM install — %systemd_user_post preset leaves agent-sec-core.service disabled

3 participants