surjection_core/secrets/mod.rs
1//! Secrets (SPEC 11): references, providers and the leak scanner.
2//!
3//! - [`grammar`]: templates (`${secret:ALIAS}`, ...) and provider
4//! references (`op://`, `op-env://`, `keyring://`, `env:`).
5//! - [`catalog`]: `secrets.toml` with this machine's overlay applied.
6//! - [`providers`]: env, OS keyring and the 1Password CLI; [`status`] is
7//! what resolving found.
8//! - [`classify`] and [`scanner`]: the SPEC 11.7 classifier and the leak
9//! scanner every store commit passes through; [`extract`] replaces
10//! sensitive literals by aliases on import and migration.
11//! - [`delivery`] and [`render`]: how references reach a server for one
12//! client (SPEC 11.4: `env`, `launch`, `command`, `inline`).
13//!
14//! Values exist only in memory, inside a [`SecretValue`]: it has no
15//! `Display`, no `Serialize`, and its `Debug` is redacted, so a value
16//! cannot end up in a store file, a log line or an error by accident.
17//! Every value a provider hands out is recorded (as a keyed hash) in the
18//! process's [`scanner::SecretMemory`], so a later commit that holds it is
19//! refused.
20
21pub mod catalog;
22pub mod classify;
23pub mod delivery;
24pub mod extract;
25pub mod grammar;
26pub mod providers;
27pub mod render;
28pub mod scanner;
29pub mod status;
30
31use std::fmt;
32
33/// A resolved secret value. Read it with [`SecretValue::expose`] at the
34/// one place that hands it on (a child process environment, the keyring).
35#[derive(Clone, PartialEq, Eq)]
36pub struct SecretValue(String);
37
38impl SecretValue {
39 pub fn new(value: impl Into<String>) -> Self {
40 Self(value.into())
41 }
42
43 pub fn expose(&self) -> &str {
44 &self.0
45 }
46}
47
48impl fmt::Debug for SecretValue {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 f.write_str("SecretValue(<redacted>)")
51 }
52}