Skip to content

fix: redact home paths in profile runner logs - #262

Open
chen2021673 wants to merge 2 commits into
masterfrom
fix/run-models-profile-redaction
Open

chen2021673 wants to merge 2 commits into
masterfrom
fix/run-models-profile-redaction

Conversation

@chen2021673

Copy link
Copy Markdown
Collaborator

Summary

为 run_models_and_profile.bash 增加日志路径脱敏,避免在控制台输出和上传的运行日志中输出本机用户目录;同时保证脱敏过滤在命令失败时也能完整落盘,并兼容 macOS 的 sed 实现。

Changes

  • 新增 redact_log_paths 过滤函数,统一处理 /home/<user>、/Users/<user>、/root、~/ 等常见用户路径前缀,替换为 <home>;/root 仅在独立路径边界生效,不会误伤 /rootdir、/root_foo 等目录名。
  • 命令的 stdout/stderr 改为经脱敏过滤器写入日志文件,并在读取失败日志前等待过滤器退出、完成刷盘,避免尾部输出丢失。
  • 控制台中的命令、CMake 命令、日志目录、checkpoint 清理、profile 文件移动、比较脚本输出等均经过脱敏。
  • run_metadata.log 与各用例日志改用相对路径记录(../run_metadata.log),metadata 中仅记录 config 文件名和 logs / profile_logs,不再写入绝对路径。
  • 手动比较命令和最终 Feishu 写表提示改用相对路径。
  • sed 缓冲参数改为启动时探测:GNU sed 使用 -u,BSD/macOS sed 回退到默认缓冲(调用方已有 wait/flush 兜底),不再依赖 GNU-only 的 sed -u 与 realpath --relative-to。

Comment thread scripts/run_models_and_profile.bash Outdated
# Filter output before writing it, including logs from interrupted commands.
# Keep eval in this shell and wait for the filter to flush before reading logs.
local log_output_fd log_filter_pid exit_code=0
exec {log_output_fd}> >(redact_log_paths >> "$log_path")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

查了一下这个语法 exec {log_output_fd}> >(…) 是 Bash 4.1 才支持的,macOS 可能不支持。上面特意做了macOS 的兼容,在 macOS 可能因为这块还是会报错。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

移除了 Bash 4.1+ 才支持的exec {log_output_fd}> >(…),改为普通管道 + PIPESTATUS,Bash 3.2(macOS 自带版本)可用。

Comment thread scripts/run_models_and_profile.bash Outdated

redact_log_paths() {
sed -E "${REDACT_SED_BUFFER[@]}" \
"s@/(home|Users)/[^/[:space:]\"']+@<home>@g; s@~/@<home>/@g; s@/root([^[:alnum:]_-])@<home>\\1@g; s@/root\$@<home>@g" "$@"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这里的 [^/[:space:]\"']+ 只把 /、空白和引号当作路径结束边界,其他常见分隔符会被当成用户名的一部分一起吞掉。这里是不是把 [^/[:space:]\"']+ 替换成识别 $HOME 覆盖更全面一点

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

新增 REDACT_HOME_RULE,把 $HOME 转义成 sed 正则后整体替换为 ,不再依赖用户名的字符边界;[^/[:space:]"']+ 改为 [[:alnum:]_.-]+,只匹配 POSIX 用户名的安全字符。

Filter home-directory prefixes from console output, command metadata, and
streamed command logs. Route command stdout/stderr through the redaction
filter and wait for it to flush before reporting failures so trailing
output is not lost.

Record the metadata file location relative to each tag log directory and
keep manual next-step hints relative. Detect GNU sed unbuffered-mode
support so the redaction filter also works with BSD/macOS sed.
Use a pipeline with PIPESTATUS instead of Bash 4.1 dynamic FDs so
redaction works on macOS Bash 3.2, and match /root plus POSIX-safe
usernames so delimiters are not swallowed.
@chen2021673
chen2021673 force-pushed the fix/run-models-profile-redaction branch from d5ea356 to 17f9648 Compare November 26, 2026 02:55
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.

2 participants