Repository navigation
feat(box): load, check, and store a secret source declaration - #499
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.
|
Assessment: Comment I found no correctness defect at What I checked, and the resultFor each new check, I listed the cases that reach it and confirmed what the code does with each one. Each result was correct:
I ran For the API reviewer: The tests prove each refusal with a pinned message and a matching positive case, which made this stack easy to check. |
ferdingler
left a comment
There was a problem hiding this comment.
I don't get why this wouldn't work on Linux? This feature needs to work on both: macOS and Linux.
|
Hey Anand, nice work on this stack. The tests and the refusal messages make it easy to follow. My first comment is about the macOS-only refusal in I understand why you held it back. On Linux the sandbox can't mount over a path that doesn't exist yet, and Shell and Monty can't resolve one either. But the design already accepts that: "On Linux, only paths present at configuration time are protected." So I think we should do what the design says instead of refusing the whole table. Protect the Do you mind proposing how you'd handle the absent path for Shell and Monty, and for the Shell move you noted in AGENTS.md? Happy to go through it together if that helps. Also, I think this means #501 has to cover Linux before the stack can merge. |
Thanks Fernando. Agreed, it has to work on Linux and that is my intention too. The refusal on Linux is a deliberate split. The plan was macOS first, then Linux as a follow-up PR. Until that PR, Box refuses the table on Linux, so it never loads a source whose vault it cannot protect. I should have said in the PR text that a follow-up was planned. |
…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.
|
Assessment: Comment (follow-up for The only new commit since my last review ( What I checked, and the result
I will not repeat the Linux point I raised earlier, because the author and @ferdingler are already discussing it above. |
## 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.
…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.
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.
|
Assessment: Comment (follow-up for The only change since What I checked, and the result
The open Linux-support discussion with @ferdingler above still applies at this head. I am not repeating it here. |
ferdingler
left a comment
There was a problem hiding this comment.
Thanks Anand. Approving, with Linux support coming in the follow-up PR you mentioned. Please link it here when it's open.
Linux support is up: #531. It protects the reads and deny paths that exist at startup, and refuses a path that doesn't exist with a message that names the entry. |
Description
This is the second of four stacked PRs that build the secret provider design (#467). #489 is merged, so the base of this PR is
main.What this PR does
box.tomlgets a[secret-source.<scheme>]table and asecret.envkey. Box loads the table, checks it, and stores it in the record. Each place that names a secret accepts a declared scheme, and Box refuses each unsafe configuration when it loads.This PR reads no secret yet. A box that declares a source passes the load checks, stores its record, and does not start. The next PR adds the read.
An operator writes this:
and
strands-box run --config box.tomlprints this. It is a real run on macOS with this code, a stand-in program, and alangsmithtelemetry target in the same scheme beside the route:The stored record was version 38 in that run. On this head it is version 39, because
maintook 38 fordeny_write(#429). The stand-in program did not run.What to expect:
[experimental-features] secret-sources = true. On Linux a table is refused, and the message says that protection for Linux is not built yet. Thesecret.envkey needs the same switch, on each operating system.protocol,command,output,pass-env,pass-secret-env,reads, anddeny. The credentials crate checks the first five, so its refusals reach the operator: a reserved scheme, a program that is not an absolute path, a command with no{ref}. This PR storesreadsanddenyand checks no grant against them.secret.env. It names the variable that holds the placeholder in the workload. A route or a remote MCP server in a declared scheme requires it. One variable holds one secret: two entries with one variable and different references are refused.secret.env), and a backendauth.refand a telemetrysecret.ref(with no placeholder variable, because Box attaches those secrets itself). Alangfuseorlangsmithtarget takes one too. A CloudWatch target is signed, so it refuses one.env://NAMEandsecret://NAMEare refused when apass-secret-enventry namesNAME. So no route or telemetry target can send that credential out.credentials::Locatorfor the scheme when it looks up the declared source of a reference, and the backend routes each read by the same scheme. A reference in a scheme that a table can declare, with nothing after://, such asop://, is refused when the configuration loads: a route getscredential locator "op://" is invalid, and a telemetry target gets the refusal of a reference in no scheme that the box reads, with no part echoed.op://...with no[secret-source.op]table is refused. The message names the table to declare, and it says that Box loads a source on macOS only.Three refusals, each from a run of the built binary before the rebase onto
ab29afd3. A test pins each text on this head:An operator who declares no source: each configuration that starts today still starts, with the same record version. The three changes for that operator are the last three interface changes below.
Interface changes
This PR follows the design as #467 revises it. Each change below needs a maintainer's approval:
box.tomlkeys. A fourteenth top-level key,[secret-source.<scheme>].[experimental-features] secret-sources.secret.envon[egress.<name>]and on[mcp.<name>] type = "http". A declared scheme insecret.refand in a backendauth.ref.secret-sourcemap and theenvkey of a secret. A record that holds either one is version 39, also beside adeny_writelist, which alone is version 38. The switch alone keeps the ordinary version.an-undeliverable-credential-is-refused-at-loadis rewritten: a provider scheme is valid only when its provider is declared.SecretSourceCommand::passes_as_secretis nowpub. The box asks it whether apass-secret-enventry names a variable.policy generate-schema. It now judges each remote MCP server asrundoes. Onmainit reads anop://orfile://reference of a remote MCP server through the built-in sources, althoughrunrefuses the same file. Now it refusesfile://, and it refusesop://unless the file declaresop. With the declaration it stops in this PR, asrundoes.env://AWS_ACCESS_KEY_IDorenv://AWS_SECRET_ACCESS_KEYroute beside a signed route is now refused when the configuration loads. Before, the vault refused the variable when the box started.injectandphantom_prefixrefusals on a signed route, the telemetrysecret.refrefusal, and the refusal of a scheme that Box does not reserve.Known limits
readsanddenyprotect nothing yet. The grant refusals come in the fourth PR of the stack.policy generate-schemacannot read anop://reference of a remote MCP server on any operating system: withopdeclared it stops, asrundoes. The next PR adds that read on macOS. On Linux abox.tomlcannot declareop, so the gap stays there.runrefuses that file onmainalready.aws://route signs with the AWS identity of the operator's environment, also when apass-secret-envlist names the AWS keys. The design pairs them: the AWS Secrets Manager source reads with that identity.The full rules are in
docs/user/config.md, in the section[secret-source.<scheme>].Related Issues
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,162 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: 293 unit tests and 33 integration tests passed. The five doc guards passed. Two undo patches each made a test fail on this head: one judges adeny_writelist before a secret source inrecord_version, and one gives the two record versions one number. Before the merge ofmain, two more each made a test fail: one removes the declared-scheme arm of the telemetrysecret.refcheck, and one swaps the order of two record versions.box_credentials29 passed and 1 ignored,mcp_schema_generation21 passed,run_config25 passed, and the 328 unit tests ofrecord::config,command, andrun::credentialpassed. This run is on the head of this PR, with Rust 1.96.0.main: the run that the description shows. The same file with no[secret-source.op]table is refused, and the refusal names the table and says that Box loads a source on macOS only.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: the full workspace suite on macOS (3,515 passed, none failed), 22 hand-writtenbox.tomlfiles through the built binary, and 56 undo patches, one for each new check. Each undo patch made its test fail. The last commit before the merge ofmainhas 5 more, and each made its test fail on that commit.Not run: a real
oporaws, because this PR reads no secret. The full workspace suite on this head: CI runs it.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.