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 support for basic chassis information #5282

Merged
merged 13 commits into from Jun 10, 2020

Conversation

jjerger
Copy link
Contributor

@jjerger jjerger commented Nov 6, 2018

This will query basic chassis_information such as equipped alarms and breach status/description should there be one.

I have not yet included an integration test because I am not sure which fields to verify as not null - this WMI class can return alot of null values depending on what the chassis is equipped with. I was hoping for some input on what should be verified for this table to be considered sane as well as my approach to handling the boolean values (resetting a value each time for example).

@facebook-github-bot facebook-github-bot added the cla signed Automated label: Pull Request author has signed the osquery CLA label Nov 6, 2018
osquery/tables/system/windows/chassis_info.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/chassis_info.cpp Outdated Show resolved Hide resolved
if (!wmiResults.empty()) {
for (const auto& data : wmiResults) {
Row r;
bool boolean = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename this :p Also auto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I struggled to find a good name for this since it's so generic. Any ideas here? What if I just said "condition"? Or maybe "isPresent" ? That sounds very c# though

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps an endrun, these seem to be more commonly represented as INTs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You know, revisiting this after a long hiatus made me realize "boolean" in this case relates to items in wmiResults, not a variable that is tracking if I want to bail out.

I'm renaming this to isPresent, because it will represent if a certain feature exists on the machine (wmiResults will have true/false for this field). If there's any thought on a better variable name, let me know.

Consequently, I'm going to add a bail condition to the for loop.

osquery/tables/system/windows/chassis_info.cpp Outdated Show resolved Hide resolved
implementation("chassis_info@genChassisInfo")
examples([
"select * from chassis_info",
])
Copy link
Contributor

Choose a reason for hiding this comment

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

New line

specs/windows/chassis_info.table Show resolved Hide resolved
@jjerger
Copy link
Contributor Author

jjerger commented Dec 13, 2018

Anything else I need to change? I'd like to upstream this by sometime early January if possible

@jjerger
Copy link
Contributor Author

jjerger commented Feb 21, 2019

Oops, I forgot I let this one slip. Is there anything else I needed to change and any response wrt to the questions re: flipping the logic and returning early?

@muffins
Copy link
Contributor

muffins commented Sep 15, 2019

@jjerger sorry we let this one slip! Any chance you could rebase this off of the latest master, make the "return early" changes suggested and we'll get this merged? Otherwise the code looked good to me.

@jjerger
Copy link
Contributor Author

jjerger commented Sep 23, 2019 via email

@jjerger
Copy link
Contributor Author

jjerger commented May 7, 2020

Holy cow I really need to get on this.

Are we still okay to rebase off the master, flip the return early changes and get this merged? I can get moving on that.

@directionless
Copy link
Member

Yes. Rebasing on master is correct. Early returns are preferred. Happy to re-review with those.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 27, 2020

CLA Check

@jjerger
Copy link
Contributor Author

jjerger commented May 27, 2020

Ah, regarding CLAs, I left and rejoined Google in the time since I opened this, so I will need to re-link my github account to the org. I should have that handled in the next day or so.

@theopolis
Copy link
Member

theopolis commented May 31, 2020

Hopefully two more steps and this is ready to go!

  1. The Linux builds are failing due to code formatting, apply the patch:
diff --git a/osquery/tables/system/windows/chassis_info.cpp b/osquery/tables/system/windows/chassis_info.cpp
index 3682cd80..c0e2e975 100644
--- a/osquery/tables/system/windows/chassis_info.cpp
+++ b/osquery/tables/system/windows/chassis_info.cpp
@@ -24,7 +24,7 @@ QueryData genChassisInfo(QueryContext& context) {
   WmiRequest wmiSystemReq("select * from Win32_SystemEnclosure");
   const auto& wmiResults = wmiSystemReq.results();
 
-  //check if the results are empty and return a warning if so
+  // check if the results are empty and return a warning if so
   if (wmiResults.empty()) {
     LOG(WARNING) << wmiSystemReq.getStatus().getMessage();
     return results;
@@ -41,7 +41,7 @@ QueryData genChassisInfo(QueryContext& context) {
     r["chassis_types"] = INTEGER(number);
     data.GetString("Description", r["description"]);
 
-    //reset boolean to make sure there is no interference from the last call
+    // reset boolean to make sure there is no interference from the last call
     boolean = false;
 
     data.GetBool("LockPresent", boolean);
@@ -55,7 +55,7 @@ QueryData genChassisInfo(QueryContext& context) {
     data.GetString("SKU", r["sku"]);
     data.GetString("Status", r["status"]);
 
-    //reset boolean to make sure there is no interference from the last call
+    // reset boolean to make sure there is no interference from the last call
     boolean = false;
 
     data.GetBool("VisibleAlarm", boolean);

Or run the build target format_check.

  1. Add an integration test for the new table. Take a look here for a recent example: https://github.com/osquery/osquery/pull/5539/files but ignore all of the Buck stuff.

@jjerger
Copy link
Contributor Author

jjerger commented Jun 1, 2020

Uh oh, I think i botched the rebase from your master (this feels familiar, thought I'd learned).

Perhaps I'm best nuking the current branch and opening a PR under a fresh one properly rebased?

@Smjert
Copy link
Member

Smjert commented Jun 2, 2020

Uh oh, I think i botched the rebase from your master (this feels familiar, thought I'd learned).

Perhaps I'm best nuking the current branch and opening a PR under a fresh one properly rebased?

You can push force, something like:

// Being checked out on the PR branch, rename it
git branch -M chassis_info-backup
// Switch to master and "recreate" the branch
git checkout master
git checkout -b chassis_info
// Might not be necessary, but tell the branch which remote to track (substitute origin with the PR remote)
git branch -u origin/chassis_info
// Get the top commit with the PR implementation from the old branch
git cherry-pick chassis_info-backup
// Push force the PR branch
git push --force

@jjerger
Copy link
Contributor Author

jjerger commented Jun 2, 2020

Ok after that mess of rebasing I think I have it current again and added an integration test. I haven't added one of those in ages, so please sanity check it to make sure I made the right assertions.

@Smjert
Copy link
Member

Smjert commented Jun 3, 2020

@jjerger You can verify the formatting of the code via cmake --build . --target format_check from the build folder (it doesn't require anything to be built, but the CMake configure has to have been run).

We also have cmake --build . --target format to actually format the code how we would like, though keep in mind that this is meant to be run before committing, which means that it doesn't work on already committed code.
Although you can go back in time via interactive rebase + reset soft to format and then recommit the commits that needed formatting.

EDIT: Check https://osquery.readthedocs.io/en/latest/development/building/ Formatting the code for more info, also being on Windows you would have to install C++ Clang tools for Windows, as stated in the Windows pre-requisites for building.

@jjerger
Copy link
Contributor Author

jjerger commented Jun 3, 2020

I set up a new Windows instance following those prereqs so it should have them all. I'll verify with that.

@jjerger
Copy link
Contributor Author

jjerger commented Jun 3, 2020

Oddly enough clang format was formatting in a way that caused it to fail check, so that's interesting.

I see Wix errors - is there a formatting command that needs to be done through Wix? I have no experience with that toolset and I didn't see much mention of it in the build doc (it's only used on Release build by the look of it?)

@jjerger
Copy link
Contributor Author

jjerger commented Jun 3, 2020

Actually, checking the outupt it looks like Wix is missing from the test container?

@theopolis
Copy link
Member

Heads up I added a quick-fix since the integration test code was not being built.

theopolis
theopolis previously approved these changes Jun 4, 2020
@jjerger
Copy link
Contributor Author

jjerger commented Jun 5, 2020

It seems to be failing on WmiRequest but I am not quite sure why.. I used the same logic as I had used in previous tables but chassis_info is returning false for wmiSystemReq.getStatus().ok() resulting in an empty result set.

This isn't being caught in the build process but surfacing in the table integration check. Am I missing something here?

@theopolis
Copy link
Member

Does the WMI query not work on a VM? If that is the case then the integration test should only apply the validation if there is a non-empty result set.

@jjerger
Copy link
Contributor Author

jjerger commented Jun 5, 2020

I suppose it depends on the hypervisor, since GCP instances do return some info, although almost nothing.

Maybe Azure doesn't? The part that got me thinking about this was The Windows Release Output indicating that the table didn't exist and that status.ok() was false. I figured this was referring to the query that built the table?

When I moved it to a physical desktop and rebuilt it, I saw the same behavior. No error during build, but if I check osqueryi, there is no chassis_info table at all. Win32_SystemEnclosure is in the Root\CIMv2 namespace so we shouldn't have to specify it, right?

@jjerger
Copy link
Contributor Author

jjerger commented Jun 9, 2020

Looks like LGTM timed out running tests - not sure if they all pass.

As it stands, let's hold off on merging too. I found an error with ChassisTypes that I'm addressing.

@jjerger
Copy link
Contributor Author

jjerger commented Jun 9, 2020

Related to my previous comment: I see that WmiResultItem has a way to retrieve an array of strings with GetVectorOfStrings, but is there a similar way to retrieve integers?

I'm having difficulty retrieving ChassisTypes as it is an array of UInt16 values, although I have not been able to find a device with multiple values contained within. Perhaps Surface Pros might have two with the detachable chassis? No idea.

@mike-myers-tob
Copy link
Member

Looks like LGTM timed out running tests - not sure if they all pass.

The LGTM test runner doesn't run long enough to compile osquery and all of its dependencies, so right now LGTM will always fail.

@theopolis theopolis merged commit d09ad2b into osquery:master Jun 10, 2020
@jjerger
Copy link
Contributor Author

jjerger commented Jun 10, 2020

Eek! I had not yet fixed an error with ChassisTypes. It'll run as is, but the value it's returning is less than helpful.

Want me to open a separate PR with the fix to that?

@directionless
Copy link
Member

Want me to open a separate PR with the fix to that?

Yes please!

aikuchin pushed a commit to aikuchin/osquery that referenced this pull request Jul 11, 2023
…0 to master

* commit 'eeee0fb0957f5af983f817c2e6f19c53108d9e09': (83 commits)
  Add additional changelog items (osquery#6523)
  Changelog for 4.4.0 (osquery#6492)
  build: Add Azure tables to specs CMakeLists (osquery#6507)
  CMake: Correct macOS framework linking (osquery#6522)
  tables: Only populate table cache with star-like selects (osquery#6513)
  CMake: Fix and cleanup compile flags (osquery#6521)
  docs: Add note to bump the Homebrew cask (osquery#6519)
  tests: Fix atom_packages, processes, rpm_packages flakiness (osquery#6518)
  bug: Do not use system proxy for AWS local authority (osquery#6512)
  packaging: updating docs on cpack usage to include Chocolatey (osquery#6022)
  bug: Fix typed_row table caching (osquery#6508)
  Implement event batching support for Windows tables (osquery#6280)
  http: Use sync resolve (osquery#6490)
  Add support for basic chassis information (osquery#5282)
  Only emit 'denylist' warning once (osquery#6493)
  docs: Remove references to brew in macOS install (osquery#6494)
  Fix for osquery#5890: Event Format Results and the Kafka Logger (osquery#6449)
  make apt_sources table parsing much more resilient (osquery#6482)
  Make file and hash container columns hidden (osquery#6486)
  Update documentation to use 'allow list' and 'deny list' diction (osquery#6489)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed Automated label: Pull Request author has signed the osquery CLA virtual tables Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants