Repository navigation
feat(box): read each declared secret at startup and deliver it - #500
Conversation
## Problem The credentials crate reads a secret from a vault only through its built-in `op://` source. A second vault, such as AWS Secrets Manager, needs a new source in the crate, with its own dependencies and its own review. The secret provider design (#467) replaces that with one contract. The caller declares a host program, and the box runs it at startup and reads one secret from its stdout. The crate has no way to run a declared program. ## Solution Add a declared secret source to the credentials crate. Nothing reads it from `box.toml` yet, so a box behaves as before. - `SecretSourceCommand` declares one program for one scheme: the protocol (`box.secret-source.v1`), the command, the output form (`text` or `json`), and two pass lists. Its constructor refuses a reserved or malformed scheme, another protocol, and an empty command. It also refuses a program that is not an absolute path, and a command with no `{ref}` in its arguments. A pass list refuses the entries `*`, `PATH`, and `HOME`, and an entry with a `*` before its end. Each refusal names the key and the entry. - The runner starts the program with no shell and no stdin, in `/`. The environment is `HOME`, `PATH=/usr/bin:/bin`, and each pass-list variable that is set. An entry that ends with `*` passes each variable with that prefix. A run of more than 30 seconds, more than 1 MiB of stdout, or a non-zero exit fails the fetch. A failure carries the end of stderr, at most 512 bytes, with the reference name and each passed `pass_secret_env` value replaced. - `{ref}` (`SECRET_REFERENCE_TOKEN`) is the text after `scheme://` without `#FIELD`. The source replaces it inside each argument, and refuses a reference whose text after `scheme://` starts with `-`. - With `output = "json"`, stdout is one JSON string. With `#FIELD`, the secret is a JSON object, and the source returns that one string field. Without `#FIELD`, a secret that is a JSON object is refused. The JSON field step and its wipe helpers follow #448. - `RESERVED_SECRET_SCHEMES` lists the schemes that no declaration can claim, and `SecretSourceCommand::check_scheme` is the check. - `Backend::declared(declarations)` registers `env`, `file`, and one source for each declaration. A declared `op` takes the place of the built-in `op://` source. The backend keeps each fetched secret, so two references that differ only in `#FIELD` run the program once. Interfaces that moved: - The `pub use` set of the crate grows from 20 names to 23: `SecretSourceCommand`, `SECRET_REFERENCE_TOKEN`, `RESERVED_SECRET_SCHEMES`. - `SecretSourceCommand` has the constant `PROTOCOL` and the functions `new`, `check_scheme`, `output`, `pass_env`, and `pass_secret_env`. - The URI vocabulary of the crate gains `SCHEME://NAME[#FIELD]` for a declared scheme. `#` starts a field only for a declared scheme. - `Backend` gains the constructor `declared`, and is now `Clone`. Each clone shares the same sources and the same fetched secrets. The held secrets have no accessor. - `Backend::local()` is the same: `env`, `file`, and the built-in `op`. ## Tests Each test uses a stand-in program, a shell script in a temp dir. No test runs a real `op` or `aws`. - `cargo test -p strands-box-credentials --all-features --locked`: 292 unit tests and 33 integration tests passed on macOS. 289 unit tests and 33 integration tests passed in an Amazon Linux 2023 container. 55 unit tests are new. - The declaration: `each_reserved_scheme_is_refused_by_name`, `a_command_with_no_reference_token_in_its_arguments_is_refused`, `a_pass_list_entry_that_has_no_effect_or_passes_every_variable_is_refused`. - The environment: `the_program_gets_only_home_the_fixed_path_and_the_passed_variables`, `a_variable_with_a_name_that_is_not_utf8_does_not_pass`. - No stdin, the directory `/`, no shell, `{ref}`: `the_program_gets_no_stdin`, `the_program_starts_in_the_root_directory`, `each_argument_reaches_the_program_as_one_argument_with_no_shell`, `a_malformed_reference_is_refused_before_the_program_starts`. - The bounds: `a_program_that_runs_past_the_timeout_is_stopped`, `stdout_up_to_the_limit_is_read_and_one_more_byte_is_refused`, `a_program_that_never_stops_writing_is_stopped_at_the_limit`, `a_program_that_leaves_its_stdout_open_fails_at_the_deadline`. - The failure text: `a_non_zero_exit_is_a_failure_that_carries_stderr`, `a_failure_hides_the_reference_and_each_passed_credential_and_each_control_character`, `a_failure_hides_a_passed_credential_that_is_not_utf8`, `a_failure_carries_at_most_512_bytes_of_stderr`, `the_excerpt_hides_a_whole_hidden_value_near_the_start_of_a_cut_capture`. - The output and the field: `json_output_is_one_json_string_and_any_other_value_is_refused`, `a_field_selects_one_string_of_a_json_object_and_any_other_case_is_refused`, `a_json_object_without_a_field_is_refused`. - One fetch: `two_references_that_differ_only_in_the_field_run_the_program_once`, `each_clone_of_a_declared_backend_shares_one_fetch`, `two_callers_at_one_time_run_the_program_once`. - The backend: `a_declared_op_takes_the_place_of_the_built_in_source`, `local_holds_the_env_file_and_op_schemes`. - Clippy for the workspace (`--all-targets --all-features -D warnings`) and the rustdoc gate of the crate are clean in the container. Not run: the full workspace suite, because no other crate calls the new surface. No test can observe the wipe of a value that drops, a parsed JSON value or a copied environment value; `a_wipe_empties_each_string_of_a_parsed_value` tests the helper.
The README example names `OP_SESSION_*`, the variable of `op signin`, and did not pass `TMPDIR`. `op` 2.42.0 on macOS keeps the session of `op signin` in a folder under `TMPDIR`. With `HOME`, `PATH`, and `OP_SESSION_*` alone it says that no session is active, and with `TMPDIR` too it finds the session. The code does not change. `pass_env` accepts `TMPDIR`.
… the crate The reserved scheme list did not hold `strip-phantom`, the scheme of the crate's second route marker (`strip-phantom://route`). So a declaration could claim it. The list now holds it, and `SecretSourceCommand::check_scheme` refuses a declaration of that scheme. `RESERVED_SECRET_SCHEMES` and `SECRET_REFERENCE_TOKEN` were public, and no other crate reads them. The crate adds a public item only for a named external caller, so both are now private to the crate. `SecretSourceCommand::check_scheme` stays the one check of a scheme for a caller. The `pub use` set of the crate is now 21 names, one more than before this PR: `SecretSourceCommand`. Tests: `the_reserved_schemes_are_the_nine_the_box_owns` and `each_reserved_scheme_is_refused_by_name` fail when `strip-phantom` leaves the list.
… each owner The reserved scheme list held each scheme as a second literal, beside the constant of the code that owns it. An earlier revision of this change missed `strip-phantom` for that reason. The list now takes each name from its owner. Six names come from the scheme constants of the crate: `env`, `file`, `aws`, `credsd`, `cmd`, and `oauth2`. Two come from the route markers `aws-signed://route` and `strip-phantom://route`. Only `secret` stays a literal, because the box crate owns it. The nine names and their order do not change. Tests: `each_scheme_constant_and_each_route_marker_of_the_crate_is_reserved` fails when the list holds a literal and the constant of its owner changes. `the_reserved_schemes_are_the_nine_the_box_owns` still compares the nine literal names, because a refusal prints the list.
…ut a field A declared source refuses a secret that is a JSON object when the reference has no `#FIELD`, with each `output`. The built-in `op://` source returns such a secret whole. So a declared `op`, which takes the place of the built-in source, differs from it here. The docs did not say so, and the README row for `text` read as if stdout always passes. The rule stays for each `output`, as the design (#467) states it: one destination never gets each key of an object. A check for `json` alone lets a program that prints an object as text pass it whole. - `a_declared_op_refuses_a_json_object_without_a_field_in_text_output` pins the refusal for scheme `op`. - `returns_a_json_object_whole` pins what the built-in source does with the same stdout. - The README rows for `output` and `#FIELD` state that the rule holds for each `output`, and name the difference.
…itself `each_scheme_constant_and_each_route_marker_of_the_crate_is_reserved` asked `check_scheme` for a refusal. A malformed scheme is refused too. So the test passed when a scheme constant held a malformed text, and when a route marker had a form that `scheme_of` and `Locator::scheme` read differently. The test now looks for each scheme in the list. - `crates/credentials/AGENTS.md` says that no code collects the constants, so each new scheme constant and each new route marker goes into the list and into this test. - The README row for `#FIELD` says "all the keys". - `a_declared_op_refuses_a_json_object_without_a_field_in_text_output` builds its backend with the helper of its file, which gives the program an empty operator environment, as the other tests of a refusal do.
## Problem A box can name a secret only as `env://NAME` or `aws://`. An operator with a vault, such as 1Password, must wrap `box run` in `op run` to put each secret in a variable first. The secret provider design (#467) replaces that: `box.toml` declares the host program that reads a secret, and a route names the secret in that program's scheme. The credentials crate can run a declared program, but `box.toml` has no key that declares one, and each place that names a secret refuses a provider scheme. ## Solution Load a `[secret-source.<scheme>]` table, check it, and store it in the record. Accept a declared scheme at each place that names a secret, and refuse each unsafe configuration when it loads. No step reads a secret yet, so a box that declares a source passes the load checks, stores its record, and does not start. - `record::config::secret_source` holds the table (`protocol`, `command`, `output`, `pass-env`, `pass-secret-env`, `reads`, `deny`) and its one check, `DeclaredSources::check`. The check refuses a table on an operating system other than macOS, a table without `[experimental-features] secret-sources = true`, a reserved scheme, an absent `protocol`, and each declaration that `credentials::SecretSourceCommand` refuses. It also refuses a `reads` or `deny` entry that is not absolute, is not `~`, and does not begin with `~/`. - `secret.env` names the variable that holds the placeholder. It needs the same switch as the table, on each operating system, also on `env://NAME` where it has no effect. A route or a remote MCP server in a declared scheme requires it. On `env://NAME` it is optional and equals `NAME`. A signed secret and a backend `auth` take none. - One placeholder variable holds one secret. Two entries with one variable and different references are refused, and the refusal names both tables. An `env://NAME` entry counts under `NAME`. Beside a signed route, no other route holds a placeholder in `AWS_ACCESS_KEY_ID` or `AWS_SECRET_ACCESS_KEY`, which that route fills. The own secret of a re-routed entry is not such a route. - A telemetry `secret.ref` and a backend `auth.ref` accept a declared scheme. The own secret of a re-routed entry stays `env://`. - A telemetry `secret.ref` takes `env://NAME`, `secret://NAME`, `aws://PROFILE`, `credsd://ENVIRONMENT`, or a declared scheme, and one refusal text names the five. A `langfuse` or `langsmith` target takes a declared scheme and keeps the placement of its vendor. A CloudWatch kind is signed, so it refuses one. - A route in a declared scheme takes `phantom_prefix`, `inject`, and the placement keys, as an `env://` route does. - `env://NAME` and `secret://NAME` are refused when a `pass-secret-env` entry names `NAME`, prefix entries included, on a route, a remote MCP server, a backend `auth.ref`, and a telemetry target. - A reference in a scheme that no table declares is refused. The message names the table to declare, and it says that Box loads a source on macOS only. - `run` stops after the load checks when the record declares a source. `policy generate-schema` now judges each remote MCP server as `run` does, and stops for one in a declared scheme. Without these refusals, the local backend runs its built-in `op://` source and ignores the declaration. Interfaces that moved: - `box.toml`: a fourteenth top-level key, `[secret-source.<scheme>]`; `[experimental-features] secret-sources`; `secret.env` on `[egress.<name>]` and on `[mcp.<name>] type = "http"`, behind that switch; a declared scheme in `secret.ref` and in a backend `auth.ref`. - The stored record: the `secret-source` map and the `env` key of a secret. A record that holds either one is version 38. - The decision `an-undeliverable-credential-is-refused-at-load` is rewritten: a provider scheme is valid only when its provider is declared. - `credentials::SecretSourceCommand::passes_as_secret` is `pub`. - `policy generate-schema` judges each remote MCP server as `run` does. It refuses an undeclared `op://` or `file://` reference there, which the built-in sources read before. - An ordinary `env://AWS_ACCESS_KEY_ID` or `env://AWS_SECRET_ACCESS_KEY` route beside a signed route is refused at load, on `run` and on `policy generate-schema`. Before, the vault refused the variable at startup. - Four refusal texts change for a configuration with no declaration: the `inject` and `phantom_prefix` refusals on a signed route and the telemetry `secret.ref` refusal name a declared scheme too, and a reference in a scheme that Box does not reserve gets the text that names the table to declare. ## Tests On this commit, on `main` `ab29afd3` (after #314 and #444): - Amazon Linux 2023 container (x86_64, Rust 1.98.1): workspace clippy with `-D warnings` is clean, and `cargo fmt --all --check` is clean. The full `strands-box` unit suite passed 1,116 tests and failed 16 in `run::broker`, `run::contain`, and `run::hosted`, the same 16 as on the commit before this change. `cargo test -p strands-box-credentials` passed 293 unit tests and 33 integration tests. The guards `site_manifest`, `documented_inputs`, `four_inputs`, `documented_commands`, and `credential_method_scope` passed (36 tests). One test of the telemetry crate fails there, `export::tests::the_vault_attaches_a_credential_on_an_ipv6_address`: it fails in the same way on the commit before this change, because the container has no IPv6 loopback. - macOS (arm64, Rust 1.96.0), the test targets of this change: `box_credentials` passed 29 tests and ignored 1, `mcp_schema_generation` passed 21, the unit tests of the changed modules passed 390, and `strands-box-credentials` passed 296 unit tests and 33 integration tests. - macOS, the built binary with two hand-written `box.toml` files. One holds a route and a `langsmith` target in the declared `op` scheme: it stores a version 38 record, with the target as an `otlp` target under `x-api-key`, and stops before the stand-in program runs. The other is that file with no `[secret-source.op]` table: it is refused, and the refusal names the table and says that Box loads a source on macOS only. - Two undo patches, each run on the last commit of this stack: without the declared-scheme arm of `telemetry_secret_uri`, four telemetry tests of a declared scheme fail; with the first two arms of `record_version` in the other order, `a_placeholder_variable_key_stores_the_secret_source_version` fails (37, not 38). Before the rebase onto `ab29afd3`, and not repeated on this commit: - macOS: `cargo test --workspace --all-features --locked --no-fail-fast` passed 3,515 tests in 155 targets, and none failed. - macOS, the built binary with 18 hand-written `box.toml` files: one valid configuration stores its record and stops before the stand-in program runs, 16 configurations are refused and store no record, and one `env://` configuration with no declaration starts its workload and stores a version 21 record. - The container, the built binary with four hand-written `box.toml` files: a `secret.env` key with no switch, an `env://AWS_ACCESS_KEY_ID` route beside an `aws://` route, a `strip-phantom://` route, and a declaration on Linux are each refused, and none stores a record. - The container, through the built binary, in a scratch copy with only the test's launcher probe forced on: `an_undeliverable_credential_scheme_is_refused_at_configure`, `a_declared_secret_source_is_refused_where_no_protection_is_built`, and `a_placeholder_variable_key_is_refused_while_the_switch_is_off` passed. - 56 undo patches, one for each new check: each made its test fail. 51 ran in the container, and the 5 whose tests need a loaded declaration ran on macOS. What each behavior claim rests on: - The switch and the macOS-only load: `a_declaration_without_the_feature_is_refused`, `a_declaration_on_an_unprotected_operating_system_is_refused`, `a_secret_source_table_needs_the_secret_sources_switch`. - The table and its refusals: `a_reserved_or_malformed_scheme_is_refused`, `a_declaration_without_a_protocol_is_refused`, `each_refusal_of_the_declaration_constructor_reaches_the_operator`, `a_reads_or_deny_entry_that_is_not_a_host_path_is_refused`, `an_unknown_key_is_a_parse_error`. - An undeclared scheme: `an_undeliverable_credential_scheme_is_refused`, `an_undeliverable_credential_scheme_is_refused_at_configure`. - `secret.env`: `a_declared_route_needs_a_placeholder_variable_and_provisions_it`, `a_declared_route_may_not_claim_a_reserved_variable`, `a_placeholder_variable_on_another_scheme_is_checked`, `a_placeholder_variable_key_needs_the_secret_sources_switch`, `a_stored_placeholder_variable_key_needs_the_stored_switch`. - One variable, one secret: `one_placeholder_variable_with_two_references_is_refused`, `one_placeholder_variable_across_egress_and_remote_mcp_is_refused`, `a_placeholder_in_a_signing_variable_beside_a_signed_route_is_refused`. - The other `secret.*` keys: `a_declared_route_takes_the_other_secret_keys`. - Backend `auth.ref` and telemetry `secret.ref`: `a_backend_auth_takes_a_declared_scheme_and_the_destination_secret_does_not`, `a_secret_reference_is_normalized_and_a_literal_is_refused`, `a_target_takes_a_declared_scheme_and_no_placeholder_variable`, `a_vendor_kind_takes_a_declared_scheme`. - The vault's own credential: `a_reference_to_the_credential_of_a_declared_source_is_refused` (in `egress.rs` and in `telemetry.rs`), `a_pass_secret_env_entry_names_the_credential_of_its_source`. - The record: `a_declaration_is_stored_at_a_version_no_earlier_build_reads`, `a_placeholder_variable_key_stores_the_secret_source_version`, `a_stored_declaration_is_checked_again_when_the_record_is_read`, `a_stored_route_in_an_undeclared_scheme_is_refused_when_it_is_read`. - No step reads a secret: `a_record_that_declares_a_secret_source_does_not_start`, `a_declared_secret_source_is_stored_and_the_box_does_not_start`, `offline_schema_generation_refuses_a_declared_secret_source`, `offline_schema_generation_refuses_an_undeclared_scheme`. - The reserved list and the fourteen keys: `the_reserved_schemes_are_the_nine_the_box_owns`, `no_secret_source_can_claim_a_scheme_that_a_target_reads_itself`, `the_config_record_carries_only_the_four_inputs`. Not run: a real `op` or `aws`, because no step reads a secret. The full macOS suite on this head. The other box integration targets on Linux, which need a sandbox that the x86_64 container cannot build.
## Problem Box loads a `[secret-source.<scheme>]` table, checks it, and stores it, and then refuses to start, because no step reads a secret through the table. So an operator with a vault still wraps `box run` in the vault's own launcher. The credentials crate can run a declared program, but it starts the program by its path with no check of the file, and each caller in the box reads through `Backend::local()`, which ignores a declaration. ## Solution Run each declared program when the box starts, read each secret once, and deliver it: the workload holds a placeholder, and the gateway adds the real value to a request that policy permits. - `run::secret_sources::SecretSources` holds the declared sources of one run: the checked program of each one, and the one backend that reads through them. `SecretSources::open` checks each program file with `ConfiguredCommand::load`, which is the check of a configured tool command, now a function of its own. A program that is missing or cannot execute is refused with its table name. - `ConfiguredCommands::load` holds the program of each declaration beside the tool commands. A source program also holds each symbolic link that the resolution of its path passes through. So a write grant that covers the program path, the file that it resolves to, a link on the way, or a folder that holds one of them is refused, and the Shell and Monty refuse a change to them. The record stores no program identity, so this is what keeps a workload from replacing the program for the next run. `SecretSources::refuse_writable_programs` makes the write-grant check before the first read, in `run` and in `policy generate-schema`, so a refused box never starts the program. That check and the later one in `ApprovedReach::judge_with` take their tables from `Record::process_tables`, so a table that one judges, the other judges too. - The runner in `credentials` keeps the opened program file. It starts the program only while the declared path names that file, by device and inode, and it compares again after the program exits. A mismatch fails the read, and the output of that run is not read. - `command::run::execute` reads in two steps. It reads the secrets of telemetry targets before `telemetry::open`, because the collector needs them. It reads the others in `hosted`, after these checks, which need no secret: the policy, the credsd preflight, the `aws://` telemetry preflight, the tool commands, and the tool grammars. The checks of `HostedBox::open` come after that read, such as the refusal of a write grant over a tool command. Any read that fails stops startup before a workload starts. A read that fails in the first step is on stderr only. - One backend serves the run: the telemetry secret, each vault of `run::credential`, and `policy generate-schema`. So a telemetry target and a route with one secret run the program once. - Each telemetry target holds its secret in a vault of its own (#314). `record::config::telemetry::resolved_secret` opens that vault with the backend of the run, after the first step has read the secret, so the open starts no program. `preflight_aws` keeps `Backend::local()`: an `aws://` reference is in no declared scheme, and a signed route reads nothing through the backend. - A route in a declared scheme provisions its `secret.env` variable for the agent, each tool, each stdio MCP server, and the Shell. Box does not read the operator's value of that variable. - Box prints one line on stderr for each declared source, with its program, before any program runs. - Each read of a configuration entry is one `secret_fetched` control-plane record: the entry, the source, the program, and the reference with its body redacted. - A failed read is two lines on stderr. The first holds the error of `credentials`, with the last words of the program. The second is the refusal, which names the entry that holds the reference and holds no text of that error. The `box_stopped` record takes its reason from the refusal, so no record holds a word that the program printed. - `credential::project` opens each vault and then closes the declared sources: the backend wipes each held secret, and a later read through a declared source fails. - `policy generate-schema` reads a remote MCP secret through the declarations of the file that `--config` names. It checks the program files and the write grants, prints the lines, and reads each declared secret only when a server names a secret in a declared scheme, and before it starts a stdio MCP server. - `command::run::refuse_declared_sources` and the `SecretSourceFetch` refusal of `read_remote_mcp_servers` are removed. Interfaces that moved: - The composed environment: the workload gets the placeholder of a declared-scheme route under its `secret.env` variable. - `credentials::Backend::declared` takes each `SecretSourceCommand` with the opened program file that the caller checked. `credentials::Backend::close_declared` is new. The `pub use` set does not change. - `telemetry::ControlOperation` gains `SecretFetched`, with the wire text `secret_fetched`. - Stderr at startup: one line for each `[secret-source.<scheme>]` table. - A write grant over the program of a secret source is refused, on `run` and on `policy generate-schema`, which now judges the filesystem lists for that. - `policy generate-schema` starts the declared program, outside every sandbox, for a remote MCP server whose secret names a declared scheme. - `run` and `policy generate-schema` no longer refuse a configuration that declares a secret source. The checked program identity is held in memory for the run, as the open file. The stored record does not hold it, because each run checks the file again. No check compares a grant with `reads` and `deny` yet. ## Tests On this commit, on `main` `ab29afd3` (after #314 and #444): - Amazon Linux 2023 container (x86_64, Rust 1.98.1): workspace clippy with `-D warnings` is clean, and `cargo fmt --all --check` is clean. The full `strands-box` unit suite passed 1,134 tests and failed 16, the same 16 that fail on the commit before this change because of container limits. The `credentials` suite passed 297 unit and 33 integration tests. The five doc guards passed (37 tests). One test of the telemetry crate fails there, `export::tests::the_vault_attaches_a_credential_on_an_ipv6_address`: it fails in the same way on the commit before this change, because the container has no IPv6 loopback. - macOS (arm64, Rust 1.96.0), the test targets of this change: `box_credentials` passed 32 tests and ignored 1, `mcp_schema_generation` passed 26, the unit tests of the changed modules passed 409, and `strands-box-credentials` passed 300 unit tests and 33 integration tests. The box test `a_telemetry_target_and_a_route_with_one_secret_run_the_program_once` passed through the binary: the program ran once, and the endpoint of the target got its field of the secret. This ran before the last change of this commit, which is one docs paragraph. - One undo patch, run on the code of the last commit of this stack: with `Backend::local()` in place of the backend of the run in `resolved_secret`, `a_target_secret_in_a_declared_scheme_is_read_through_the_given_backend` fails. Before the rebase onto `ab29afd3`, and not repeated on this commit: - The container, the macOS-only tests that need no sandbox, in a scratch copy with the operating-system check forced on: 353 unit tests and 9 tests through the built binary passed. - macOS: the full workspace suite passed 3,542 tests and failed 6. One was a test of this change whose box name was 33 bytes, over the limit of 32: the test now uses a shorter name, and it passes. The other 5 failed on a time limit in that one run, in files that this change does not touch, and each passed in the full suites before and after it. A real box with a stand-in program reached a public echo host with the secret. - 54 undo patches, one for each new check: each made its test fail. 38 ran in the container, and the 16 that need a box ran on macOS. - A real `op` 2.42.0 and a real `aws` 2.27.52 ran by hand on macOS on 2026-11-17, with the commit that follows this one and a Box CLI plugin on top: the workload held a placeholder, and the request carried the real secret. What each behavior claim rests on: - The program check before a read: `a_program_that_box_cannot_check_is_refused_before_a_fetch`. - A program path that names another file stops the read: `a_program_path_that_names_another_file_after_the_check_does_not_start`, `a_program_path_that_changes_while_the_program_runs_gives_no_secret` (the runner), `a_program_path_that_names_another_file_after_the_check_stops_the_fetch` (the box). - A write grant or an interpreter cannot change the program: `a_secret_source_program_is_protected_like_a_configured_tool_command`, `a_write_grant_over_a_source_program_is_refused_and_starts_no_program`, `a_write_grant_over_a_secret_source_program_is_refused` (through the binary, for a route and for a telemetry target; the program does not start), `generate_schema_refuses_a_write_grant_over_a_source_program`, `each_link_on_the_way_to_a_secret_source_program_is_protected`, `a_program_path_whose_links_do_not_end_is_an_error`, `the_process_tables_are_the_agent_each_tool_and_each_stdio_mcp_server`. - The startup line: `startup_names_each_declared_source_and_its_program`. - Each entry that names a declared secret is read: `each_entry_whose_secret_a_declared_source_reads_is_a_use`, `a_fetch_reads_each_use_and_states_each_read`. - One run of the program for a telemetry target and a route: `a_telemetry_target_and_a_route_with_one_secret_run_the_program_once` (a unit test, and a box test through the binary), `a_target_secret_in_a_declared_scheme_is_read_through_the_given_backend`. - A failed read stops startup, names its entry, and puts no word of the program in a record or a refusal: `a_failed_fetch_names_its_entry_and_stops_the_later_reads`, `a_reference_that_the_runner_refuses_names_its_entry`, `a_secret_source_that_fails_stops_the_box_before_the_workload` (through the binary, for a route and for a telemetry target). - The workload holds a placeholder under `secret.env`, the program runs once for each run, the read is recorded, and no file holds the secret: `a_declared_secret_is_read_at_startup_and_the_workload_holds_a_placeholder` (through the binary), `a_route_in_a_declared_scheme_opens_through_the_given_backend`. - The gateway adds a secret that a declared program read to a permitted request: `a_secret_that_a_declared_program_read_rides_a_permitted_request` (the gateway in the test process, with a TLS origin). - The sources close after the vaults open: `each_vault_opens_through_the_sources_of_the_run_and_then_they_close`, `a_closed_backend_holds_no_secret_and_reads_no_declared_scheme`, `a_closed_source_drops_each_held_secret`, `the_sources_read_no_secret_after_they_close`. - The record of a read and its wire text: `a_read_is_recorded_as_one_control_plane_record`, `each_control_operation_keeps_its_wire_spelling`. - `policy generate-schema`: `generate_schema_reads_a_remote_mcp_secret_through_its_declared_source`, `generate_schema_stops_when_a_declared_source_returns_no_secret` (no stdio server starts first), `generate_schema_checks_no_program_when_no_server_names_a_declared_scheme`, `generate_schema_refuses_a_placement_before_it_starts_the_program`, `offline_schema_generation_reads_a_server_whose_secret_names_a_declared_scheme`. - No declaration, no change: `a_configuration_with_no_declaration_reads_through_the_local_sources`. Each test uses a stand-in program. The gateway adds a secret only over TLS and trusts no test certificate authority, so no box test shows the secret at a local origin. The in-process gateway test and the run by hand against a public echo host show it. Not run on this commit: the full macOS suite, and a real `op` or `aws`.
|
Assessment: Approve (pending the maintainer approvals that the description already asks for) I reviewed head Assumptions and rules I checked that held
Verification and notes
The ordering and its limits are clearly documented in |
…ls locator ## Problem Box found the scheme of a secret reference by its own split on `://` in three places of this change: `EgressSecret::scheme`, `telemetry_secret_uri`, and `read_remote_mcp_servers`. The backend finds it with `credentials::Locator::scheme`, and routes each read by it. So Box and the backend each decided what the scheme of a reference is. They agree for each reference that the backend accepts. But if one rule changes, such as a trim, Box can say that a declared source reads a reference that the backend sends to another source. The two rules already differ for one text: `op://` with nothing after it has the scheme `op` for the split, and is no reference for the backend. ## Solution - `secret_source::routed_scheme` is the one place that finds the scheme of a reference for a declared source. It asks `credentials::Locator`. - `DeclaredSources::source_of(reference)` answers "which declared source reads this reference" for each caller. The telemetry check and `read_remote_mcp_servers` use it in place of their own split. - `EgressSecret::routed_scheme` replaces `EgressSecret::scheme`. A reference that `Locator` refuses has no scheme, so the route check returns the locator refusal for it. Interfaces that moved, each for a reference in a scheme that a table can declare, with nothing after `://`, such as `op://`: - On a route with no `secret.env`, the refusal was "a reference in the op:// scheme needs secret.env". It is now `credential locator "op://" is invalid`, with the reason of `credentials`. - On a route with `secret.env`, the same locator refusal came when the routes were built. It now comes with the other checks of the entry. - On a route in a scheme that no table declares, such as `vault://`, the refusal was "secret scheme "vault" has no `[secret-source.vault]` table". It is now the locator refusal. - On a telemetry target, the check accepted `op://` beside a declared `op`, and a later step refused it with the scheme in its text. The check now refuses it as a reference in no scheme that the box reads, and echoes no part of it. No other reference gets another answer: a probe ran 29 references through the route check and the telemetry check before and after, and 111 of the 116 results are equal. `docs/user/config.md` and `docs/user/telemetry.md` name the new refusals. Not changed: `EgressSecret::deliverable` and `validate_secret` still split a reference to sort it into its kind and to word a refusal. They are older than this change, and no declaration is looked up with their scheme. ## Tests In an Amazon Linux 2023 container (x86_64, Rust 1.98.1): - `cargo test -p strands-box --all-features --locked --lib --no-fail-fast`: 1,118 passed and 16 failed in one run, and 1,121 and 13 in a second run. Each failure is one of the 16 tests that fail in this container on the commit before this change, because of container limits, and some of the 16 pass in some runs. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` and `cargo fmt --all --check` are clean. The five doc guards passed (36 tests). - `a_declared_source_reads_a_reference_by_the_scheme_that_credentials_routes` gives 15 references to `DeclaredSources::source_of` and compares each answer with the scheme of `Locator::parse_uri`. - `a_reference_with_nothing_after_a_declarable_scheme_is_refused_as_a_locator` pins the locator refusal on a route, with and without `secret.env`, for a declared and an undeclared scheme. - `a_secret_reference_is_normalized_and_a_literal_is_refused` now also gives `op://`, `OP://...`, and `op ://...` to the telemetry check beside a declared `op`: each gets the refusal of an undeclared scheme, with no part echoed. - 5 undo patches, one for each place that now asks the locator: each made its test fail. 4 ran in the container, and the one whose test asserts on macOS alone ran there. On macOS (arm64, Rust 1.96.0): `box_credentials` passed 29 tests and ignored 1, `mcp_schema_generation` passed 21, and the unit tests of the changed modules passed 321. The box test counts are the same as on the commit before this one. `offline_schema_generation_refuses_a_declared_secret_source` passed there, and it reaches `source_of` on macOS only. Not run: the full workspace suite, which CI runs.
…-fetch This brings in the commit that finds the scheme of a secret reference through the credentials locator. Two files had a conflict: - `crates/box/src/record/config/mod.rs`: this branch removes the refusal in `read_remote_mcp_servers` that the merged commit changed, so the refusal stays removed. - `crates/box/src/record/config/secret_source.rs`: `DeclaredSources::source_of` from the merged commit and `DeclaredSources::into_declarations` from this branch are both kept.
…mmits
## Problem
`SecretSources` had nine methods, and a caller had to use them in one order: open, refuse a write grant over a program, disclose, read the telemetry secrets, open the collector, read the other secrets, open the vaults, close. `command::run` and `command::policy` each wrote that order by hand, and `policy` had its own `split_once("://")` beside `SecretSources::reads`. So the rule "no source program starts before the check of the write grants" held only because both callers had the order right. A third caller could start a vault program in a box that lets a workload replace it, and no type would stop it. A moved line in one of the two callers fails only the two tests that start a real box, and those run on macOS only. `credential::project` also closed the sources as a side effect, which a reader of `project` can miss.
`SecretSources` also found the scheme of a reference with its own split on `://` (`scheme_of`), while the backend routes each read by `credentials::Locator::scheme`. So Box and the backend each decided which source reads a reference.
And `execute` made the check after `prepare` had committed the record of a new box directory. A refusal of the check on the first run left a record with no policy history, and the next run of that directory stopped with "the box record is committed, but the history ... is absent". So an operator who installed the missing program, or narrowed the grant, still had to empty the box directory.
## Solution
The order is now three types in `run::secret_sources`. Each step takes the value of the step before it, and only that step returns it:
- `SecretSources::check(record, protected_sources, stderr)` checks each program file, refuses a write grant over one, and writes the startup lines, in that order. It is the only way to get a `SecretSources` for a run. A refusal returns no value, so no code can read a secret after it. The check also keeps the list of entries that it will read, so a read needs no record.
- `SecretSources::fetch_telemetry` consumes the checked value and returns `TelemetrySecrets`. `telemetry::open` takes that type, so the collector cannot open before the first read.
- `TelemetrySecrets::fetch_routes` consumes that value and returns `RouteSecrets`. `HostedBox::open` and `credential::project` take it by value, so no vault opens before the second read.
- The drop of `SecretSources` calls `Backend::close_declared`. `project` has no close call now: the sources close when `project` returns, and also when a run stops before the vaults open.
- `credential::workspace` and `credential::backend_capabilities` are private, so `project` is the only function of `run::credential` that another module can call to open a route vault. `only_project_opens_a_route_vault_for_another_module` pins it.
- `policy generate-schema` calls `SecretSources::check_for_references`, which runs the same check when a remote MCP server names a secret in a declared scheme, and checks no table when none does. Its own `split_once("://")` is gone.
- `SecretSources::locator` parses each reference once through `credentials::Locator`, and each read keeps that `Locator`. So the scheme that finds the program and the reference that `Backend::resolve` gets are one value. `scheme_of` is gone, and `check_for_references` asks `secret_source::routed_scheme`.
- `prepare_contract` calls `SecretSources::check` before `BoxRoot::initialize_first_use` commits the record, and returns the checked value beside the locked run. A refusal of the check now stores nothing in a new box directory, and the next run starts there.
- `open`, `refuse_writable_programs`, `disclose`, `telemetry_uses`, `route_uses`, `fetch`, and `SecretUse` are private to the module. `of`, `close`, and the two test-only constructors are gone: each test door is in the `tests` module.
Interfaces that moved:
- The `[secret-source.<scheme>]` line on stderr now comes before the `box ... created` or `box ... updated` line, and a refusal of the check comes before that line too. On a box that is already running, or whose history and record disagree, the line and a refusal of the check also come before that refusal. The check starts no program.
- A run that the check refuses on the first run of a new box directory leaves that directory empty. Before, it left a record that stopped each later run.
- Each refusal text, each record, and the order of the two reads are the same as before.
Not fixed: a telemetry target whose secret the program does not return on the first run of a new box directory still leaves a record with no history, and the next run stops. The read runs a program, so it holds the run lock, which exists only after the commit. Each other refusal of `telemetry::open` sits in the same place, also in a configuration with no secret source. One of them ran on a build of `main`: an `env://` secret that is not set leaves the same record. `docs/user/config.md` tells the operator to remove the box directory, and `a_telemetry_secret_that_is_not_returned_on_a_first_run_still_strands_the_box_directory` pins the limit, so it fails when the gap closes.
The `credentials` crate does not change. The fetched secrets stay in the one backend (the map in `CommandSource`), because that map is what gives one run of the program for a secret that a telemetry target and a route both name, and for two references that differ only in `#FIELD`. A value that the vaults take in its place needs a second public way into `credentials` to hand a fetched secret to a vault, and it holds the same plaintext for the same time.
## Tests
In an Amazon Linux 2023 container (x86_64, Rust 1.98.1):
- `cargo test -p strands-box --all-features --locked --lib --no-fail-fast`: 1,142 passed and 16 failed, in each of two runs. The 16 are the tests that fail in this container on the commit before this change, because of container limits, in `run::broker`, `run::contain`, and `run::hosted`.
- `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` and `cargo fmt --all --check` are clean. The five doc guards passed (37 tests).
- `cargo test -p strands-box-credentials -p strands-box-telemetry --all-features --locked --no-fail-fast`: `credentials` passed 297 unit tests and 33 integration tests. `telemetry` passed 107 and failed 1, `export::tests::the_vault_attaches_a_credential_on_an_ipv6_address`, which fails in the same way on the commit before this one, because the container has no IPv6 loopback.
- A wrong order is a compile error, which no test can show. So `only_the_check_builds_the_sources_and_only_they_read` reads the module and pins its doors: the two checks, the two reads, `reads`, and the three `backend` accessors. It also refuses each other visible item (a field, a field of a tuple, a `pub(in ...)` item), each other `impl`, so no trait builds or copies a state, a second child module, and a test-only item.
- `a_write_grant_over_a_source_program_is_refused_and_starts_no_program` now goes through the whole check: a refused table gives no sources and no startup line, and a table beside the program gives both.
- `the_check_of_a_record_gives_the_sources_that_read_each_of_its_secrets` runs the three steps on one record: one line, then the telemetry secret, then the route secret.
- `a_read_that_fails_gives_no_value_to_the_next_step` fails the first read and then the second: neither returns its type, and the sources are closed.
- `the_sources_read_no_secret_after_the_vaults_take_them` keeps a clone of the backend, drops `RouteSecrets`, and gets "is closed" from the clone. The same holds for sources that drop before a read.
- `a_check_for_references_checks_no_table_that_no_reference_reads` gives a table whose program does not exist: no reference that `credentials` routes to its scheme means no check and the local sources, and one such reference means the refusal of the table.
- `the_sources_read_a_reference_by_the_scheme_that_credentials_routes` gives 15 references to `SecretSources::reads` and compares each answer with the scheme of `Locator::parse_uri`.
- 46 undo patches on Linux, one for each property of the module: 45 made a test fail, and one (a `Clone` on a state) does not compile. They cover the order inside the check, the list of entries that each step reads, a failed read that gives the next step, the close on drop, the check for references, the read of a reference through the locator, and each door that the two door tests refuse.
On macOS (arm64, Rust 1.96.0), on the same tree:
- `cargo test -p strands-box --all-features --locked --test box_credentials --test mcp_schema_generation`: 34 passed and 1 ignored, and 26 passed. That is the count of the commit before this one and the two new tests. The tests start a real box and run `policy generate-schema` through the built binary, so they cover the order of startup end to end: the refusal before a program starts, the startup line, the two reads, the records, and the close.
- `a_new_box_directory_starts_after_the_cause_of_a_secret_source_refusal_is_gone` is new. On the first run of a new box directory, an absent program file and a write grant over the file that the program path resolves to each stop the run and leave the directory empty. After the operator installs the program, or points the path outside the grant, the next run starts in that directory. Its control is a route secret that the program does not return and then returns. Before this change the first two cases stopped the next run with "the history ... is absent".
- `a_telemetry_secret_that_is_not_returned_on_a_first_run_still_strands_the_box_directory` is new, and pins the limit above: the next run stops with that error, and starts no program.
- The unit tests of the changed modules: 342 passed. `each_vault_opens_through_the_secrets_of_the_run_and_then_they_close` runs on macOS only: `project` consumes `RouteSecrets`, the route and the backend token share one run of the program, and a clone of the backend is closed after.
- 16 undo patches whose tests need a box or a loaded declaration: each made its test fail. They remove the refusal from the check, the lines, the stop after a failed read in each step, the second read, the records, and the read of `policy generate-schema`, and one moves the check after the commit of the record.
- By hand, through the binary: a second run of a box that is running prints the `[secret-source.<scheme>]` line, then the "already running" refusal, and starts no program. On a build of `main`, a telemetry target whose `env://` secret is not set on the first run of a new box directory stops the next run with "the history ... is absent", and the same target with the variable set starts.
Not run: the full workspace suite, which CI runs, and a real `op` or `aws`.
## Problem `SecretSources` gave its backend through `backend()` before a read step, because `policy generate-schema` reads through it. So code in `command::run` could read a declared secret between the check and the first read step. That read comes before the startup checks, and it writes no `secret_fetched` record. No caller did so, but the types did not stop it, and `crates/box/AGENTS.md` said that a wrong order is a compile error. A value of `SecretSources::check_for_references` was also a `SecretSources`: it holds no list of entries, so it could pass both read steps with no read and reach the vaults. ## Solution - `SecretSources::check_for_references` returns a new type, `SchemaSecrets`. It gives `reads` and `backend`, it has no read step, and no function of a run takes it. - `SecretSources` has no `backend` accessor now, and its `reads` is private. So `command::run` gets no backend from the sources of a run, and reads through them by `fetch_telemetry` and `fetch_routes` alone. - `TelemetrySecrets::backend` and `RouteSecrets::backend` are `pub(in crate::run)`, for the collector and the vaults. - `crates/box/AGENTS.md` says what the types hold and what they do not. Not held: a function of `crate::run` that gets `&TelemetrySecrets` can read a route's secret before the second read, another module can call `check_for_references` and read through `SchemaSecrets::backend`, and `credentials::Backend::declared` is public. Today only `run::telemetry::open`, `command::policy`, and `SecretSources::open` use these three. - `only_generate_schema_reads_a_declared_secret_with_no_read_step` reads each source file of the crate and pins the last two: one file builds a declared backend, and `command/policy.rs` alone names `check_for_references` and `SchemaSecrets`. No refusal, output, or record changes, and no file of the `credentials` crate. ## Tests In an Amazon Linux 2023 container (x86_64, Rust 1.98.1): - `cargo test -p strands-box --all-features --locked --lib --no-fail-fast`: 1,144 passed and 15 failed. Each failure is one of the 16 tests that fail in this container on the commit before this change, because of container limits, and some of the 16 pass in some runs. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` and `cargo fmt --all --check` are clean. The five doc guards passed (37 tests). `strands-box-credentials` passed 297 unit tests and 33 integration tests. `strands-box-telemetry` passed 107 tests and failed 1, `export::tests::the_vault_attaches_a_credential_on_an_ipv6_address`, as on the commit before this one, because the container has no IPv6 loopback. - `only_the_check_builds_the_sources_and_only_they_read` pins the new list of doors: `SecretSources` gives `check`, `check_for_references`, and `fetch_telemetry`, the two backends of a run are marked as visible in `crate::run` alone, and `SchemaSecrets` gives `reads` and `backend`. - 7 undo patches, and each one made its test fail. 5 fail the door test: a backend accessor on `SecretSources` under another name, each backend of a run made `pub(crate)`, a way from `SchemaSecrets` into a `SecretSources`, and a visible field of `SchemaSecrets`. 2 fail the new pin: a call of `check_for_references` in `command/run.rs`, and a second `Backend::declared` there. - `a_check_for_references_checks_no_table_that_no_reference_reads` covers the door of `policy generate-schema` on Linux. Not run: macOS. The tests that run `policy generate-schema` with a declared source through the binary are in `crates/box/tests/mcp_schema_generation.rs` and run on macOS only, such as `generate_schema_reads_a_remote_mcp_secret_through_its_declared_source` and `generate_schema_stops_when_a_declared_source_returns_no_secret`. CI runs them.
|
Assessment: Approve (follow-up for head Since my last review ( What I checked on the new code, and it held
Verification: on Linux, |
ferdingler
left a comment
There was a problem hiding this comment.
Thanks Anand, the three types read much better, and the order can't go wrong now. Keeping the cache in CommandSource for now is fine with me, since dropping it needs new public API in the credentials crate. Let's do that as a follow-up. CodeQL is still red; please dismiss 66 as you said.
## Problem The credentials crate reads a secret from a vault only through its built-in `op://` source. A second vault, such as AWS Secrets Manager, needs a new source in the crate, with its own dependencies and its own review. The secret provider design (#467) replaces that with one contract. The caller declares a host program, and the box runs it at startup and reads one secret from its stdout. The crate has no way to run a declared program. ## Solution Add a declared secret source to the credentials crate. Nothing reads it from `box.toml` yet, so a box behaves as before. - `SecretSourceCommand` declares one program for one scheme: the protocol (`box.secret-source.v1`), the command, the output form (`text` or `json`), and two pass lists. Its constructor refuses a reserved or malformed scheme, another protocol, and an empty command. It also refuses a program that is not an absolute path, and a command with no `{ref}` in its arguments. A pass list refuses the entries `*`, `PATH`, and `HOME`, and an entry with a `*` before its end. Each refusal names the key and the entry. - The runner starts the program with no shell and no stdin, in `/`. The environment is `HOME`, `PATH=/usr/bin:/bin`, and each pass-list variable that is set. An entry that ends with `*` passes each variable with that prefix. A run of more than 30 seconds, more than 1 MiB of stdout, or a non-zero exit fails the fetch. A failure carries the end of stderr, at most 512 bytes, with the reference name and each passed `pass_secret_env` value replaced. - `{ref}` (`SECRET_REFERENCE_TOKEN`) is the text after `scheme://` without `#FIELD`. The source replaces it inside each argument, and refuses a reference whose text after `scheme://` starts with `-`. - With `output = "json"`, stdout is one JSON string. With `#FIELD`, the secret is a JSON object, and the source returns that one string field. Without `#FIELD`, a secret that is a JSON object is refused. The JSON field step and its wipe helpers follow #448. - `RESERVED_SECRET_SCHEMES` lists the schemes that no declaration can claim, and `SecretSourceCommand::check_scheme` is the check. - `Backend::declared(declarations)` registers `env`, `file`, and one source for each declaration. A declared `op` takes the place of the built-in `op://` source. The backend keeps each fetched secret, so two references that differ only in `#FIELD` run the program once. Interfaces that moved: - The `pub use` set of the crate grows from 20 names to 23: `SecretSourceCommand`, `SECRET_REFERENCE_TOKEN`, `RESERVED_SECRET_SCHEMES`. - `SecretSourceCommand` has the constant `PROTOCOL` and the functions `new`, `check_scheme`, `output`, `pass_env`, and `pass_secret_env`. - The URI vocabulary of the crate gains `SCHEME://NAME[#FIELD]` for a declared scheme. `#` starts a field only for a declared scheme. - `Backend` gains the constructor `declared`, and is now `Clone`. Each clone shares the same sources and the same fetched secrets. The held secrets have no accessor. - `Backend::local()` is the same: `env`, `file`, and the built-in `op`. ## Tests Each test uses a stand-in program, a shell script in a temp dir. No test runs a real `op` or `aws`. - `cargo test -p strands-box-credentials --all-features --locked`: 292 unit tests and 33 integration tests passed on macOS. 289 unit tests and 33 integration tests passed in an Amazon Linux 2023 container. 55 unit tests are new. - The declaration: `each_reserved_scheme_is_refused_by_name`, `a_command_with_no_reference_token_in_its_arguments_is_refused`, `a_pass_list_entry_that_has_no_effect_or_passes_every_variable_is_refused`. - The environment: `the_program_gets_only_home_the_fixed_path_and_the_passed_variables`, `a_variable_with_a_name_that_is_not_utf8_does_not_pass`. - No stdin, the directory `/`, no shell, `{ref}`: `the_program_gets_no_stdin`, `the_program_starts_in_the_root_directory`, `each_argument_reaches_the_program_as_one_argument_with_no_shell`, `a_malformed_reference_is_refused_before_the_program_starts`. - The bounds: `a_program_that_runs_past_the_timeout_is_stopped`, `stdout_up_to_the_limit_is_read_and_one_more_byte_is_refused`, `a_program_that_never_stops_writing_is_stopped_at_the_limit`, `a_program_that_leaves_its_stdout_open_fails_at_the_deadline`. - The failure text: `a_non_zero_exit_is_a_failure_that_carries_stderr`, `a_failure_hides_the_reference_and_each_passed_credential_and_each_control_character`, `a_failure_hides_a_passed_credential_that_is_not_utf8`, `a_failure_carries_at_most_512_bytes_of_stderr`, `the_excerpt_hides_a_whole_hidden_value_near_the_start_of_a_cut_capture`. - The output and the field: `json_output_is_one_json_string_and_any_other_value_is_refused`, `a_field_selects_one_string_of_a_json_object_and_any_other_case_is_refused`, `a_json_object_without_a_field_is_refused`. - One fetch: `two_references_that_differ_only_in_the_field_run_the_program_once`, `each_clone_of_a_declared_backend_shares_one_fetch`, `two_callers_at_one_time_run_the_program_once`. - The backend: `a_declared_op_takes_the_place_of_the_built_in_source`, `local_holds_the_env_file_and_op_schemes`. - Clippy for the workspace (`--all-targets --all-features -D warnings`) and the rustdoc gate of the crate are clean in the container. Not run: the full workspace suite, because no other crate calls the new surface. No test can observe the wipe of a value that drops, a parsed JSON value or a copied environment value; `a_wipe_empties_each_string_of_a_parsed_value` tests the helper.
The README example names `OP_SESSION_*`, the variable of `op signin`, and did not pass `TMPDIR`. `op` 2.42.0 on macOS keeps the session of `op signin` in a folder under `TMPDIR`. With `HOME`, `PATH`, and `OP_SESSION_*` alone it says that no session is active, and with `TMPDIR` too it finds the session. The code does not change. `pass_env` accepts `TMPDIR`.
… the crate The reserved scheme list did not hold `strip-phantom`, the scheme of the crate's second route marker (`strip-phantom://route`). So a declaration could claim it. The list now holds it, and `SecretSourceCommand::check_scheme` refuses a declaration of that scheme. `RESERVED_SECRET_SCHEMES` and `SECRET_REFERENCE_TOKEN` were public, and no other crate reads them. The crate adds a public item only for a named external caller, so both are now private to the crate. `SecretSourceCommand::check_scheme` stays the one check of a scheme for a caller. The `pub use` set of the crate is now 21 names, one more than before this PR: `SecretSourceCommand`. Tests: `the_reserved_schemes_are_the_nine_the_box_owns` and `each_reserved_scheme_is_refused_by_name` fail when `strip-phantom` leaves the list.
… each owner The reserved scheme list held each scheme as a second literal, beside the constant of the code that owns it. An earlier revision of this change missed `strip-phantom` for that reason. The list now takes each name from its owner. Six names come from the scheme constants of the crate: `env`, `file`, `aws`, `credsd`, `cmd`, and `oauth2`. Two come from the route markers `aws-signed://route` and `strip-phantom://route`. Only `secret` stays a literal, because the box crate owns it. The nine names and their order do not change. Tests: `each_scheme_constant_and_each_route_marker_of_the_crate_is_reserved` fails when the list holds a literal and the constant of its owner changes. `the_reserved_schemes_are_the_nine_the_box_owns` still compares the nine literal names, because a refusal prints the list.
…ut a field A declared source refuses a secret that is a JSON object when the reference has no `#FIELD`, with each `output`. The built-in `op://` source returns such a secret whole. So a declared `op`, which takes the place of the built-in source, differs from it here. The docs did not say so, and the README row for `text` read as if stdout always passes. The rule stays for each `output`, as the design (#467) states it: one destination never gets each key of an object. A check for `json` alone lets a program that prints an object as text pass it whole. - `a_declared_op_refuses_a_json_object_without_a_field_in_text_output` pins the refusal for scheme `op`. - `returns_a_json_object_whole` pins what the built-in source does with the same stdout. - The README rows for `output` and `#FIELD` state that the rule holds for each `output`, and name the difference.
…itself `each_scheme_constant_and_each_route_marker_of_the_crate_is_reserved` asked `check_scheme` for a refusal. A malformed scheme is refused too. So the test passed when a scheme constant held a malformed text, and when a route marker had a form that `scheme_of` and `Locator::scheme` read differently. The test now looks for each scheme in the list. - `crates/credentials/AGENTS.md` says that no code collects the constants, so each new scheme constant and each new route marker goes into the list and into this test. - The README row for `#FIELD` says "all the keys". - `a_declared_op_refuses_a_json_object_without_a_field_in_text_output` builds its backend with the helper of its file, which gives the program an empty operator environment, as the other tests of a refusal do.
Three files had a conflict. - crates/box/src/record/config/mod.rs, four hunks. main (#429) took record version 38 for a `deny_write` list, which this branch took for a secret source. `SECRET_SOURCE_RECORD_VERSION` is now 39, after `DENY_WRITE_RECORD_VERSION`. In `record_version` a secret source table or a `secret.env` key is judged first, then a `deny_write` list, so a record with both is version 39 and a record with the list alone stays 38. The list of the versions that this build reads holds both, and the test of a foreign version uses the last one. - crates/box/AGENTS.md: main changed "the CLI verbs and flags" to "the `strands-box` verbs and flags". This branch changed the last record version of that sentence to `SECRET_SOURCE_RECORD_VERSION`. The merge keeps both. - docs/user/native-filesystem-policy.md: main added the lines for record versions 37 and 38 where this branch added its line. The merge keeps the three, in the order of the versions, and the line of this branch says 39. Four more places needed a change that the text merge does not make. - The number 39 in place of 38, in three more files: the assert in crates/box/tests/box_credentials.rs, docs/user/config.md, and crates/box/README.md. The assert in `a_declaration_is_stored_at_a_version_no_earlier_build_reads`, in the file with the conflict, has it too. - crates/box/src/run/commands.rs: a test of main (#490) builds a `Record` by its fields. This branch adds the field `secret_source`, so the test gets `secret_source: Default::default()`. `a_placeholder_variable_key_stores_the_secret_source_version` now also pins the pair: a `deny_write` list alone is version 38, the list beside a `secret.env` key is version 39, and that record is refused at version 38.
…-fetch This brings main into this branch, through the merge of the branch below. Four files had a conflict. - crates/box/src/command/run.rs, four hunks. Three are the `cfg` of `prepare` and of its two calls: main (#188) removed `box_native_adapter_tests`, and this branch made `prepare` return `(LockedRun, SecretSources)`. The merge keeps both, so the Linux form gives the checked sources too. The fourth is in `prepare_contract`: main (#490) leaves out each tool whose program is not installed, after the record is stored, and this branch checks the secret sources before the record is stored. - docs/design/architecture.md, step 2 of the startup order: the merge keeps both texts, in the order of the code, and adds one sentence: the check reads no table of a left-out tool. - docs/user/config.md, "Configured command integrity": the merge keeps main's sentence and this branch's sentences about the program of a secret source. The sentence that each tool program must exist stays removed, as on main. - crates/box/README.md, the sentence with the record version: this branch's text, with version 39. The order in `prepare_contract` is a choice. `settle_tools` leaves out each tool whose program is not installed once, on the run's copy of the record, before `SecretSources::check`, and the check judges that copy. So the check judges each process table that the run starts and no other, as `ApprovedReach::judge_with` does, and a list of a left-out tool refuses no run. A check of the stored record judges a list that Box says it does not check: in the new unit test on Linux, it refused a left-out tool for a write grant with no read grant. The check stays before `BoxRoot::initialize_first_use`. The `left out` lines and a refusal of the choice stay after the record is stored, as on main. `the_secret_source_check_judges_no_table_of_a_left_out_tool` pins the order in `settle_tools`. On macOS, `a_left_out_tool_with_a_write_grant_over_a_secret_source_program_stops_no_box` pins it through the binary. `crates/box/AGENTS.md` says where the choice is made. One difference from main follows, for a box with or without a secret source. The tools are now chosen before the run writes `bin/` into a new box directory. So a tool whose program is a file that Box writes there is left out on the first run of that directory, and each later run refuses it, as each run did before. `run_config.rs::a_tool_program_that_box_writes_is_left_out_on_the_first_run_alone` pins it, and `crates/box/AGENTS.md` states it. `docs/user/config.md`, "What Box protects", now says that `run` checks the tables of the tools that it keeps, and that `policy generate-schema` leaves no tool out.
…ce-table The branch below was rebased onto main. It now holds new commits with the same content as the commits of it that this branch holds: the merge of the old head into main and the new head have one tree. Three files of crates/credentials had a conflict, because both sides add the same lines and this branch then changes them: AGENTS.md, README.md, and src/model/secret_source.rs. Each one resolves to the file of this branch, which is the file of the branch below with the changes of this branch. This merge changes no file: its tree is the tree of its first parent.
…-fetch This brings the rebased commits of feature/secret-source-command into this branch, through the merge of the branch below. They have the same content as the commits of it that this branch holds. This merge changes no file: its tree is the tree of its first parent.
main now holds the change of feature/secret-source-command as one squashed commit (#489), with the same content as the commits of it that this branch holds. Three files of crates/credentials had a conflict, because both sides add the same lines and this branch then changes them: AGENTS.md, README.md, and src/model/secret_source.rs. Each one resolves to the file of this branch, which is the file of main with the changes of this branch. The merge also brings six files under .agents/ from main (#521). No other file changes.
…-fetch This brings main into this branch, through the merge of the branch below. main now holds the change of feature/secret-source-command as one squashed commit (#489), with the same content as the commits of it that this branch holds, so each file of crates/credentials stays as this branch has it. The merge also brings six files under .agents/ from main (#521). No other file changes.
|
Assessment: Approve (follow-up for head Since What I checked in the merge, and it held
Verification: on Linux, |
ferdingler
left a comment
There was a problem hiding this comment.
Re-approving after the merges from the base branch.
|
Assessment: Approve (follow-up for head Since
#512 changes only the Linux namespace view. This PR reads secrets on macOS alone (Box refuses a Verification: on Linux, after the merge, |
Description
This is the third of four stacked PRs that build the secret provider design (#467). It is stacked on the PR that adds the
[secret-source.<scheme>]table, so its diff shows only this step.What this PR does
After the PR below, Box loads a
[secret-source.<scheme>]table and then does not start, because no step reads a secret. This PR adds that step.strands-box runruns each declared program when the box starts, reads each secret from its stdout, and delivers it. The workload holds a placeholder, and the gateway adds the real value to a request that policy permits.An operator writes this:
and a bash agent in that box prints
GH_TOKEN, prints it again in the hosted Shell, sends it tohttps://postman-echo.com/get, and then sends a request with another token. This is a real run on macOS with a stand-in program, before the rebase ontoab29afd3. The first two lines are in the order of this head. The filesystem disclosure lines are left out:The operator set no
GH_TOKEN. The echo host returned the header that it received, and the gateway replaced the real secret in that response with[REDACTED], so the real secret went out. The stand-in program ran once. No file under the box directory holds the secret.When the program returns no secret, the box does not start. The first line holds the program's own words, and the second line names the entry:
What to expect:
[agent], a tool that the run does not leave out, or a local MCP server is refused when it covers the program path, the file that it resolves to, a symbolic link on the way, or a folder that holds one of them. Box makes this check before the program starts for the first time.box ... createdorbox ... updatedline.policy generate-schema. It gets its secrets through a type of its own,SchemaSecrets. The checked value of a run gives no backend, sorunreads through it by its two read steps alone.[tool.<name>]table, also one that the run leaves out.#FIELDshare one run of the program.langsmithorotlptarget can take its key from a declared program. Anaws://target signs as before.secret_fetchedrecord for each read of a configuration entry: the entry, the source, the program, and the reference with its name removed. No record holds a word that the program printed.policy generate-schema. It reads the secret of a remote MCP server through the declared program of the samebox.toml, and prints the same line first.An operator who declares no source sees one change, the interface change "When a run chooses the tools that it leaves out" below (a tool whose program is a file that Box writes into the box directory). Apart from it, that box reads through the local sources, prints no new line, and writes no new record.
Interface changes
Each change below needs a maintainer's approval:
The composed environment. The workload gets the placeholder of a declared-scheme route under its
secret.envvariable. Box does not read the operator's value of that variable.The credentials crate.
Backend::declarednow takes eachSecretSourceCommandwith the opened program file that the caller checked.Backend::close_declaredis new. Thepub useset does not change.The telemetry crate.
ControlOperationgainsSecretFetched, with the wire textsecret_fetched.Stderr at startup. One new line for each
[secret-source.<scheme>]table. It comes before thebox ... createdorbox ... updatedline. On a box that is already running, or whose history and record disagree, the line and a refusal of the check come before that refusal, so a run that the check refuses does not print it. The check starts no program.A new refusal. A write grant over the program of a secret source is refused, on
runand onpolicy generate-schema.policy generate-schemaruns a host program. For a remote MCP server whose secret names a declared scheme, it starts the declared program, outside every sandbox.When a run chooses the tools that it leaves out.
mainleaves out a[tool.<name>]whose program is not installed (feat(box): leave out a tool whose program is not installed #490), after it stores the record. This PR checks the secret sources before it stores the record, and that check must judge the tables of the tools that the run keeps. So a run now chooses those tools once, before the check and before it writes into the box directory. Theleft outlines keep their place. One case changes, for a box with or without a secret source: a tool whose program is a file that Box itself writes into the box directory, such ascommand = ["<box_dir>/bin/sh"]. Onmaineach run refuses it. Now the first run of a new box directory leaves it out, because the file is not there yet, and each later run refuses it as before. A left-out tool gets no grant. First run onmain, then on this head, then the second run on this head, from the built binaries on Linux.<box_dir>stands for the box directory, the agent of the probe printsWORKLOAD RAN, and the other startup lines are left out:Two refusals are removed.
runandpolicy generate-schemano longer stop with "this build cannot yet read a secret from a declared secret source".Known limits
readsanddenylists yet. So a workload can still get a grant over the vault's own files. The next PR of the stack adds that refusal.#!script. An operator who needs a script makes it the program.mainopens the collector in the same place, so each refusal of a telemetry target on a first run does the same there. One case ran on a build ofmainwith no secret source: anenv://secret that is not set.policy generate-schemaleaves no tool out, so it judges each[tool.<name>]table as written. With a declared source that a remote MCP server reads, a write grant of a tool whose program is not installed stopspolicy generate-schemaand does not stoprun.The full rules are in
docs/user/config.md, in the section "How a run reads the secrets".Related Issues
awsprogram. On Linux, Box refuses the table in this version, so this PR does not cover that case there.Type of Change
New feature
Testing
On this head, which holds
mainat37af6316through a merge. The Linux and macOS runs are on the merge ofmainat6f4a2e36. The merges after it change no file but six files under.agents/:cargo clippy --workspace --all-targets --all-features --locked -- -D warningsandcargo fmt --all --checkare clean.cargo test -p strands-box --all-features --locked --lib --no-fail-fast, after a workspace build: 1,188 passed and 5 failed. Each failure is one of the 5 tests that fail in this container onmainat6f4a2e36, by name: two need thehostnameprogram, which the container does not have, one runs a script through a program that is acoreutilslink in the container, and two make a kernel probe that the container refuses.strands-box-credentials: 297 unit tests and 33 integration tests passed. The five doc guards passed.box_credentials35 passed and 1 ignored,mcp_schema_generation26 passed,run_config26 passed, and the 351 unit tests ofrun::secret_sources,run::credential,record::config, andcommandpassed. Thebox_credentialstests start real sandboxes. One of them has a telemetry target and a route that name one secret: the program runs once, and the endpoint of the target gets its field of that secret. One is new with the merge ofmain: a tool that the run leaves out, with a write grant over a source program, stops no box, and the same table stops the box when its program is installed. This run is on the head of this PR, with Rust 1.96.0. It holds the five tests ofpolicy generate-schemawith a declared source, which run on macOS only.box_credentials28 passed and 1 ignored,mcp_schema_generation21 passed,run_config26 passed, andtool_grammars18 passed, with no skipped test.run_configholds the test of feat(box): leave out a tool whose program is not installed #490 that starts a box with a tool that is not installed, and a new test for the tool whose program Box itself writes. On Linux, Box refuses a secret source table, so the tests that read a secret run on macOS only.main, each made a test fail: 3 change the order of the tool choice and the check, and 2 givecommand::runa second way to a declared secret.export::tests::the_vault_attaches_a_credential_on_an_ipv6_address. It fails in the same way onmain, because the container has no IPv6 loopback.Before the rebase onto
ab29afd3, and not repeated:op2.42.0 read a GitHub token at startup, andgh api userin the box returned the login. The realaws2.27.52 read one field of a JSON secret for a telemetry target, and a secret for a route.Not run on this head: the full workspace suite (CI runs it), and a real
oporaws.just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.