Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ axum = "0.8.9"
clap = { version = "4.6.1", features = ["derive"] }
# Keep all five workspace components on one immutable rust-gvm commit so Cargo
# resolves a coherent upstream snapshot.
gvm-client = { git = "https://github.com/greenbone/rust-gvm", rev = "ab437cfaab51b636b0ef69bddde09103dbb16b92" }
gvm-connection = { git = "https://github.com/greenbone/rust-gvm", rev = "ab437cfaab51b636b0ef69bddde09103dbb16b92" }
gvm-gmp = { git = "https://github.com/greenbone/rust-gvm", rev = "ab437cfaab51b636b0ef69bddde09103dbb16b92", features = ["serde"] }
gvm-mock-server = { git = "https://github.com/greenbone/rust-gvm", rev = "ab437cfaab51b636b0ef69bddde09103dbb16b92" }
gvm-protocol = { git = "https://github.com/greenbone/rust-gvm", rev = "ab437cfaab51b636b0ef69bddde09103dbb16b92" }
gvm-client = { git = "https://github.com/greenbone/rust-gvm", rev = "5b723fadc53660e7eafb642a13a5877b76b93558" }
gvm-connection = { git = "https://github.com/greenbone/rust-gvm", rev = "5b723fadc53660e7eafb642a13a5877b76b93558" }
gvm-gmp = { git = "https://github.com/greenbone/rust-gvm", rev = "5b723fadc53660e7eafb642a13a5877b76b93558", features = ["serde"] }
gvm-mock-server = { git = "https://github.com/greenbone/rust-gvm", rev = "5b723fadc53660e7eafb642a13a5877b76b93558" }
gvm-protocol = { git = "https://github.com/greenbone/rust-gvm", rev = "5b723fadc53660e7eafb642a13a5877b76b93558" }
http = "1.4.1"
opentelemetry = { version = "0.33.0", features = ["trace"] }
opentelemetry-otlp = { version = "0.33.0", features = ["grpc-tonic", "trace"] }
Expand Down
1 change: 1 addition & 0 deletions crates/gvm-gateway-app/src/test_support/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ impl AgentPort for MockAgentPort {
interval_in_seconds: Some(60),
miss_until_inactive: Some(3),
}),
file_search: None,
}),
})
}
Expand Down
11 changes: 11 additions & 0 deletions crates/gvm-gateway-domain/src/agents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ pub struct AgentConfig {
/// Heartbeat settings.
#[serde(skip_serializing_if = "Option::is_none")]
pub heartbeat: Option<AgentHeartbeatConfig>,
/// File-search exclusions for updates; omitted settings remain unchanged.
#[serde(rename = "fileSearch", skip_serializing_if = "Option::is_none")]
pub file_search: Option<AgentFileSearchConfig>,
}

/// File-search settings for agent configuration updates.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct AgentFileSearchConfig {
/// Paths sent verbatim; omission preserves exclusions and an empty list clears them.
#[serde(rename = "excludedPaths", skip_serializing_if = "Option::is_none")]
pub excluded_paths: Option<Vec<String>>,
}

/// Agent-control settings.
Expand Down
2 changes: 2 additions & 0 deletions crates/gvm-gateway-gvmd/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ fn agent_config_from_gmp(config: gvm_gmp::responses::AgentConfig) -> AgentConfig
.agent_script_executor
.map(agent_script_executor_config_from_gmp),
heartbeat: config.heartbeat.map(agent_heartbeat_config_from_gmp),
// File-search support is write-only until upstream provides typed read-back.
file_search: None,
}
}

Expand Down
5 changes: 5 additions & 0 deletions crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/agents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ fn agent_config_opts_from_domain(input: AgentConfig) -> AgentConfigOpts {
.agent_script_executor
.map(agent_script_executor_config_opts_from_domain),
heartbeat: input.heartbeat.map(agent_heartbeat_config_opts_from_domain),
file_search: input.file_search.map(|config| {
gvm_gmp::commands::agents::AgentFileSearchConfig {
excluded_paths: config.excluded_paths,
}
}),
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/gvm-gateway-gvmd/tests/architecture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const RUST_GVM_COMPONENTS: &[&str] = &[
// v0.12.0 release commit.
const RUST_GVM_DEPENDENCY_URL: &str = "https://github.com/greenbone/rust-gvm";
const RUST_GVM_DEPENDENCY_VERSION: &str = "0.12.0";
const RUST_GVM_DEPENDENCY_REVISION: &str = "ab437cfaab51b636b0ef69bddde09103dbb16b92";
// File-search write support is pinned independently of the release facade snapshot below.
const RUST_GVM_DEPENDENCY_REVISION: &str = "5b723fadc53660e7eafb642a13a5877b76b93558";
// The v0.12.0 release retains the reviewed 270-helper feature-stack facade.
// Advance the matching snapshot and disposition ledger to the release tag
// without changing their deliberately reviewed classifications.
Expand Down
41 changes: 41 additions & 0 deletions crates/gvm-gateway-rest/src/agents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,42 @@ struct AgentConfigRequest {
#[serde(rename = "agentScriptExecutor")]
agent_script_executor: Option<AgentScriptExecutorConfigRequest>,
heartbeat: Option<AgentHeartbeatConfigRequest>,
/// Omit to leave file-search settings unchanged; null is not accepted.
#[serde(
rename = "fileSearch",
default,
deserialize_with = "deserialize_file_search"
)]
file_search: Option<AgentFileSearchConfigRequest>,
}

