Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mlw committed Nov 26, 2024
1 parent ee42f28 commit 5b55659
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
18 changes: 14 additions & 4 deletions Source/common/SNTConfigurator.m
Original file line number Diff line number Diff line change
Expand Up @@ -1045,12 +1045,22 @@ - (BOOL)enableForkAndExitLogging {
return number ? [number boolValue] : NO;
}

// This method returns only the values that are of the expected string type.
// The reasoning is that if a filter is attempted to be set, this method should
// return some subset rather than `nil`. Since `nil` effectively means to log
// everything, returning it would be akin to "failing open" even though some
// filter configuration was attempted.
- (NSArray<NSString *> *)telemetry {
NSArray *events = self.configState[kTelemetryKey];
NSArray *configuredEvents = self.configState[kTelemetryKey];
if (!configuredEvents) {
return nil;
}

for (id event in events) {
if (![event isKindOfClass:[NSString class]]) {
return nil;
NSMutableArray *events = [[NSMutableArray alloc] initWithCapacity:configuredEvents.count];

for (id event in configuredEvents) {
if ([event isKindOfClass:[NSString class]]) {
[events addObject:event];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/common/TelemetryEventMap.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TelemetryEvent TelemetryConfigToBitmask(NSArray<NSString *> *telemetry,
mask |= EventNameToMask(santa::NSStringToUTF8StringView([event_name lowercaseString]));
}
} else {
mask = EventNameToMask("everything");
mask = TelemetryEvent::kEverything;

if (enableForkAndExitLogging == false) {
mask &= (~TelemetryEvent::kFork & ~TelemetryEvent::kExit);
Expand Down
46 changes: 24 additions & 22 deletions Source/santad/Santad.mm
Original file line number Diff line number Diff line change
Expand Up @@ -400,31 +400,33 @@ void SantadMain(std::shared_ptr<EndpointSecurityAPI> esapi, std::shared_ptr<Logg
FlushCacheReason::kEntitlementsPrefixFilterChanged);
[authorizer_client clearCache];
}],
[[SNTKVOManager alloc] initWithObject:configurator
selector:@selector(telemetry)
type:[NSArray class]
callback:^(NSArray *oldValue, NSArray *newValue) {
if (!oldValue && !newValue) {
return;
}
[[SNTKVOManager alloc]
initWithObject:configurator
selector:@selector(telemetry)
type:[NSArray class]
callback:^(NSArray *oldValue, NSArray *newValue) {
if (!oldValue && !newValue) {
return;
}

// Ensure the new array is composed of strings
for (id element in newValue) {
if (![element isKindOfClass:[NSString class]]) {
return;
}
}
// Ensure the new array is composed of strings
for (id element in newValue) {
if (![element isKindOfClass:[NSString class]]) {
LOGW(@"Expected type in Telemetry config. Want String. Got: %@: value: %@",
[element class], element);
return;
}
}

if ([oldValue isEqualToArray:newValue]) {
return;
}
if ([oldValue isEqualToArray:newValue]) {
return;
}

LOGI(@"Telemetry changed: %@ -> %@",
[oldValue componentsJoinedByString:@","],
[newValue componentsJoinedByString:@","]);
logger->SetTelemetryMask(santa::TelemetryConfigToBitmask(
newValue, configurator.enableForkAndExitLogging));
}],
LOGI(@"Telemetry changed: %@ -> %@", [oldValue componentsJoinedByString:@","],
[newValue componentsJoinedByString:@","]);
logger->SetTelemetryMask(
santa::TelemetryConfigToBitmask(newValue, configurator.enableForkAndExitLogging));
}],
[[SNTKVOManager alloc] initWithObject:configurator
selector:@selector(enableForkAndExitLogging)
type:[NSNumber class]
Expand Down

0 comments on commit 5b55659

Please sign in to comment.