Repository navigation
feat(credentials): read a secret from AWS Secrets Manager - #448
Closed
SaiAbhishek98 wants to merge 1 commit into
Closed
SaiAbhishek98 wants to merge 1 commit into
SaiAbhishek98 wants to merge 1 commit into
Conversation
## Problem A telemetry key must come from the environment of `strands-box run`. Thus the operator must write each vendor key into that environment before each start of Box. AWS Secrets Manager can hold all the keys in one location, but the vault cannot read from it. ## Solution - The credential source `aws-secretsmanager://SECRET[#FIELD]` reads the secret string of `SECRET`, a name or an ARN, or one string field of a JSON secret. For a name, the region comes from `AWS_REGION` or `AWS_DEFAULT_REGION`. Box reads the secret one time, at startup. A secret that is a JSON object needs `#FIELD`, so one target does not get all the keys in it. - The `GetSecretValue` request goes through the AWS default-chain worker that a bare `aws://` uses (`SdkChainProvider::call`, new). The request uses the runtime, the `ring` HTTPS client and the cached credentials of that worker. The source has no worker, runtime or credential chain of its own. The worker stops a call at its deadline, so a call cannot stop a bare `aws://` signer for longer. A call that panics gives an error to its caller, and the worker continues. - The crate adds `aws-sdk-secretsmanager` with its default features off. Thus `aws-lc` is not in the build together with `ring`. `Cargo.lock` gets one new package. - A vault built with `require_scoped_aws_profile` refuses the scheme before a fetch, because the request signs with the ambient identity. - `Backend::resolve` and the vault print one line on stderr that says the secret was read with the ambient AWS identity of the host. No message shows the secret value. Box redacts the name of the secret in its messages, and also where an AWS refusal quotes the name. Box wipes each copy of a JSON value that it parses. - A telemetry `secret.ref` accepts the scheme. An egress `secret.ref` does not change. Schema discovery (`policy generate-schema`) refuses the scheme in an `[mcp.<name>]` `secret.ref`, as `run` does. - Docs: `docs/user/config.md`, `docs/design/credentials.md`, `docs/design/architecture.md`, the crate README and AGENTS.md, and the new entry `decisions.md#a-secrets-manager-secret-is-read-on-the-default-chains-worker`. - Interface changes: the credential scheme `aws-secretsmanager://`, accepted by a telemetry `secret.ref`; the new text of the telemetry `secret.ref` refusal; the stderr line; and `Backend::resolve`, which can also send a request to AWS Secrets Manager. ## Tests - `cargo test --workspace --all-features --no-fail-fast`: 5226 passed, 1 failed, 19 ignored. The failure is `a_port_with_no_listener_is_not_ready` in `crates/ingress`, which this change does not touch. It passed 3 of 3 runs alone. - New tests: `a_json_field_is_read_with_a_sigv4_signature`, `a_whole_secret_string_is_read`, `a_missing_field_is_refused_without_the_secret`, `a_refusal_names_the_service_error`, `a_missing_identity_is_refused_before_any_call`, `the_region_comes_from_the_arn_or_the_environment`, `a_reference_is_plain_and_bounded`, `a_fetch_discloses_the_ambient_identity`, `a_whole_json_object_is_refused`, `a_service_message_that_quotes_the_secret_is_redacted`, `a_stuck_call_releases_the_worker_at_its_deadline`, `a_panicking_call_leaves_the_worker_running`, `discovery_refuses_a_secrets_manager_reference`, `the_source_fetches_on_the_shared_default_chain`, `no_second_crypto_provider_is_linked`, `a_call_runs_with_the_chains_credentials`, `a_call_without_credentials_or_a_runtime_does_not_run` and `a_secrets_manager_route_is_refused_when_a_scoped_profile_is_required`. - End-to-end test on macOS: a box read a telemetry key from one field of a JSON secret in AWS. The default chain signed the request with a local AWS profile. A local OTLP endpoint received the key on `/v1/logs` and `/v1/traces`, and its SHA-256 and length agreed with the field of the secret. A box that referred to a field that is not in the secret stopped before its workload, and the refusal did not show the secret. - `cargo fmt --all --check` has no errors. `cargo clippy` adds no warnings in crates other than `crates/shell`. - `feature-critic` ran on this change. Its first verdict was rework, for nine findings. This commit includes the fix for each one, and the confirmation pass gave ship.
Contributor
|
@SaiAbhishek98 can we hold this and do it through the provider contract in #395 (@ferdingler's design) instead of another in-tree source? Same issue as #277 (1Password integration): each new vault should not need Rust in |
This was referenced Nov 13, 2026
yesyayen
added a commit
that referenced
this pull request
Nov 17, 2026
## 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.
7 of 8 tasks
yesyayen
added a commit
that referenced
this pull request
Nov 18, 2026
## 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A telemetry key must come from the environment of
strands-box run. Thus the operator must write each vendor key into that environment before each start of Box. This PR lets the vault read a key from AWS Secrets Manager.aws-secretsmanager://SECRET[#FIELD]reads the secret string ofSECRET, a name or an ARN, or one string field of a JSON secret. Thus one secret can hold the key for each target:Decisions that the diff does not show
GetSecretValuerequest goes through the worker that a bareaws://uses, with a newSdkChainProvider::call. The request uses the runtime, theringHTTPS client and the cached credentials of that worker. Thus one process has one ambient AWS identity, one runtime and one TLS stack. A second worker and a second credential chain in the source were rejected, because two chains can sign as two identities in one box.aws://signer for longer. A call that panics gives an error to its caller, and the worker continues.#FIELD. Thus one target never gets all the keys in the object. Box wipes each copy of a JSON value that it parses.aws-sdk-secretsmanagerhas its default features off. The default features add the default HTTPS client, which putsaws-lcin the build together withring. Therustlsbuilders of the egress gateway then panic.no_second_crypto_provider_is_linkedfails ifaws-lc-rs,aws-lc-sysor a secondrustlsgets intoCargo.lock.Cargo.lockgets one new package.credential_processrisk as a bareaws://. A vault built withrequire_scoped_aws_profilerefuses the scheme before a fetch. Box prints one line on stderr that says it used the ambient identity of the host.AccessDeniedExceptionquotes the name of the secret. The AWS message can still name the signing role.Interface changes
These change frozen surfaces:
aws-secretsmanager://SECRET[#FIELD].secret.refaccepts the scheme, and the text of its refusal changes. An egresssecret.refdoes not change. Schema discovery (policy generate-schema) refuses the scheme in an[mcp.<name>]secret.ref, asrundoes.strands-box credentials: aws-secretsmanager://[REDACTED] read from Secrets Manager, signed with the host's ambient AWS identity from the default credential provider chain. Grant the workload no write access to ~/.aws.Backend::resolvecan now send a request to AWS Secrets Manager.SdkChainProvider::callincrates/credentials, visible only incrate::sources.Verified outside CI
On macOS, a box read a telemetry key from one field of a JSON secret in AWS Secrets Manager. The default chain signed the request with a local AWS profile. A local OTLP endpoint received the key on
/v1/logsand/v1/traces. The SHA-256 and the length of the received key agreed with the field of the secret. A box that referred to a field that is not in the secret stopped before its workload, and the refusal did not show the secret.Deferred
Related Issues
Builds on #342.
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsResults on this branch, which is based on
mainat70eb3af:cargo test --workspace --all-features --no-fail-fast: 5226 passed, 1 failed, 19 ignored. The failure isa_port_with_no_listener_is_not_readyincrates/ingress, which this PR does not change. It passed 3 of 3 runs alone.cargo fmt --all --checkhas no errors.cargo clippy --workspace --all-targets --all-featuresreports warnings only incrates/shell. This PR does not changecrates/shell.cargo build --workspace --all-features --lockedhas no errors, soCargo.lockis consistent.feature-criticran on this change. Its first verdict was rework, for nine findings. The commit includes the fix for each one, and the confirmation pass gave ship.a_json_field_is_read_with_a_sigv4_signature,a_whole_secret_string_is_read,a_whole_json_object_is_refused,a_missing_field_is_refused_without_the_secret,a_refusal_names_the_service_error,a_service_message_that_quotes_the_secret_is_redacted,a_missing_identity_is_refused_before_any_call,the_region_comes_from_the_arn_or_the_environment,a_reference_is_plain_and_bounded,a_fetch_discloses_the_ambient_identityandthe_source_fetches_on_the_shared_default_chain.a_call_runs_with_the_chains_credentials,a_call_without_credentials_or_a_runtime_does_not_run,a_stuck_call_releases_the_worker_at_its_deadlineanda_panicking_call_leaves_the_worker_running.discovery_refuses_a_secrets_manager_reference.a_secrets_manager_route_is_refused_when_a_scoped_profile_is_required.no_second_crypto_provider_is_linked.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.