feat: remove OPENAI_API_KEY from env and mlock if set #4243
+151
−14
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.
This is potentially breaking behavior, as we now actively remove
OPENAI_API_KEY
from the environment so that subprocesses cannot inherit this value. We make it available within the codebase as a&'static str
, but on UNIX, we usemlock(2)
to ensure this value remains resident in RAM and is never paged out to disk. (Admittedly, any logic that makes a local copy of this value could still be paged out to disk.)Removing
OPENAI_API_KEY
from the environment entails anunsafe
use ofstd::env::remove_var()
, so we exercise this logic as part ofarg0_dispatch_or_else()
to ensure we use it before any threads are created.Note we make this modification after the checks for
codex_linux_sandbox::run_main()
andcodex_apply_patch::main()
to ensure we do not modify the environment in those cases.Stack created with Sapling. Best reviewed with ReviewStack.