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 device connection #4049

Merged
merged 2 commits into from
May 23, 2024
Merged

⭐️ Add device connection #4049

merged 2 commits into from
May 23, 2024

Conversation

preslavgerchev
Copy link
Contributor

This PR adds the initial version of the device connection. It's currently only supported on linux.

To run a best-effort (guess the device) scan:

cnquery scan device

To specify the actual device you want:

cnquery scan device --device-name /dev/sda

To specify a device by its LUN (specifically useful for azure vms):

cnquery scan device --lun 1

The connection also supports injecting platform-ids:

cnquery scan device --lun 1 --platform-ids 1,2,3


import "go.mondoo.com/cnquery/v11/providers/os/connection/device/shared"

type DeviceManager interface {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can change this interface in the future to make this work better with mac/windows if needed

@@ -26,12 +26,12 @@ type VolumeMounter struct {
// where we tell AWS to attach the volume; it doesn't necessarily get attached there, but we have to reference this same location when detaching
VolumeAttachmentLoc string
opts map[string]string
cmdRunner *LocalCommandRunner
CmdRunner *LocalCommandRunner
}

func NewVolumeMounter(shell []string) *VolumeMounter {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can move this entirely to device/linux once we migrate the snapshot connections (AWS, Azure, GCP)

}
if runtime.GOOS == "windows" {
// shell = []string{"powershell", "-c"}
return nil, errors.New("device manager not implemented for windows")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding support for windows should be as simple as implementing the device manager and then ensuring it gets created here

Copy link
Member

Choose a reason for hiding this comment

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

nice preparation

Copy link
Contributor

github-actions bot commented May 22, 2024

Test Results

3 002 tests  +6   3 001 ✅ +6   1m 22s ⏱️ -13s
  332 suites +3       1 💤 ±0 
   23 files   ±0       0 ❌ ±0 

Results for commit e1ad90e. ± Comparison against base commit 9ba0338.

♻️ This comment has been updated with latest results.

@preslavgerchev preslavgerchev requested a review from chris-rock May 22, 2024 08:30
@chris-rock chris-rock requested a review from vjeffrey May 22, 2024 22:21
Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Thank you @preslavgerchev

}
if runtime.GOOS == "windows" {
// shell = []string{"powershell", "-c"}
return nil, errors.New("device manager not implemented for windows")
Copy link
Member

Choose a reason for hiding this comment

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

nice preparation

}
log.Debug().Str("manager", manager.Name()).Msg("device manager created")

mi, err := manager.IdentifyBlock(conf.Options)
Copy link
Member

Choose a reason for hiding this comment

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

Should we call this function IdentifyBlockDevice?

Copy link
Member

Choose a reason for hiding this comment

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

Going forward we should expect that this returns a list of block devices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great idea, adjusted, the code now returns a list. the connection stills works with a single device but we can adjust this when needed.

providers/os/connection/device/device_connection.go Outdated Show resolved Hide resolved
Copy link
Contributor

@vjeffrey vjeffrey left a comment

Choose a reason for hiding this comment

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

👍 thank you!!

@preslavgerchev preslavgerchev merged commit d21b14a into main May 23, 2024
15 checks passed
@preslavgerchev preslavgerchev deleted the preslav/device-conn branch May 23, 2024 07:55
@github-actions github-actions bot locked and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants