Repository navigation
feat(engine): let a caller withhold an inherited endpoint key file #1034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,9 @@ const fn stdio_options<'a>( | |
| app_paths: paths, | ||
| env_root, | ||
| endpoint_key_file: None, | ||
| // An external plugin is a third-party binary: never hand it a path to | ||
| // a live endpoint credential, including one we inherited ourselves. | ||
| withhold_inherited_key_file: true, | ||
| request_progress: stream_progress, | ||
| forward_stderr: true, | ||
| note_failing_exit_after_answer: false, | ||
|
|
@@ -385,6 +388,30 @@ mod tests { | |
| use super::*; | ||
| use crate::tests::test_paths; | ||
|
|
||
| /// `rocm` must actually ASK for the withholding, not merely be able to. | ||
| /// | ||
| /// The protocol crate's own test proves the flag causes the clearing; this | ||
| /// is the other half of the chain, and without it flipping the value here | ||
| /// to `false` would re-open the leak with every test still green. Asserted | ||
| /// on `stdio_options` rather than on a built `Command` because | ||
| /// `engine_stdio_command` is private to the protocol crate. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
| #[test] | ||
| fn every_external_plugin_spawn_asks_to_withhold_the_endpoint_key_file() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please confirm (and note in the PR body) that you broke this by flipping the flag to false and saw this test go red, and that every plugin spawn path goes through stdio_options. |
||
| for stream_progress in [false, true] { | ||
| let options = stdio_options(None, None, stream_progress); | ||
| assert!( | ||
| options.withhold_inherited_key_file, | ||
| "an engine plugin is a third-party binary: `rocm` must withhold \ | ||
| an inherited key-file path from it, whatever else this request \ | ||
| asks for" | ||
| ); | ||
| assert!( | ||
| options.endpoint_key_file.is_none(), | ||
| "and it must never hand one over either" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn engine_plugin_discovery_finds_runtime_binary() -> Result<()> { | ||
| let (root, paths) = test_paths("engine-plugin"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,15 @@ pub struct EngineStdioOptions<'a> { | |
| /// its HTTP probe of a protected endpoint authenticates. The caller decides | ||
| /// whether a file holds a usable key; this only carries it. | ||
| pub endpoint_key_file: Option<&'a Path>, | ||
| /// With no `endpoint_key_file`, also CLEAR [`ENDPOINT_API_KEY_FILE_ENV`] | ||
| /// rather than leave whatever this process inherited to pass through. | ||
| /// | ||
| /// For a child that must not see a credential path at all — `rocm`'s | ||
| /// external engine plugins are third-party binaries. Off by default, | ||
| /// because "no key file for this request" and "this child may not have one" | ||
| /// are different statements: `rocmd` passes `None` for a loopback service | ||
| /// that simply needs no key, and its children are its own. | ||
| pub withhold_inherited_key_file: bool, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail-open default: a new caller that forgets this bool leaks by default. Consider a 3-state enum ( |
||
| /// Ask the engine for progress on stderr ([`ENGINE_PROGRESS_STDERR_ENV`]). | ||
| pub request_progress: bool, | ||
| /// Write the child's stderr to this process's stderr as it arrives, so a | ||
|
|
@@ -155,6 +164,14 @@ where | |
| } | ||
| if let Some(key_file) = options.endpoint_key_file { | ||
| command.env(ENDPOINT_API_KEY_FILE_ENV, key_file); | ||
| } else if options.withhold_inherited_key_file { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This precedence is not covered: |
||
| // Cleared, not merely left unset: a value this process inherited must | ||
| // not reach a third-party plugin binary just because nothing | ||
| // overwrote it. Only for callers that ask — `rocmd` passes `None` for | ||
| // a loopback service that needs no key, and clearing there would | ||
| // change what its own children see. See | ||
| // `an_external_plugin_child_is_not_handed_the_endpoint_key_file`. | ||
| command.env_remove(ENDPOINT_API_KEY_FILE_ENV); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please confirm no other rocm plugin spawn path bypasses
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only the key-file path variable is cleared. If any other inherited variable carries the endpoint key itself, a third-party plugin would still see it; worth confirming none exists. |
||
| } | ||
| if options.request_progress { | ||
| command.env(ENGINE_PROGRESS_STDERR_ENV, "1"); | ||
|
|
@@ -675,6 +692,68 @@ mod tests { | |
| assert!(added_env(&command).is_empty(), "{:?}", added_env(&command)); | ||
| } | ||
|
|
||
| /// A child told it gets no endpoint key must have the variable CLEARED, | ||
| /// not merely left unset. | ||
| /// | ||
| /// `rocm` passes `endpoint_key_file: None` for every external engine | ||
| /// plugin — a third-party binary — and the path it would otherwise carry | ||
| /// points at a mode-0600 file holding a live endpoint credential. Merely | ||
| /// not setting it would still hand the value through whenever this process | ||
| /// inherited one. | ||
| /// | ||
| /// Asserts the distinction directly: `Command` records `env_remove` as an | ||
| /// explicit `(key, None)` entry, so a plain "is it absent" check would pass | ||
| /// even with the clearing deleted. | ||
| #[test] | ||
| fn an_external_plugin_child_is_not_handed_the_endpoint_key_file() { | ||
| let key_var = std::ffi::OsStr::new(ENDPOINT_API_KEY_FILE_ENV); | ||
| let command = engine_stdio_command( | ||
| Path::new("/an/engine"), | ||
| ["stdio"], | ||
| &EngineStdioOptions { | ||
| app_paths: None, | ||
| env_root: None, | ||
| endpoint_key_file: None, | ||
| withhold_inherited_key_file: true, | ||
| request_progress: false, | ||
| forward_stderr: false, | ||
| note_failing_exit_after_answer: false, | ||
| }, | ||
| ); | ||
|
|
||
| let entry = command | ||
| .get_envs() | ||
| .find(|(key, _)| *key == key_var) | ||
| .map(|(_, value)| value); | ||
| assert_eq!( | ||
| entry, | ||
| Some(None), | ||
| "the key-file variable must be explicitly CLEARED when no key file \ | ||
| is passed, not merely left unset" | ||
| ); | ||
|
|
||
| // The other direction, which is what keeps this scoped: a caller that | ||
| // did not ask (`rocmd`, for a loopback service that simply needs no | ||
| // key) must leave the child's inherited value alone. | ||
| let kept = engine_stdio_command( | ||
| Path::new("/an/engine"), | ||
| ["stdio"], | ||
| &EngineStdioOptions { | ||
| app_paths: None, | ||
| env_root: None, | ||
| endpoint_key_file: None, | ||
| withhold_inherited_key_file: false, | ||
| request_progress: false, | ||
| forward_stderr: false, | ||
| note_failing_exit_after_answer: false, | ||
| }, | ||
| ); | ||
| assert!( | ||
| kept.get_envs().all(|(key, _)| key != key_var), | ||
| "a caller that did not ask to withhold must not touch the variable" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn each_option_sets_exactly_its_own_variable() { | ||
| let paths = AppPaths { | ||
|
|
@@ -689,6 +768,7 @@ mod tests { | |
| app_paths: Some(&paths), | ||
| env_root: Some(Path::new("/envs")), | ||
| endpoint_key_file: Some(Path::new("/keys/svc.endpoint-key")), | ||
| withhold_inherited_key_file: false, | ||
| request_progress: true, | ||
| forward_stderr: true, | ||
| note_failing_exit_after_answer: false, | ||
|
|
@@ -722,6 +802,7 @@ mod tests { | |
| "ROCM_SERVE_API_KEY_FILE", | ||
| EngineStdioOptions { | ||
| endpoint_key_file: Some(Path::new("/keys/k")), | ||
| withhold_inherited_key_file: false, | ||
| ..EngineStdioOptions::default() | ||
| }, | ||
| ), | ||
|
|
@@ -1143,6 +1224,7 @@ mod tests { | |
| app_paths: Some(&paths), | ||
| env_root: Some(Path::new("/envs")), | ||
| endpoint_key_file: Some(Path::new("/keys/k")), | ||
| withhold_inherited_key_file: false, | ||
| request_progress: true, | ||
| forward_stderr: false, | ||
| note_failing_exit_after_answer: false, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing tests that rocm actually sets this flag: the new test hand-builds
EngineStdioOptionsin the protocol crate, so flipping this tofalsekeeps every test green and re-opens the leak. Please add a test over rocm's own stdio options / plugin command asserting the key var is explicitly cleared, or make withholding the default.