-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧹 support sysinfo without providers (#2969)
* 🧹 support sysinfo without providers Normally we require to download and install the OS provider when we want to gather the OS info. This is now no longer necessary. Instead we grab a few very isolated libraries from the OS provider itself and embed them into the runtime. This yielded no significant increase in the runtime (500kb). While we want to further decrease this size over time, it is important to support scanning other provider targets without requiring the OS provider to be pulled. Signed-off-by: Dominik Richter <[email protected]> * 🧹 decouple os connection type constant * 🧹 extract os filesystem connection into submodule Signed-off-by: Dominik Richter <[email protected]> --------- Signed-off-by: Dominik Richter <[email protected]>
- Loading branch information
Showing
32 changed files
with
177 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package sysinfo | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/rs/zerolog/log" | ||
|
||
"go.mondoo.com/cnquery/v9" | ||
"go.mondoo.com/cnquery/v9/cli/execruntime" | ||
"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" | ||
"go.mondoo.com/cnquery/v9/providers/os/connection/local" | ||
"go.mondoo.com/cnquery/v9/providers/os/detector" | ||
"go.mondoo.com/cnquery/v9/providers/os/id" | ||
"go.mondoo.com/cnquery/v9/providers/os/id/hostname" | ||
"go.mondoo.com/cnquery/v9/providers/os/resources/networkinterface" | ||
) | ||
|
||
type SystemInfo struct { | ||
Version string `json:"version,omitempty"` | ||
Build string `json:"build,omitempty"` | ||
Platform *inventory.Platform `json:"platform,omitempty"` | ||
IP string `json:"ip,omitempty"` | ||
Hostname string `json:"platform_hostname,omitempty"` | ||
Labels map[string]string `json:"labels,omitempty"` | ||
PlatformId string `json:"platform_id,omitempty"` | ||
} | ||
|
||
func Get() (*SystemInfo, error) { | ||
log.Debug().Msg("Gathering system information") | ||
|
||
sysInfo := &SystemInfo{ | ||
Version: cnquery.GetVersion(), | ||
Build: cnquery.GetBuild(), | ||
} | ||
|
||
asset := inventory.Asset{ | ||
Connections: []*inventory.Config{{ | ||
Type: "local", | ||
Discover: &inventory.Discovery{Targets: []string{"none"}}, | ||
}}, | ||
} | ||
|
||
conn := local.NewConnection(0, &inventory.Config{ | ||
Type: "local", | ||
}, &asset) | ||
|
||
fingerprint, err := id.IdentifyPlatform(conn, asset.Platform, asset.IdDetector) | ||
if err == nil { | ||
if len(fingerprint.PlatformIDs) > 0 { | ||
sysInfo.PlatformId = fingerprint.PlatformIDs[0] | ||
} | ||
} | ||
|
||
var ok bool | ||
sysInfo.Platform, ok = detector.DetectOS(conn) | ||
if !ok { | ||
return nil, errors.New("failed to detect the OS") | ||
} | ||
|
||
sysInfo.Hostname, _ = hostname.Hostname(conn, sysInfo.Platform) | ||
|
||
// determine ip address | ||
ipAddr, err := networkinterface.GetOutboundIP() | ||
if err == nil { | ||
sysInfo.IP = ipAddr.String() | ||
} | ||
|
||
// detect the execution runtime | ||
execEnv := execruntime.Detect() | ||
sysInfo.Labels = map[string]string{ | ||
"environment": execEnv.Id, | ||
} | ||
|
||
return sysInfo, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,4 @@ func init() { | |
// }, | ||
// Config: &osconf.Config, | ||
// } | ||
|
||
} |
Oops, something went wrong.