Skip to content

fix(trainer): redact provider API keys in config.json and summary.json - #454

Open
ni (nniiovoo) wants to merge 1 commit into
microsoft:mainfrom
nniiovoo:fix/trainer-redact-api-keys
Open

ni (nniiovoo) wants to merge 1 commit into
microsoft:mainfrom
nniiovoo:fix/trainer-redact-api-keys

Conversation

@nniiovoo

Copy link
Copy Markdown

Fixes #453

_redact_cfg only masked azure_api_key, api_key and openai_api_key. But the config stores credentials as azure_openai_api_key, qwen_chat_api_key, minimax_api_key, openai_compatible_api_key and the role-specific Azure, Qwen and OpenAI-compatible keys. So a key set in the YAML or with --cfg-options was written to the run folder in plaintext. That included the copy load_config makes of a legacy azure_api_key.

A key is now masked when its name is in the existing set or ends in api_key, api-key, token, secret or password. scripts/train.py already treats those suffixes as credentials when it checks --cfg-options. The same rule applies inside a section that flattening keeps as-is, such as --cfg-options gateway.api_key=.... Only the copies written to disk are masked; the config the run uses is unchanged.

Tests: new tests/test_trainer_config_redaction.py. All 4 tests fail on main.

  • One runs the trainer with a mock adapter and eight real config key names, and checks that none of the values appears in any file under out_root.
  • One goes through load_config with --azure_api_key and checks that the alias copy is masked.
  • One checks the token/secret/password suffixes while budgets like max_completion_tokens stay as they are.
  • One checks a key inside a nested section.

Full suite on macOS: 2435 passed. The 2 failures in tests/test_sleep_adopt_skill_subset.py also fail on main.

_redact_cfg only masked azure_api_key, api_key and openai_api_key, but
the config stores credentials as azure_openai_api_key, qwen_chat_api_key,
minimax_api_key, openai_compatible_api_key and the role-specific Azure,
Qwen and OpenAI-compatible keys. A key set in the YAML or with
--cfg-options was written to the run folder in plaintext, including the
copy load_config makes of a legacy azure_api_key.

A key is now masked when its name is in the existing set or ends in
api_key, api-key, token, secret or password, the suffixes
scripts/train.py already treats as credentials, also inside a nested
section that flattening keeps as-is.

Fixes microsoft#453

Signed-off-by: NNIIOVO <haimingni44@gmail.com>

This branch has not been deployed

No deployments
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.

trainer: API keys set in the config are written to config.json and summary.json in plaintext

1 participant