Skip to content

feat(credentials): read a secret from AWS Secrets Manager - #448

Closed
SaiAbhishek98 wants to merge 1 commit into
strands-agents:mainfrom
SaiAbhishek98:feature/aws-secretsmanager-credentials
Closed

SaiAbhishek98 wants to merge 1 commit into
strands-agents:mainfrom
SaiAbhishek98:feature/aws-secretsmanager-credentials

Conversation

@SaiAbhishek98

Copy link
Copy Markdown
Contributor

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 of SECRET, a name or an ARN, or one string field of a JSON secret. Thus one secret can hold the key for each target:

[telemetry.langsmith]
kind = "otlp"
destination = "https://api.smith.langchain.com/otel"
secret.ref = "aws-secretsmanager://box/telemetry#LANGSMITH_API_KEY"
secret.header = "x-api-key"

Decisions that the diff does not show

  • The source uses the default chain from feat(credentials): sign a bare aws:// with the AWS default credential chain #342, and has no AWS machinery of its own. The GetSecretValue request goes through the worker that a bare aws:// uses, with a new SdkChainProvider::call. The request uses the runtime, the ring HTTPS 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.
  • A call blocks the other callers of the worker while it runs. The source calls it one time, at startup, and never on each request. The worker stops the call at its deadline (20 s), so a stuck call cannot block a bare aws:// signer for longer. A call that panics gives an error to its caller, and the worker continues.
  • A secret that is a JSON object needs #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-secretsmanager has its default features off. The default features add the default HTTPS client, which puts aws-lc in the build together with ring. The rustls builders of the egress gateway then panic. no_second_crypto_provider_is_linked fails if aws-lc-rs, aws-lc-sys or a second rustls gets into Cargo.lock. Cargo.lock gets one new package.
  • The request signs with the ambient identity, so it has the same credential_process risk as a bare aws://. A vault built with require_scoped_aws_profile refuses the scheme before a fetch. Box prints one line on stderr that says it used the ambient identity of the host.
  • No message shows the secret value. Box redacts the reference in its messages and in the stderr line, and also where an AWS refusal such as AccessDeniedException quotes the name of the secret. The AWS message can still name the signing role.

Interface changes

These change frozen surfaces:

  • The credential scheme aws-secretsmanager://SECRET[#FIELD].
  • A telemetry secret.ref accepts the scheme, and the text of its refusal changes. An egress secret.ref does not change. Schema discovery (policy generate-schema) refuses the scheme in an [mcp.<name>] secret.ref, as run does.
  • The stderr line: 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::resolve can now send a request to AWS Secrets Manager.
  • SdkChainProvider::call in crates/credentials, visible only in crate::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/logs and /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

  • An egress route cannot use the scheme. That is a separate change to the egress vocabulary.
  • The source reads the secret one time for each run. A rotated secret takes effect on the next run.

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.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Results on this branch, which is based on main at 70eb3af:

  • 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 PR does not change. It passed 3 of 3 runs alone.
  • cargo fmt --all --check has no errors.
  • cargo clippy --workspace --all-targets --all-features reports warnings only in crates/shell. This PR does not change crates/shell.
  • cargo build --workspace --all-features --locked has no errors, so Cargo.lock is consistent.
  • feature-critic ran 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.
  • New tests:
    • The source: 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_identity and the_source_fetches_on_the_shared_default_chain.
    • The worker: 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_deadline and a_panicking_call_leaves_the_worker_running.
    • Schema discovery: discovery_refuses_a_secrets_manager_reference.
    • The vault: a_secrets_manager_route_is_refused_when_a_scoped_profile_is_required.
    • The build: no_second_crypto_provider_is_linked.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## 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.
@github-actions github-actions Bot added enhancement New feature or request Area - Egress/Creds Area - Telemetry The telemetry collector, receiver, and record targets labels Nov 13, 2026
@yesyayen

Copy link
Copy Markdown
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 crates/credentials. It provides a clean contract and so a new provider needs no Core change.

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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Egress/Creds Area - Telemetry The telemetry collector, receiver, and record targets enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants