Skip to content

feat: mask SecretId / SecretKey / Token in list and get output#123

Open
Mxiansen wants to merge 3 commits into
TencentCloud:masterfrom
Mxiansen:feat/configure-mask-secret
Open

feat: mask SecretId / SecretKey / Token in list and get output#123
Mxiansen wants to merge 3 commits into
TencentCloud:masterfrom
Mxiansen:feat/configure-mask-secret

Conversation

@Mxiansen

@Mxiansen Mxiansen commented Jul 1, 2026

Copy link
Copy Markdown

Optimization

  • Add sensitive_keys set and _mask_value static method to BasicConfigure, following the existing masking style '*' + value[-4:].
  • Update ConfigureListCommand._run_main to apply _mask_value when printing sensitive fields; non-secret fields such as token / role-arn remain in plaintext.
  • Update ConfigureGetCommand._run_main with a from_cred flag, masking only when the field is read from the credential file and belongs to sensitive_keys; the conf branch and kv-parsing branch are unchanged.
  • Sync ConfigureListCommand.EXAMPLES and ConfigureGetCommand.EXAMPLES to demonstrate masked output.
  • Credential file content on disk is untouched and does not affect subsequent authentication calls.

在 tccli configure list 与 tccli configure get 命令输出中对 secretId 和
secretKey 做脱敏,避免在 AI Agent 等场景直接打印凭证原文导致泄漏。

- 在 BasicConfigure 中新增 sensitive_keys 集合与 _mask_value 静态方法,
  沿用项目已有 '*' + value[-4:] 的脱敏样式。
- ConfigureListCommand._run_main 输出敏感字段前套用 _mask_value,
  token / role-arn 等非密钥字段保持明文。
- ConfigureGetCommand._run_main 增加 from_cred 标志,仅当命中
  credential 文件且字段属于 sensitive_keys 时脱敏,
  conf 分支与 kv 解析分支行为不变。
- 同步更新 ConfigureListCommand.EXAMPLES 与 ConfigureGetCommand.EXAMPLES,
  演示脱敏后的输出形态。
- 磁盘上的 credential 文件内容保持原样,不影响后续鉴权调用。

Related TAPD: https://tapd.woa.com/tapd_fe/10161711/story/detail/1010161711135046182
@Mxiansen Mxiansen changed the title feat(configure): mask secretId/secretKey in list and get output feat: mask secretId/secretKey in list and get output Jul 6, 2026
…ace/curr_project/tencentcloud-cli && python3 -m pytest tests/test_command.py::test_G4_unfold_depth_31_rejected -q 2>&1 | tail -40

- 将 _mask_value 静态方法替换为模块级 mask_secret 函数
  - 新实现采用等长 * + 末4位格式(更安全)
  - 支持长度 <= 4 的短值全部脱敏
- 将 sensitive_keys 重命名为 sensitive_cred_fields 并扩展为 set
  - 新增 token 字段的脱敏支持
- configure get 命令:无论字段来源均对敏感字段脱敏
@Mxiansen Mxiansen changed the title feat: mask secretId/secretKey in list and get output feat: mask SecretId / SecretKey / Token in list and get output Jul 6, 2026
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.

1 participant