Skip to content

Commit 2ba7945

Browse files
author
Marco Napetti
committed
feat: wireup secret_gateway_addr
1 parent 1eb47a1 commit 2ba7945

6 files changed

Lines changed: 37 additions & 27 deletions

File tree

crates/firma-config-schema/src/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub struct ProfilePatch {
119119
/// How the sandbox CA trust store is assembled. `None` resolves to the
120120
/// default `CaTrustMode::Sole`.
121121
pub ca_trust_mode: Option<CaTrustMode>,
122+
pub secret_gateway_addr: Option<String>,
122123
/// Secret providers to activate: bare strings reference a built-in
123124
/// integration, tables define a custom one. Additive across
124125
/// `[run.defaults]` and the active profile (like `env_passthrough`);

crates/firma-run/src/config.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use firma_config_schema::secret_provider::SecretProviderPatch;
99
use firma_core::SecretMatcher;
1010
use firma_runtime_state::RuntimeLayout;
1111
use firma_secret_provider::IntegrationSpec;
12+
use firma_secret_provider::gateway::client::GATEWAY_ADDR_ENV;
1213
use serde::Serialize;
1314

1415
pub use firma_config_schema::run::SandboxIdentityMode;
@@ -69,6 +70,7 @@ pub struct ResolvedProfile {
6970
pub capability: CapabilityLeaseConfig,
7071
pub(crate) sidecar_local_exec: Option<CommandMediatorConfig>,
7172
pub(crate) executable_policies: BTreeMap<String, ExecutableLaunchPolicy>,
73+
pub(crate) secret_gateway_addr: Option<String>,
7274
/// Resolved secret-provider integrations: CLI vault tools keyed by binary
7375
/// basename, HTTP vaults keyed by `provider_id`. A CLI entry activates a
7476
/// secret-mediation shim for that binary (stdio routed through the
@@ -498,6 +500,7 @@ impl Merge for ProfilePatch {
498500
allow_non_structural: higher.allow_non_structural.or(self.allow_non_structural),
499501
mask_home_paths: higher.mask_home_paths.or(self.mask_home_paths),
500502
ca_trust_mode: higher.ca_trust_mode.or(self.ca_trust_mode),
503+
secret_gateway_addr: higher.secret_gateway_addr.or(self.secret_gateway_addr),
501504
secret_providers: match (self.secret_providers, higher.secret_providers) {
502505
// Additive across layers (like `env_passthrough`); the later
503506
// (higher) entries come last so they win on name collision in
@@ -640,6 +643,12 @@ pub(crate) fn resolve_profile_with_layout(
640643
.map(|(executable, policy)| (executable, resolve_executable_policy(policy)))
641644
.collect();
642645

646+
let secret_gateway_addr = patch.secret_gateway_addr.clone().or_else(|| {
647+
std::env::var(GATEWAY_ADDR_ENV)
648+
.ok()
649+
.filter(|value| !value.trim().is_empty())
650+
});
651+
643652
let seccomp_policy = patch
644653
.seccomp_policy
645654
.map(seccomp_policy_from_patch)
@@ -664,6 +673,7 @@ pub(crate) fn resolve_profile_with_layout(
664673
sidecar_local_exec,
665674
executable_policies,
666675
secret_providers,
676+
secret_gateway_addr,
667677
use_http_proxy_sidecar: patch.use_http_proxy_sidecar.unwrap_or(false),
668678
allow_non_structural: patch.allow_non_structural.unwrap_or(false),
669679
ca_trust_mode: patch.ca_trust_mode.unwrap_or_default(),
@@ -762,7 +772,8 @@ fn cli_profile_patch(args: &RunInput) -> ProfilePatch {
762772
}),
763773
sidecar_local_exec: None,
764774
executable_policies: None,
765-
secret_providers: Vec::new(),
775+
secret_gateway_addr: None,
776+
secret_providers: None,
766777
use_http_proxy_sidecar: None,
767778
allow_non_structural: args.allow_non_structural.then_some(true),
768779
mask_home_paths: None,
@@ -817,24 +828,6 @@ fn resolve_secret_providers(
817828
Ok(resolved)
818829
}
819830

820-
fn resolve_executable_policies(
821-
patch: BTreeMap<String, ExecutableLaunchPolicyPatch>,
822-
legacy_codex: Option<ExecutableLaunchPolicyPatch>,
823-
) -> BTreeMap<String, ExecutableLaunchPolicy> {
824-
let mut resolved = patch
825-
.into_iter()
826-
.map(|(executable, policy)| (executable, resolve_executable_policy(policy)))
827-
.collect::<BTreeMap<_, _>>();
828-
829-
if let Some(codex_policy) = legacy_codex {
830-
resolved
831-
.entry("codex".to_string())
832-
.or_insert_with(|| resolve_executable_policy(codex_policy));
833-
}
834-
835-
resolved
836-
}
837-
838831
fn resolve_executable_policy(policy: ExecutableLaunchPolicyPatch) -> ExecutableLaunchPolicy {
839832
ExecutableLaunchPolicy {
840833
enforce_wrapper_defaults: policy.enforce_wrapper_defaults.unwrap_or(true),
@@ -2195,11 +2188,12 @@ approval_policy = "never"
21952188
capability,
21962189
sidecar_local_exec,
21972190
executable_policies,
2198-
use_http_proxy_sidecar,
2199-
allow_non_structural,
2200-
mask_home_paths,
2201-
ca_trust_mode,
2202-
secret_providers,
2191+
use_http_proxy_sidecar: _,
2192+
allow_non_structural: _,
2193+
mask_home_paths: _,
2194+
ca_trust_mode: _,
2195+
secret_gateway_addr: _,
2196+
secret_providers: _,
22032197
} = patch;
22042198

22052199
for MountPatch {

crates/firma-run/src/profile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ fn generic_profile() -> ProfilePatch {
8383
}),
8484
sidecar_local_exec: None,
8585
executable_policies: Some(BTreeMap::new()),
86-
secret_providers: Vec::new(),
86+
secret_gateway_addr: None,
87+
secret_providers: None,
8788
use_http_proxy_sidecar: Some(true),
8889
allow_non_structural: Some(false),
8990
mask_home_paths: None,

crates/firma-run/src/runtime/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ pub fn execute_run(args: &RunInput, hooks: &LaunchHooks<'_>) -> Result<i32, RunE
210210
}),
211211
use_http_proxy_sidecar: profile.use_http_proxy_sidecar,
212212
monitor_mode: args.monitor_mode,
213+
secret_gateway_addr: profile.secret_gateway_addr.clone(),
213214
http_secret_providers: profile
214215
.secret_providers
215216
.values()
@@ -904,6 +905,7 @@ mod tests {
904905
requested_actions: CapabilityLeaseConfig::default_requested_actions(),
905906
},
906907
sidecar_local_exec: None,
908+
secret_gateway_addr: None,
907909
secret_providers: BTreeMap::new(),
908910
executable_policies: BTreeMap::new(),
909911
use_http_proxy_sidecar: false,
@@ -973,6 +975,7 @@ mod tests {
973975
requested_actions: CapabilityLeaseConfig::default_requested_actions(),
974976
},
975977
sidecar_local_exec: None,
978+
secret_gateway_addr: None,
976979
secret_providers: BTreeMap::new(),
977980
executable_policies: BTreeMap::new(),
978981
use_http_proxy_sidecar: false,
@@ -1027,6 +1030,7 @@ mod tests {
10271030
requested_actions: CapabilityLeaseConfig::default_requested_actions(),
10281031
},
10291032
sidecar_local_exec: None,
1033+
secret_gateway_addr: None,
10301034
secret_providers: BTreeMap::new(),
10311035
executable_policies: BTreeMap::new(),
10321036
use_http_proxy_sidecar: false,
@@ -1096,6 +1100,7 @@ mod tests {
10961100
requested_actions: CapabilityLeaseConfig::default_requested_actions(),
10971101
},
10981102
sidecar_local_exec: None,
1103+
secret_gateway_addr: None,
10991104
secret_providers: BTreeMap::new(),
11001105
executable_policies: BTreeMap::new(),
11011106
use_http_proxy_sidecar: false,
@@ -1196,6 +1201,7 @@ mod tests {
11961201
requested_actions: CapabilityLeaseConfig::default_requested_actions(),
11971202
},
11981203
sidecar_local_exec: None,
1204+
secret_gateway_addr: None,
11991205
secret_providers: BTreeMap::new(),
12001206
use_http_proxy_sidecar: true,
12011207
allow_non_structural: false,
@@ -1266,6 +1272,7 @@ mod tests {
12661272
requested_actions: CapabilityLeaseConfig::default_requested_actions(),
12671273
},
12681274
sidecar_local_exec: None,
1275+
secret_gateway_addr: None,
12691276
secret_providers: BTreeMap::new(),
12701277
executable_policies: BTreeMap::new(),
12711278
use_http_proxy_sidecar: true,
@@ -1367,6 +1374,7 @@ mod tests {
13671374
requested_actions: CapabilityLeaseConfig::default_requested_actions(),
13681375
},
13691376
sidecar_local_exec: None,
1377+
secret_gateway_addr: None,
13701378
secret_providers: BTreeMap::new(),
13711379
use_http_proxy_sidecar: true,
13721380
allow_non_structural: false,
@@ -1440,6 +1448,7 @@ mod tests {
14401448
requested_actions: CapabilityLeaseConfig::default_requested_actions(),
14411449
},
14421450
sidecar_local_exec: None,
1451+
secret_gateway_addr: None,
14431452
secret_providers: BTreeMap::new(),
14441453
use_http_proxy_sidecar: true,
14451454
allow_non_structural: false,

crates/firma-run/src/sidecar/prepare.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use firma_config_loader::AgentProfile;
88
use firma_core::SecretMatcher;
99
use firma_identifiers::{AgentId, SandboxId};
1010
use firma_runtime_state::RunEntryLayout;
11+
use firma_secret_provider::gateway::client::GATEWAY_ADDR_ENV;
1112
use firma_secret_provider::spec::http::HttpIntegrationSpec;
1213
use firma_sidecar::authority_credentials::SidecarCredentialsConfig;
1314

@@ -174,7 +175,9 @@ pub fn prepare(req: PrepareRequest<'_>) -> Result<PreparedSidecarLaunch, RunErro
174175
command.env("FIRMA_ALLOW_MONITOR_MODE", "1");
175176
}
176177
if let Some(ref addr) = req.secret_gateway_addr {
177-
command.env("FIRMA_SECRET_GATEWAY_ADDR", addr);
178+
command.env(GATEWAY_ADDR_ENV, addr);
179+
} else {
180+
command.env_remove(GATEWAY_ADDR_ENV);
178181
}
179182

180183
Ok(PreparedSidecarLaunch {

crates/firma/tests/integration/sidecar_startup_contract.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use std::io::{BufRead, BufReader};
2020
use std::process::Command;
2121
use std::time::{Duration, Instant};
2222

23+
use firma_secret_provider::gateway::client::GATEWAY_ADDR_ENV;
24+
2325
use super::CONFIG_FILE_NAME;
2426

2527
const CONTRACT_PREFIXES: &[&str] = &[
@@ -196,7 +198,7 @@ pattern = "no_named_groups_here"
196198
.args(["sidecar", "--config"])
197199
.arg(&fixture.config_path)
198200
.args(["--health-bind-addr", "127.0.0.1:0"])
199-
.env("FIRMA_SECRET_GATEWAY_ADDR", "tcp://127.0.0.1:1")
201+
.env(GATEWAY_ADDR_ENV, "tcp://127.0.0.1:1")
200202
.output()
201203
.expect("spawn firma sidecar");
202204
let stderr = String::from_utf8_lossy(&output.stderr);

0 commit comments

Comments
 (0)