Fix no such table errors for mdm & munki_info in vanilla osquery macOS hosts (#6170)

* Add discovery queries for mdm and munki_info

* Add changes file

* Amend discovery table tests
This commit is contained in:
Lucas Manuel Rodriguez 2022-06-13 08:52:33 -03:00 committed by GitHub
parent f3212f4537
commit 515454e47f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View file

@ -0,0 +1 @@
* Fixed `no such table` errors for `mdm` and `munki_info` for vanilla osquery macOS hosts.

View file

@ -413,6 +413,8 @@ func verifyDiscovery(t *testing.T, queries, discovery map[string]string) {
discoveryUsed := map[string]struct{}{
hostDetailQueryPrefix + "google_chrome_profiles": {},
hostDetailQueryPrefix + "orbit_info": {},
hostDetailQueryPrefix + "mdm": {},
hostDetailQueryPrefix + "munki_info": {},
}
for name := range queries {
require.NotEmpty(t, discovery[name])

View file

@ -48,10 +48,12 @@ func (q *DetailQuery) RunsForPlatform(platform string) bool {
return false
}
// detailQueries defines the detail queries that should be run on the host, as
// hostDetailQueries defines the detail queries that should be run on the host, as
// well as how the results of those queries should be ingested into the
// fleet.Host data model. This map should not be modified at runtime.
var detailQueries = map[string]DetailQuery{
// fleet.Host data model (via IngestFunc).
//
// This map should not be modified at runtime.
var hostDetailQueries = map[string]DetailQuery{
"network_interface": {
Query: `select ia.address, id.mac, id.interface
from interface_details id join interface_addresses ia
@ -306,15 +308,25 @@ FROM logical_drives WHERE file_system = 'NTFS' LIMIT 1;`,
Platforms: []string{"windows"},
IngestFunc: ingestDiskSpace,
},
}
// extraDetailQueries defines extra detail queries that should be run on the host, as
// well as how the results of those queries should be ingested into the hosts related tables
// (via DirectIngestFunc).
//
// This map should not be modified at runtime.
var extraDetailQueries = map[string]DetailQuery{
"mdm": {
Query: `select enrolled, server_url, installed_from_dep from mdm;`,
DirectIngestFunc: directIngestMDM,
Platforms: []string{"darwin"},
Discovery: discoveryTable("mdm"),
},
"munki_info": {
Query: `select version from munki_info;`,
DirectIngestFunc: directIngestMunkiInfo,
Platforms: []string{"darwin"},
Discovery: discoveryTable("munki_info"),
},
"google_chrome_profiles": {
Query: `SELECT email FROM google_chrome_profiles WHERE NOT ephemeral AND email <> ''`,
@ -851,7 +863,10 @@ func directIngestMunkiInfo(ctx context.Context, logger log.Logger, host *fleet.H
func GetDetailQueries(ac *fleet.AppConfig, fleetConfig config.FleetConfig) map[string]DetailQuery {
generatedMap := make(map[string]DetailQuery)
for key, query := range detailQueries {
for key, query := range hostDetailQueries {
generatedMap[key] = query
}
for key, query := range extraDetailQueries {
generatedMap[key] = query
}