Skip to content

macOS Unified Access Logging (UAL)#7598

Merged
mike-myers-tob merged 25 commits intoosquery:masterfrom
dabresua:unifiedlogs_api_2
Aug 3, 2022
Merged

macOS Unified Access Logging (UAL)#7598
mike-myers-tob merged 25 commits intoosquery:masterfrom
dabresua:unifiedlogs_api_2

Conversation

@dabresua
Copy link
Copy Markdown
Contributor

@dabresua dabresua commented May 20, 2022

This PR completes the work done by @puffyCid in #7259 which also continued the work made by @GarretReece and @mike-myers-tob.

The funcionality enables osquery to read from UAL using its API.

My contribution is explained in the blueprint #7591 which, in summary:

  • Limits the rows the table returns using a flag (ual_max_rows), 100 by default
  • If the user launches a non-specific query select * from unified_log returns the rows continuing from the last one, so user can extract all the logs by querying multiple times.

Adds unitary tests for the flag and for the sequential extraction.

Closes:

Co-authored-by: puffycyan@gmail.com
Co-authored-by: GarretReece@users.noreply.github.com

@dabresua dabresua requested review from a team as code owners May 20, 2022 07:26
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented May 20, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@mike-myers-tob mike-myers-tob added this to the 5.4.0 milestone May 24, 2022
@dabresua dabresua marked this pull request as draft May 25, 2022 07:14
dabresua added 2 commits May 26, 2022 12:54
…ng to unified log

Adds hidden column for max row number, deletes flag
Modifies the trigger for sequential access
@dabresua dabresua marked this pull request as ready for review May 27, 2022 07:49
@dabresua
Copy link
Copy Markdown
Contributor Author

dabresua commented Jun 2, 2022

The last changes implement what we discussed at the osquery office hours 2022-05-24.

Getting data sequentially is now triggered by the command select * from unified_log where timestamp > -1. I've tried to implement a sentinel value like LAST_TIMESTAMP, but I found the SQLite engine was not expecting a non-numerical value and rejected it, returning nothing.

Instead of a flag, a HIDDEN column is used for max_rows. The default value is 100, the way to modify it is by adding the clause max_rows = N. For example, select * from unified_logs where max_rows = 123 returns up to 123 rows.

User shall combine both clauses, i.e. select * from unified logs where timestamp > -1 and max_rows = 1000. This query returns the first 1000 log entries, and if we run it again, it will return the next 1000 log entries ordered by timestamp.

@dabresua
Copy link
Copy Markdown
Contributor Author

dabresua commented Jun 7, 2022

Finishes the work done in #7259

@mike-myers-tob
Copy link
Copy Markdown
Member

@directionless is going to re-review but it's moving to the 5.5 milestone

@mike-myers-tob mike-myers-tob modified the milestones: 5.4.0, 5.5.0 Jul 5, 2022
Copy link
Copy Markdown
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.

Code looks mostly fine to me. @alessandrogario @Smjert either you look?

One question -- I think this has a single tracking state for the last seen state. So if you had two queries each using this table and the -1 it wouldn't work. Correct?

table_name("unified_log")
description("Queries the OSLog framework for entries in the system log. "
"The maximum number of rows returned is limited for performance issues. "
"The condition \"max_rows = N\" sets the maximum number of rows returned (100 by default). "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"The condition \"max_rows = N\" sets the maximum number of rows returned (100 by default). "

@directionless
Copy link
Copy Markdown
Member

directionless commented Jul 18, 2022

I tried select timestamp, process, substr(message, 0, 200) from unified_log where max_rows = 50 and timestamp = -1; and it returned no data and mostly wedged.

And I realized an awkward spot... If the SQL has where timestamp = -1, than the table has to return that, else sqlite will filter out the data. This means would cause the timestamp data to be lost.

@directionless
Copy link
Copy Markdown
Member

Ha. Correcting myself, where timestamp > -1 works correctly.

And where timestamp = -1 seems like a footgun we probably shouldn't try to fix?

@dabresua
Copy link
Copy Markdown
Contributor Author

Ha. Correcting myself, where timestamp > -1 works correctly.

And where timestamp = -1 seems like a footgun we probably shouldn't try to fix?

As you said before, SQLite allows only the data with timestamp = -1, so it will be filtered. However, someway the UAL engine gets stuck, I'm adding an escape condition for that situation.

@directionless
Copy link
Copy Markdown
Member

I think this is probably mergable? At least, I don't think I have other comments. @Smjert, @alessandrogario Either of you have comments?

@dabresua I don't know if it makes sense, you could consider tossing in the github Co-authored-by for the other folks. Or not.

Copy link
Copy Markdown
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.

Sounds like we all think this is approvable. wooo!

Thank you so much for sticking with it @dabresua it's a huge PR and improvement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants