Skip to content

Commit 509178d

Browse files
committed
feat: pass EXTRA_* env vars to challenge containers
Allows platform-server to pass custom configuration to challenges via environment variables prefixed with EXTRA_. Example: EXTRA_GITHUB_TOKEN=xxx will be passed to challenge containers This enables challenges like bounty-challenge to receive API tokens without hardcoding them.
1 parent f8771fe commit 509178d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

crates/challenge-orchestrator/src/docker.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,15 @@ impl DockerClient {
932932
warn!(challenge = %config.name, "Failed to generate broker JWT token");
933933
}
934934

935+
// Pass through EXTRA_* environment variables to challenge containers
936+
// This allows the platform server to pass custom configuration to challenges
937+
for (key, value) in std::env::vars() {
938+
if key.starts_with("EXTRA_") {
939+
env.push(format!("{}={}", key, value));
940+
debug!(challenge = %config.name, key = %key, "Passing extra env var to challenge");
941+
}
942+
}
943+
935944
// Create container config
936945
let container_config = Config {
937946
image: Some(config.docker_image.clone()),
@@ -1286,6 +1295,40 @@ mod tests {
12861295
reset_env(&["HOSTNAME"]);
12871296
}
12881297

1298+
#[test]
1299+
#[serial]
1300+
fn test_extra_env_vars_collected() {
1301+
// Clean up any existing EXTRA_ vars
1302+
for (key, _) in std::env::vars() {
1303+
if key.starts_with("EXTRA_") {
1304+
std::env::remove_var(&key);
1305+
}
1306+
}
1307+
1308+
// Set test EXTRA_ variables
1309+
std::env::set_var("EXTRA_DEBUG", "1");
1310+
std::env::set_var("EXTRA_CUSTOM_API_KEY", "test_key_123");
1311+
std::env::set_var("NOT_EXTRA_VAR", "should_not_be_included");
1312+
1313+
// Collect EXTRA_ vars the same way as in start_challenge
1314+
let mut env: Vec<String> = Vec::new();
1315+
for (key, value) in std::env::vars() {
1316+
if key.starts_with("EXTRA_") {
1317+
env.push(format!("{}={}", key, value));
1318+
}
1319+
}
1320+
1321+
// Verify EXTRA_ vars are collected
1322+
assert!(env.iter().any(|e| e == "EXTRA_DEBUG=1"));
1323+
assert!(env.iter().any(|e| e == "EXTRA_CUSTOM_API_KEY=test_key_123"));
1324+
assert!(!env.iter().any(|e| e.contains("NOT_EXTRA_VAR")));
1325+
1326+
// Clean up
1327+
std::env::remove_var("EXTRA_DEBUG");
1328+
std::env::remove_var("EXTRA_CUSTOM_API_KEY");
1329+
std::env::remove_var("NOT_EXTRA_VAR");
1330+
}
1331+
12891332
#[tokio::test]
12901333
#[ignore = "requires Docker"]
12911334
async fn test_docker_connect() {

0 commit comments

Comments
 (0)