Repository navigation
fix: stop leaking credentials in resolved configs, debug request logs and the vLLM transport log - #3679
Conversation
d506a15 to
f2a1958
Compare
|
Thanks for fixing these credential leaks! Could you also cover the adjacent vLLM transport-log path in this PR? With This behavior predates your changes, but it seems closely related to the credential-leak fix here. Could we sanitize the error details when writing that log and add a regression test checking that a fake API key is absent from the saved error event? A targeted change at the log writer would let us preserve the exception metadata other callers receive. Thanks! |
`looks_like_secret_key` only matched the lowercase substrings `token`, `key` and `header`, so other credentials were printed in plain text by `gym env resolve` and the almost-server error, sent to W&B/MLflow as the run config, and kept in the recorded `gym eval compare` command. Match case-insensitively and also cover `password`, `passwd`, `secret`, `credential`, `bearer`, `cookie` and `authorization`. The last one catches an `Authorization` entry inside a headers mapping, which the masker walks into key by key. This only adds masking: every key masked before is still masked, and `MASKED_VALUE` stays "****", so the exporters' `is_available` checks still treat a masked config as unconfigured. Non-string OmegaConf keys (ints, enums) are matched on their string form instead of raising `TypeError`. `auth` and `session` are deliberately not matched: as substrings they would hide ordinary settings such as `author`, `require_auth` and `max_concurrent_sessions`. Example, `recursively_hide_secrets` on a config with fake values: key before after db_password sk-FAKE **** OPENAI_API_KEY sk-FAKE **** apiKey sk-FAKE **** headers mapping: Authorization Bearer sk-FAKE **** policy_api_key **** **** author me me 1 (int key) TypeError unchanged Part of NVIDIA-NeMo#2222 (ERR-40044b75). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Tsvetan (Sven) Rankov <[email protected]>
With `global_aiohttp_client_request_debug=True`, `raise_for_status`
printed the whole aiohttp `RequestInfo`: every request header, including
the `Authorization: Bearer <api key>` that `NeMoGymAsyncOpenAI` adds to
each model call, and the URL query string. That is exactly the output
someone reads while debugging a 401.
Print only the method and the URL without its query string, reusing
`_redacted_url` as `_format_upstream_error_log` already does. The
`Request info:` prefix is kept so the debugging guide's search still
matches, and the guide now says headers are not printed. The signature
of `raise_for_status` is unchanged.
Example, a 401 from a model endpoint with the flag on (fake key):
before:
Request info: RequestInfo(url=URL('http://host/v1/chat/completions?api-key=sk-FAKE'),
method='POST', headers=<CIMultiDictProxy('Authorization': 'Bearer sk-FAKE', ...)>, ...)
after:
Request info: POST http://host/v1/chat/completions
Closes NVIDIA-NeMo#2222 together with the previous commit (ERR-fcaebf7d).
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Tsvetan (Sven) Rankov <[email protected]>
With `NEMO_GYM_VLLM_TRANSPORT_LOG` set, an HTTP error from the model
endpoint was logged as `repr(e)`. `raise_for_status` keeps the request
headers on the exception, so the `transport_error_response` event wrote
`Authorization: Bearer <api key>` to the log file.
Log only the error type, status, message, method and the URL without
its query string. Response headers are left out as well; the event
still has `http_status` and `raw_response_body`. `raise_for_status` is
unchanged, so other callers still receive the full exception. The
generic `transport_error` event keeps `repr(e)`: a `ClientResponseError`
never reaches that handler, and the connection errors and timeouts that
do carry no request headers.
Example, a 400 from the model endpoint with a fake key:
before:
ClientResponseError(_PickleSafeRequestInfo(url='http://host/v1/chat/completions',
method='POST', headers=<CIMultiDict('Authorization': 'Bearer sk-FAKE', ...)>, ...), ...)
after:
ClientResponseError(status=400, message='Bad Request', method='POST',
url='http://host/v1/chat/completions')
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tsvetan (Sven) Rankov <[email protected]>
f2a1958 to
44b1b1b
Compare
|
@yuhezhang-ai Thanks for catching this, and for the repro! Fixed in 44b1b1b:
The generic I also rebased onto current |
|
/ok to test 44b1b1b |
yuhezhang-ai
left a comment
There was a problem hiding this comment.
Thanks for addressing the logging issue! I rechecked this commit with a local HTTP 400 response through the vLLM client: credentials stay out of the transport log and debug output, while the original exception retains its request and response metadata. No further code changes requested; this addresses my earlier comment. Normal CI still needs to pass.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37090232148 |
Resolve the import conflict in tests/unit_tests/test_global_config.py by keeping both upstream's hide_secrets_in_overrides import (#3679) and this branch's rollout_collection import. Signed-off-by: Ananth Subramaniam <[email protected]>
…vers (#3818, #4070, #3929, #4053) into `r0.7.0` (#4107) ## What This PR only cherry-picks four already-merged `main` PRs into `r0.7.0`. It adds no new code. The commits are applied in their `main` merge order with `git cherry-pick -x`, so each commit message records its source commit. | Original PR | Commit on `main` | Change | |---|---|---| | #3818 | `325fb49d6` | feat(data): collate declared tasksets | | #4070 | `412efc730` | refactor: name episode requests and sessions without "native" | | #3929 | `1f2446c17` | feat(config): deprecate agents without an environment server and fix the migration script | | #4053 | `89c065b0e` | feat(config): support environment servers that front several agents | ## Why #4070 and #4053 carry the `r0.7.0` label, but the automatic cherry-pick workflow could not apply them: both hit merge conflicts on `r0.7.0`. The workflow still reports success, so the failure was silent. #3818 was intended for `r0.7.0` but never had the label. #3929 is included because #4053 builds on it. Every #4053 conflict came from #3929 changes to `nemo_gym/global_config.py`, `scripts/add_legacy_agent_environment_servers.py`, and their tests. With #3929 applied first, #4053 applies cleanly. ## Conflict resolution Picking #3818 first removed one #4070 conflict. The remaining conflicts were in tests that other PRs added on `main` after the branch cut: - **#4070**: renames identifiers, comments, and test names; no behavior change. Where the conflict was a test that exists only on `main` (`single_agent_turn`, SWE-bench Pro, and Hermes `test_agent_sessions.py`), the `r0.7.0` version is kept and the `main`-only test is not brought in. In `single_agent_turn_legacy`, the existing test is renamed to `test_flat_rows_and_episode_requests_project_the_same_result` to match `main`, and the `task_source` tests from a separate PR are left out. - **#3929**: one import line in `tests/unit_tests/test_global_config.py`. `main` also imports `hide_secrets_in_overrides`, added by #3679 and unused in this file, so the `r0.7.0` import is kept. - **#3818** and **#4053**: applied cleanly. ## Validation - `pytest tests/unit_tests/test_global_config.py tests/unit_tests/test_add_legacy_agent_environment_servers.py tests/unit_tests/test_rollout_collection.py tests/unit_tests/test_environment_server.py tests/unit_tests/test_task_materialization.py tests/unit_tests/test_benchmarks.py`: pass. - `pytest environment_servers/single_agent_turn/tests` and `pytest environment_servers/single_agent_turn_legacy/tests` (run separately): pass. - `pytest tests/unit_tests -n 8`: same failures as unmodified `r0.7.0` and no new ones. The existing failures are local-environment tests in `test_opensandbox_compose.py`, `test_sandbox_stop_retry.py`, and `test_slurm_script.py`. - `pre-commit run --files` on all changed files: pass. - Checked for old names #4070 renames (`_native_request`, `_native_episode_request_body`, `_native_session_locks`, `_closed_native_sessions`): none remain. The few remaining "native row" comments are also on `main`. - SWE-bench Pro and Hermes server tests were not run locally (they need per-server venvs); release-branch CI covers them. ## Rollout evidence N/A. Each change was reviewed and validated on `main`. This PR only carries them to the release branch: #4070 is a rename with no behavior change, and the config changes are covered by the unit tests above. --------- Signed-off-by: yaoyu-33 <[email protected]> Signed-off-by: Ananth Subramaniam <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]> Co-authored-by: Yu Yao <[email protected]> Co-authored-by: Felipe Vieira Frujeri <[email protected]>
What does this PR do?
Fixes both findings in #2222, one commit each, plus a related leak in the vLLM transport log that came up in review (third commit). The code has moved since the report: masking is now
looks_like_secret_keyinnemo_gym/secret_utils.py, and the debug print is inraise_for_statusinnemo_gym/server_utils.py.1. Secret masking (ERR-40044b75)
looks_like_secret_keyonly matched the lowercase substringstoken,keyandheader. It now matches case-insensitively and also coverspassword,passwd,secret,credential,bearer,cookieandauthorization. This only adds masking: every key masked today is still masked. The same masking is used bygym env resolve, the almost-server error, the W&B/MLflow run config and the recordedgym eval comparecommand.authorizationis needed because the masker walks into a headers mapping key by key, andAuthorizationmatched none of the old substrings. For example,gym env resolveon thevcqa_agentconfig printedartifact_request_headers.AuthorizationasBearer <HF_TOKEN>in plain text.The issue also suggested
auth,session,saltandsignature.authandsessionare left out because, as substrings, they would hide ordinary settings in this repo's configs (author,require_auth,max_concurrent_sessions,session_model,session_ttl_s);authorizationcovers the credential case ofauth. No config uses a key containingsaltorsignature. I also kept the denylist instead of inverting it to an allowlist: an allowlist would change what every existing config displays, which is a bigger change than this fix.recursively_hide_secretson a config with fake values:db_passwordsk-FAKE****DB_PASSWORDsk-FAKE****client_secretsk-FAKE****OPENAI_API_KEYsk-FAKE****apiKeysk-FAKE****Authorizationinside a headers mappingBearer sk-FAKE****policy_api_key********author,wandb_project1(int key)TypeError: argument of type 'int' is not iterable2. Debug request logging (ERR-fcaebf7d)
With
++global_aiohttp_client_request_debug=True, a failed model call printed every request header, including theAuthorization: Bearer <api key>thatNeMoGymAsyncOpenAIadds to each call. It now prints the method and the URL without its query string, reusing_redacted_urlas_format_upstream_error_logalready does.Output for a 401 from a local aiohttp server (fake key, abridged):
Before:
After:
3. vLLM transport log (raised in review)
With
NEMO_GYM_VLLM_TRANSPORT_LOGset, an HTTP error from the model endpoint was written to the log asrepr(e).raise_for_statuskeeps the request headers on the exception, so thetransport_error_responseevent contained theAuthorization: Bearer <api key>header. The event now records only the error type, status, message, method and the URL without its query string; response headers are left out as well.raise_for_statusis unchanged, so other callers still get the full exception metadata.The generic
transport_errorevent keepsrepr(e): aClientResponseError(includingPermanentEndpointError) never reaches that handler, and the connection errors and timeouts that do carry no request headers.The
errorfield for a 400 from a local endpoint (fake key, abridged):Before:
After:
Closes #2222
Validation
All on the branch rebased onto
mainatd09fe41d3;git range-diffshows the first two commits unchanged by the rebase.gym env test +entrypoint=responses_api_models/vllm_model +should_validate_data=true(the CI server-test command) in a fresh environment synced fromuv.lock: 330 passed.NEMO_GYM_VLLM_TRANSPORT_LOGset, one/v1/chat/completionscall. Before, theerrorfield contains'Authorization': 'Bearer <fake>'; after, the fake key appears nowhere in the log file, and with++global_aiohttp_client_request_debug=Truenowhere in the console output either.pyteston every unit-test file that imports a changed module (grep -rlE 'nemo_gym\.(secret_utils|server_utils)|from nemo_gym import (secret_utils|server_utils)' tests/unit_tests, 23 files) plustest_compare.py,test_public_api.pyandtest_openai_utils.py: 1801 passed, 27 skipped, 2 failed. The failures aretest_cli.py::TestRunHelperServerReadiness::test_memory_profiler_uses_spawned_server_metadataandtelemetry/test_connection_pool.py::test_multi_destination_waits_are_attributed_to_the_binding_limit, which fail the same way on unmodifiedmainon macOS.pytest tests/unit_tests --continue-on-collection-errors: 6435 passed, 175 skipped, 20 failed. The failures are intest_opensandbox_compose.py(11),test_ci_environment.py(3),telemetry/test_memory.py(2),test_cli.py(memory profiler),test_enroot_provider.py,test_sandbox_stop_retry.pyandtelemetry/test_connection_pool.py. All 20 fail the same way on unmodifiedmainon macOS.Authorization) come out in plain text, the int key raisesTypeError, and the case-insensitive overrides test fails. The debug-print test finds the fake bearer token in the output, and the transport-log test finds the fake key in the log file. The two exporter tests pass either way: they are guards that masking still switches the exporters off, not reproductions of the bug.HF_TOKEN=<fake> gym env resolvewith thevcqa_agentandopenai_modelconfigs:Authorization: Bearer <fake>before,Authorization: '****'after, and the fake value appears nowhere in the output.test_global_config.py,test_exporters.py,test_server_utils.pyandtest_public_api.pyon its own.detect-secrets-hook1.5.0 with the CI baseline (.github/workflows/config/.secrets.baseline) on each of the 8 changed files: passed.pre-commit run --all-files: passed.Rollouts
N/A: no agent, verifier or environment behavior changes. This only changes how configs are masked for display/export, what a debug-only print shows, and what the opt-in vLLM transport log records for HTTP errors.
Compatibility and benchmark impact
****ingym env resolve, W&B/MLflow run configs and the recordedgym eval comparecommand. Live config values are unchanged.MASKED_VALUEstays"****", soWANDBConfig/MLFlowConfig.is_availablestill treat a masked config as unconfigured. New tests run the real masker over both exporter configs to cover this.Request info: <METHOD> <URL without query>. The signature ofraise_for_statusis unchanged, and.agents/skills/nemo-gym-debugging/references/request-boundary-visibility.mdis updated.errorfield oftransport_error_responseevents is nowClientResponseError(status=…, message=…, method=…, url=…)instead of the fullrepr, so it no longer includes request or response headers.http_statusandraw_response_bodyare unchanged, and nothing in the repo parseserror.max_tokensare still masked because they containtoken. Narrowing that is left for a separate PR, since it would unmask keys that are masked today.Checklist
pre-commit run --all-files) (so CI lint/format checks pass).git commit -s) (so the DCO check passes).