Skip to main content

agentmux_srv_core/backend/vault/
backed.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! A backed entry's value (docs/specs/SPEC_VAULT_SHARED_ACROSS_MACHINES_LAN_AND_CLOUD_2026_11_01.md ยง11.1): the Vault
5//! keeps the entry's label, kind and grants, and the key itself stays in AWS Secrets Manager. Each use reads it from
6//! there with the host's AWS login, so there is no copy in the Vault to go stale, to sync or to leak, and a change made in
7//! Secrets Manager is what the next use gets.
8//!
9//! The value lives in a `Zeroizing` buffer from the CLI's output to the caller, which hands it to the host or a command
10//! and never to an agent. A read that fails says why in fixed sentences (`aws_import`); nothing of the value is in one.
11
12use zeroize::Zeroizing;
13
14use super::aws_import::{self, Source};
15use super::linked;
16use super::source_link::Link;
17use crate::backend::storage::vault::VaultRow;
18use crate::identity::aws_broker::mint::{HostRunner, Runner};
19
20/// Where a backed entry's value is: its AWS secret, and the field of it when the secret is JSON.
21pub fn source_of(row: &VaultRow) -> Result<Source, String> {
22    Link::of_row(row).and_then(|link| link.aws()).ok_or_else(|| format!("{} is backed by AWS Secrets Manager, but its place isn't an AWS secret", row.label))
23}
24
25/// The value of the backed entry `row` for one use, read with `runner`. Not async: a use runs on a blocking thread
26/// (`aws_import::read_value_blocking`).
27pub fn value_with<R: Runner>(runner: &R, row: &VaultRow) -> Result<Zeroizing<String>, String> {
28    debug_assert!(linked::is_backed_row(row));
29    aws_import::read_value_blocking(runner, &source_of(row)?).map_err(|why| format!("{} (read from AWS Secrets Manager): {why}", row.label))
30}
31
32/// [`value_with`] under the host's own AWS login.
33pub fn value_of(row: &VaultRow) -> Result<Zeroizing<String>, String> {
34    value_with(&HostRunner, row)
35}
36
37/// Why a backed entry has no earlier value to name (`id@previous`, `id@pending`): the Vault keeps none, Secrets Manager
38/// does.
39pub fn no_versions(row: &VaultRow, which: &str) -> String {
40    format!("{} is backed by AWS Secrets Manager, so the Vault keeps no earlier value of it: @{which} is for an entry that holds its own value", row.label)
41}
42
43#[cfg(test)]
44#[path = "backed_tests.rs"]
45pub(crate) mod tests;