#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
#[schemars(rename = "AgentFileSearchConfigUpdate")]
struct AgentFileSearchConfigRequest {
/// Paths are preserved verbatim. Omit to keep exclusions; use [] to clear them.
#[serde(
rename = "excludedPaths",
default,
deserialize_with = "deserialize_excluded_paths"
)]
excluded_paths: Option<Vec<String>>,
}

// Serde defaults handle omission, while present values must have the declared type.
fn deserialize_file_search<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Option<AgentFileSearchConfigRequest>, D::Error> {
// Struct deserialization also accepts sequences; require a JSON object explicitly.
let object = serde_json::Map::<String, serde_json::Value>::deserialize(deserializer)?;
AgentFileSearchConfigRequest::deserialize(serde_json::Value::Object(object))
.map(Some)
.map_err(serde::de::Error::custom)
}

fn deserialize_excluded_paths<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Option<Vec<String>>, D::Error> {
Vec::<String>::deserialize(deserializer).map(Some)
}

impl ValidateInto<AgentConfig> for AgentConfigRequest {
Expand All @@ -430,6 +466,11 @@ impl ValidateInto<AgentConfig> for AgentConfigRequest {
.heartbeat
.map(ValidateInto::validate_into)
.transpose()?,
file_search: self
.file_search
.map(|config| gvm_gateway_domain::AgentFileSearchConfig {
excluded_paths: config.excluded_paths,
}),
})
}
}
Expand Down
69 changes: 69 additions & 0 deletions crates/gvm-gateway-rest/src/agents_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,72 @@ fn response_delay_observations_validate_without_write_range_truncation() {
}
}
}

#[test]
fn file_search_updates_preserve_omission_clearing_and_verbatim_paths() {
// Both update wrappers must preserve the distinction between no update and clearing.
let paths = vec![
r"C:\Program Files\Agent",
r"C:\\doubled\\path",
r"\\server\share",
" /private & <cache>\t\n ",
];
for (config, expected) in [
(json!({}), None),
(json!({"fileSearch": {}}), Some(None)),
(
json!({"fileSearch": {"excludedPaths": []}}),
Some(Some(vec![])),
),
(
json!({"fileSearch": {"excludedPaths": paths}}),
Some(Some(paths.iter().map(|path| (*path).to_owned()).collect())),
),
] {
let agent: ModifyAgentRequest = serde_json::from_value(json!({"config": config})).unwrap();
let controller: ModifyAgentControlScanConfigRequest =
serde_json::from_value(json!({"agentDefaults": config})).unwrap();
for parsed in [
agent.validate_into().unwrap().config.unwrap(),
controller.validate_into().unwrap().agent_defaults.unwrap(),
] {
assert_eq!(
parsed.file_search.map(|section| section.excluded_paths),
expected
);
}
}
}

#[test]
fn file_search_updates_reject_null_and_invalid_shapes_in_both_wrappers() {
// Optional fields may be absent, but must not silently discard malformed updates.
for section in [
json!(null),
json!([]),
json!([[]]),
json!("path"),
json!(42),
json!(false),
json!({"excludedPaths": null}),
json!({"excludedPaths": "/private"}),
json!({"excludedPaths": {"path": "/private"}}),
json!({"excludedPaths": 42}),
json!({"excludedPaths": [null]}),
json!({"excludedPaths": [42]}),
json!({"excludedPaths": ["/private", false]}),
] {
let config = json!({"fileSearch": section});
assert!(
serde_json::from_value::<ModifyAgentRequest>(json!({"config": config})).is_err(),
"{config}"
);
assert!(
serde_json::from_value::<ModifyAgentControlScanConfigRequest>(
json!({"agentDefaults": config})
)
.is_err(),
"{config}"
);
}
}
45 changes: 45 additions & 0 deletions crates/gvm-gateway-rest/src/openapi_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2353,3 +2353,48 @@ fn inventory_token_generated_and_curated_success_headers_forbid_caching() {
expected
);
}

#[test]
fn file_search_update_schemas_preserve_optional_non_nullable_clearable_lists() {
// The generated and curated contracts must advertise clearing without accepting null.
let generated = build_openapi();
let spec_path = root_spec_path();
let curated = read_yaml(&spec_path.parent().unwrap().join("emerging.yaml"));
for document in [&generated, &curated] {
let schemas = &document["components"]["schemas"];
let config = &schemas["AgentConfigUpdate"];
let field = resolve_local_schema_ref(schemas, &config["properties"]["fileSearch"]);
assert_eq!(field, &schemas["AgentFileSearchConfigUpdate"]);
assert_eq!(field["type"], "object");
assert!(!config["required"]
.as_array()
.is_some_and(|fields| fields.contains(&json!("fileSearch"))));
assert!(!field["required"]
.as_array()
.is_some_and(|fields| fields.contains(&json!("excludedPaths"))));
let list = &field["properties"]["excludedPaths"];
assert_eq!(list["type"], "array");
assert_eq!(list["items"]["type"], "string");
let validator = jsonschema::validator_for(field).unwrap();
for valid in [
json!({}),
json!({"excludedPaths": []}),
json!({"excludedPaths": [r"\\server\share"]}),
] {
assert!(validator.is_valid(&valid), "{valid}");
}
for invalid in [
Value::Null,
json!([]),
json!({"excludedPaths": null}),
json!({"excludedPaths": "path"}),
json!({"excludedPaths": [1]}),
] {
assert!(!validator.is_valid(&invalid), "{invalid}");
}
// Write support must not advertise unimplemented GET/read-back fields.
assert!(schemas["AgentConfig"]["properties"]
.get("fileSearch")
.is_none());
}
}
Loading
Loading