diff --git a/docs/command-replacements.md b/docs/command-replacements.md index 34d66d3bdea..a18905ff6ba 100644 --- a/docs/command-replacements.md +++ b/docs/command-replacements.md @@ -16,6 +16,8 @@ The following values are replaced with the specific values at runtime. * `{runtime_dir}`: Path to the runtime directory for the task * `{tools_dir}`: Path to the task specific `tools` directory * `{setup_dir}` : Path to the setup directory +* `{job_id}`: UUID that indicates the Job ID +* `{task_id}`: UUID that indicates the Task ID ## Example @@ -38,15 +40,18 @@ If you need `supervisor_options` to expand to: `"a", "b", "c", "d"`, you should These are currently used in the following tasks: -* libfuzzer_fuzz: `target_exe`, `target_options`, `input_corpus`, `crashes` -* libfuzzer_crash_report: `target_exe`, `target_options`, `input` -* libfuzzer_merge: `target_exe`, `target_options`, `input_corpus` -* libfuzzer_coverage: None -* generic_analysis: `input`, `target_exe`, `target_options`, `analyzer_exe`, - `anayzer_options`, `output_dir`, `tools_dir` -* generic_generator: `generated_inputs`, `input_corpus`, `tools_dir`, - `generator_exe`, `generator_options`, `target_exe`, `target_options`, `input` -* generic_supervisor: `crashes`, `runtime_dir`, `target_exe`, `target_options`, - `input_corpus`, `input`, `supervisor_exe`, `supervisor_options`, `tools_dir` -* generic_merge: `input`, `input_corpus`, `output_dir`, `target_exe`, - `target_options`, `supervisor_exe`, `supervisor_options`, `tools_dir` +* libfuzzer\_fuzz: `target_exe`, `target_options`, `input_corpus`, `crashes` +* libfuzzer\_crash\_report: `target_exe`, `target_options`, `input` +* libfuzzer\_merge: `target_exe`, `target_options`, `input_corpus` +* libfuzzer\_coverage: None +* generic\_analysis: `input`, `target_exe`, `target_options`, `analyzer_exe`, + `anayzer_options`, `output_dir`, `tools_dir`, `job_id`, `task_id` +* generic\_generator: `generated_inputs`, `input_corpus`, `tools_dir`, + `generator_exe`, `generator_options`, `target_exe`, `target_options`, + `input`, `job_id`, `task_id` +* generic\_supervisor: `crashes`, `runtime_dir`, `target_exe`, `target_options`, + `input_corpus`, `input`, `supervisor_exe`, `supervisor_options`, `tools_dir`, + `job_id`, `task_id` +* generic\_merge: `input`, `input_corpus`, `output_dir`, `target_exe`, + `target_options`, `supervisor_exe`, `supervisor_options`, `tools_dir`, + `job_id`, `task_id` diff --git a/src/agent/onefuzz-agent/src/tasks/analysis/generic.rs b/src/agent/onefuzz-agent/src/tasks/analysis/generic.rs index d8324a30fdd..9c8e2a61d03 100644 --- a/src/agent/onefuzz-agent/src/tasks/analysis/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/analysis/generic.rs @@ -124,7 +124,9 @@ pub async fn run_tool(input: impl AsRef, config: &Config) -> Result<()> { .analyzer_options(&config.analyzer_options) .output_dir(&config.analysis.path) .tools_dir(&config.tools.path) - .setup_dir(&config.common.setup_dir); + .setup_dir(&config.common.setup_dir) + .job_id(&config.common.job_id) + .task_id(&config.common.task_id); let analyzer_path = expand.evaluate_value(&config.analyzer_exe)?; diff --git a/src/agent/onefuzz-agent/src/tasks/fuzz/generator.rs b/src/agent/onefuzz-agent/src/tasks/fuzz/generator.rs index 3a2d14ea538..72c4c636689 100644 --- a/src/agent/onefuzz-agent/src/tasks/fuzz/generator.rs +++ b/src/agent/onefuzz-agent/src/tasks/fuzz/generator.rs @@ -156,7 +156,9 @@ impl GeneratorTask { .generated_inputs(&output_dir) .input_corpus(&corpus_dir) .generator_exe(&self.config.generator_exe) - .generator_options(&self.config.generator_options); + .generator_options(&self.config.generator_options) + .job_id(&self.config.common.job_id) + .task_id(&self.config.common.task_id); if let Some(tools) = &self.config.tools { expand.tools_dir(&tools.path); diff --git a/src/agent/onefuzz-agent/src/tasks/fuzz/supervisor.rs b/src/agent/onefuzz-agent/src/tasks/fuzz/supervisor.rs index d3d068fbb82..fa3513fd513 100644 --- a/src/agent/onefuzz-agent/src/tasks/fuzz/supervisor.rs +++ b/src/agent/onefuzz-agent/src/tasks/fuzz/supervisor.rs @@ -181,7 +181,9 @@ async fn start_supervisor( .crashes(&crashes.path) .input_corpus(&inputs.path) .reports_dir(&reports_dir) - .setup_dir(&config.common.setup_dir); + .setup_dir(&config.common.setup_dir) + .job_id(&config.common.job_id) + .task_id(&config.common.task_id); if let Some(tools) = &config.tools { expand.tools_dir(&tools.path); diff --git a/src/agent/onefuzz-agent/src/tasks/merge/generic.rs b/src/agent/onefuzz-agent/src/tasks/merge/generic.rs index e4d3f9f3431..99afba6ba7a 100644 --- a/src/agent/onefuzz-agent/src/tasks/merge/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/merge/generic.rs @@ -140,7 +140,9 @@ async fn merge(config: &Config, output_dir: impl AsRef) -> Result<()> { .generated_inputs(output_dir) .target_exe(&config.target_exe) .setup_dir(&config.common.setup_dir) - .tools_dir(&config.tools.path); + .tools_dir(&config.tools.path) + .job_id(&config.common.job_id) + .task_id(&config.common.task_id); let supervisor_path = expand.evaluate_value(&config.supervisor_exe)?; diff --git a/src/agent/onefuzz/src/expand.rs b/src/agent/onefuzz/src/expand.rs index 8e6fcfbf122..410ad4954be 100644 --- a/src/agent/onefuzz/src/expand.rs +++ b/src/agent/onefuzz/src/expand.rs @@ -6,6 +6,7 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use strum::IntoEnumIterator; use strum_macros::EnumIter; +use uuid::Uuid; pub enum ExpandedValue<'a> { Path(String), @@ -35,6 +36,8 @@ pub enum PlaceHolder { SupervisorOptions, SetupDir, ReportsDir, + JobId, + TaskId, } impl PlaceHolder { @@ -59,6 +62,8 @@ impl PlaceHolder { Self::SupervisorOptions => "{supervisor_options}", Self::SetupDir => "{setup_dir}", Self::ReportsDir => "{reports_dir}", + Self::JobId => "{job_id}", + Self::TaskId => "{task_id}", } .to_string() } @@ -233,6 +238,18 @@ impl<'a> Expand<'a> { self } + pub fn task_id(&mut self, arg: &Uuid) -> &mut Self { + let value = arg.to_hyphenated().to_string(); + self.set_value(PlaceHolder::TaskId, ExpandedValue::Scalar(value)); + self + } + + pub fn job_id(&mut self, arg: &Uuid) -> &mut Self { + let value = arg.to_hyphenated().to_string(); + self.set_value(PlaceHolder::JobId, ExpandedValue::Scalar(value)); + self + } + fn replace_value( &self, fmtstr: &str,