Repository navigation
fix: redact home paths in profile runner logs - #262
Open
chen2021673 wants to merge 2 commits into
Open
chen2021673 wants to merge 2 commits into
chen2021673 wants to merge 2 commits into
Conversation
| # 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") |
Contributor
There was a problem hiding this comment.
查了一下这个语法 exec {log_output_fd}> >(…) 是 Bash 4.1 才支持的,macOS 可能不支持。上面特意做了macOS 的兼容,在 macOS 可能因为这块还是会报错。
Collaborator
Author
There was a problem hiding this comment.
移除了 Bash 4.1+ 才支持的exec {log_output_fd}> >(…),改为普通管道 + PIPESTATUS,Bash 3.2(macOS 自带版本)可用。
|
|
||
| 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" "$@" |
Contributor
There was a problem hiding this comment.
这里的 [^/[:space:]\"']+ 只把 /、空白和引号当作路径结束边界,其他常见分隔符会被当成用户名的一部分一起吞掉。这里是不是把 [^/[:space:]\"']+ 替换成识别 $HOME 覆盖更全面一点
Collaborator
Author
There was a problem hiding this comment.
新增 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
force-pushed
the
fix/run-models-profile-redaction
branch
from
November 26, 2026 02:55
d5ea356 to
17f9648
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
为
run_models_and_profile.bash增加日志路径脱敏,避免在控制台输出和上传的运行日志中输出本机用户目录;同时保证脱敏过滤在命令失败时也能完整落盘,并兼容 macOS 的 sed 实现。Changes
redact_log_paths过滤函数,统一处理/home/<user>、/Users/<user>、/root、~/等常见用户路径前缀,替换为<home>;/root仅在独立路径边界生效,不会误伤/rootdir、/root_foo等目录名。run_metadata.log与各用例日志改用相对路径记录(../run_metadata.log),metadata 中仅记录 config 文件名和logs/profile_logs,不再写入绝对路径。-u,BSD/macOS sed 回退到默认缓冲(调用方已有 wait/flush 兜底),不再依赖 GNU-only 的sed -u与realpath --relative-to。