Skip to content

Commit 6817ae0

Browse files
committed
Fact now sends xattr events as gRPC messages
1 parent 007d2c9 commit 6817ae0

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

fact/src/event/mod.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,21 @@ impl FileData {
431431
let xattr_name = slice_to_string(
432432
&unsafe { extra_data.xattr }.name[..XATTR_NAME_MAX_LEN as usize],
433433
)?;
434-
FileData::SetXattr(XattrFileData { inner, xattr_name })
434+
FileData::SetXattr(XattrFileData {
435+
inner,
436+
xattr_name,
437+
operation: XattrOperation::Set,
438+
})
435439
}
436440
file_activity_type_t::FILE_ACTIVITY_REMOVEXATTR => {
437441
let xattr_name = slice_to_string(
438442
&unsafe { extra_data.xattr }.name[..XATTR_NAME_MAX_LEN as usize],
439443
)?;
440-
FileData::RemoveXattr(XattrFileData { inner, xattr_name })
444+
FileData::RemoveXattr(XattrFileData {
445+
inner,
446+
xattr_name,
447+
operation: XattrOperation::Remove,
448+
})
441449
}
442450
invalid => unreachable!("Invalid event type: {invalid:?}"),
443451
};
@@ -465,11 +473,13 @@ impl From<FileData> for fact_api::file_activity::File {
465473
FileData::RmDir(_) => {
466474
unreachable!("RmDir event reached protobuf conversion");
467475
}
468-
FileData::SetXattr(_) => {
469-
unreachable!("SetXattr event reached protobuf conversion");
476+
FileData::SetXattr(event) => {
477+
let f_act = fact_api::FileXattrChange::from(event);
478+
fact_api::file_activity::File::Xattr(f_act)
470479
}
471-
FileData::RemoveXattr(_) => {
472-
unreachable!("RemoveXattr event reached protobuf conversion");
480+
FileData::RemoveXattr(event) => {
481+
let f_act = fact_api::FileXattrChange::from(event);
482+
fact_api::file_activity::File::Xattr(f_act)
473483
}
474484
FileData::Unlink(event) => {
475485
let activity = Some(fact_api::FileActivityBase::from(event));
@@ -635,10 +645,32 @@ impl PartialEq for RenameFileData {
635645
}
636646
}
637647

648+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
649+
pub enum XattrOperation {
650+
Set,
651+
Remove,
652+
}
653+
638654
#[derive(Debug, Clone, Serialize)]
639655
pub struct XattrFileData {
640656
inner: BaseFileData,
641657
xattr_name: String,
658+
operation: XattrOperation,
659+
}
660+
661+
impl From<XattrFileData> for fact_api::FileXattrChange {
662+
fn from(value: XattrFileData) -> Self {
663+
let activity = fact_api::FileActivityBase::from(value.inner);
664+
let operation = match value.operation {
665+
XattrOperation::Set => fact_api::file_xattr_change::Operation::Set,
666+
XattrOperation::Remove => fact_api::file_xattr_change::Operation::Remove,
667+
};
668+
fact_api::FileXattrChange {
669+
activity: Some(activity),
670+
xattr_name: value.xattr_name,
671+
operation: operation.into(),
672+
}
673+
}
642674
}
643675

644676
#[cfg(test)]

fact/src/host_scanner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ You can increase this limit with:
452452
self.handle_unlink_event(&event);
453453
}
454454

455-
// Skip events that are tracked internally but not yet sent to sensor
456-
if event.is_mkdir() || event.is_rmdir() || event.is_xattr() {
455+
// Skip directory creation and deletion events - we track them internally but don't send to sensor
456+
if event.is_mkdir() || event.is_rmdir() {
457457
continue;
458458
}
459459

third_party/stackrox

Submodule stackrox updated 5282 files

0 commit comments

Comments
 (0)