Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a table for the unified log on darwin #6904

Closed

Conversation

GarretReece
Copy link
Contributor

@GarretReece GarretReece commented Jan 15, 2021

This code implements a virtual table for darwin that uses the OSLog framework to read and return entries from the unified system log. Prior versions of macOS did not have an api to access this data, necessitating an extension that invoked the log utility. macOS 10.15 makes this no longer necessary.

At the moment I've tested these changes only on a 10.15 vm. I'd be grateful to the community for feedback regarding building on earlier versions of macOS.

Closes #5760

@mike-myers-tob mike-myers-tob added macOS macOS Big Sur For things pertaining to macOS 11.0 macOS Catalina For things pertaining to macOS 10.15 logging labels Jan 15, 2021
Copy link
Member

@directionless directionless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love seeing this! Some questions/nits

osquery/tables/system/darwin/unified_log.mm Outdated Show resolved Hide resolved
specs/darwin/unified_log.table Show resolved Hide resolved
{LESS_THAN_OR_EQUALS, NSLessThanOrEqualToPredicateOperatorType},
{LIKE, NSLikePredicateOperatorType}};

const std::map<std::string, std::string> columnToOSLogEntryProp = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble finding docs on the object in question, but man logs also describes eventType, messageType, processImagePath, and senderImagePath. Do you think we care about any of those?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the best place to find docs would probably be the entry for OSLogEntryLog. processImagePath and senderImagePath aren't exposed in this API. eventType might be something we can extract, I'll take a look, though I don't think so. messageType is the severity of the message when the event type is a log or trace event--I'm not sure it's exposed in this api either. I'll dig in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this might work:

const char* aulLevelNames[] = {
[OSLogEntryLogLevelUndefined] = "undefined",
[OSLogEntryLogLevelDebug] = "debug",
[OSLogEntryLogLevelInfo] = "info",
[OSLogEntryLogLevelNotice] = "default",
[OSLogEntryLogLevelError] = "error",
[OSLogEntryLogLevelFault] = "fault",
};

  if ([entry isKindOfClass:[OSLogEntryLog class]]) { 
    r["type"] = aulLevelNames[[(OSLogEntryLog*)entry level]];
  } else if ([entry isKindOfClass:[OSLogEntryActivity class]]) {
     r["type"] = "activity";
  } 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is slightly dangerous. If the set of logtypes change then this could fault. However, that seems unlikely. Can you use a C++ container to get this same effect, then you will except vs. fault.

osquery/tables/system/darwin/unified_log.mm Outdated Show resolved Hide resolved
osquery/tables/system/darwin/unified_log.mm Outdated Show resolved Hide resolved
@Smjert Smjert closed this Jan 22, 2021
@Smjert Smjert reopened this Jan 22, 2021
@GarretReece GarretReece force-pushed the garret/table/darwin_unified_log branch from 5a3a581 to bc2040e Compare January 22, 2021 22:30
@mike-myers-tob mike-myers-tob added the ready for review Pull requests that are ready to be reviewed by a maintainer label Jan 25, 2021
osquery/tables/system/darwin/unified_log.mm Outdated Show resolved Hide resolved
osquery/tables/system/darwin/unified_log.mm Outdated Show resolved Hide resolved
@theopolis theopolis removed the ready for review Pull requests that are ready to be reviewed by a maintainer label Feb 5, 2021
@GarretReece GarretReece requested review from a team as code owners March 9, 2021 01:33
@mike-myers-tob
Copy link
Member

I did some ad-hoc testing on macOS 11.2 and it works there also (previously was tested only on 10.15).

If anyone would like to help with this PR, I see a few things to finish:

  1. Querying the table without any reasonable constraints resulted in a segfault, so I think we'll have to determine the root cause of that and whether it can be prevented
  2. Add some unit tests
  3. Add a section to the wiki page about syslog consumption on macOS with osquery which is currently about ASL

@mike-myers-tob
Copy link
Member

Much thanks to @GarretReece and @puffyCid on this, we can close this PR in favor of finishing the work in #7259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logging macOS Big Sur For things pertaining to macOS 11.0 macOS Catalina For things pertaining to macOS 10.15 macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecation of ASL logging, and asl table
6 participants