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

Generate the enrollment details on launcher startup #2045

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl
flagController := flags.NewFlagController(slogger, stores[storage.AgentFlagsStore], fcOpts...)
k := knapsack.New(stores, flagController, db, multiSlogger, systemMultiSlogger)

if err := osquery.CollectAndSetEnrollmentDetails(ctx, k, 5*time.Second, 5*time.Second); err != nil {
slogger.Log(ctx, slog.LevelError,
"setting enrollment details",
"err", err,
)
}

// Generate a new run ID
newRunID := k.GetRunID()

Expand Down
34 changes: 34 additions & 0 deletions ee/agent/knapsack/knapsack.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ import (
"github.com/kolide/launcher/ee/agent/types"
"github.com/kolide/launcher/ee/tuf"
"github.com/kolide/launcher/pkg/log/multislogger"

"go.etcd.io/bbolt"
)

// Package-level runID variable
var runID string

// Package-level enrollmentDetails variable
var enrollmentDetails *types.EnrollmentDetails

// type alias Flags, so that we can embed it inside knapsack, as `flags` and not `Flags`
type flags types.Flags

Expand Down Expand Up @@ -239,3 +243,33 @@ func (k *knapsack) CurrentEnrollmentStatus() (types.EnrollmentStatus, error) {

return types.Enrolled, nil
}

func (k *knapsack) SetEnrollmentDetails(details types.EnrollmentDetails) error {
if enrollmentDetails == nil {
newDetails := details
enrollmentDetails = &newDetails
k.Slogger().Log(context.Background(), slog.LevelDebug,
"initializing enrollment details",
"details", fmt.Sprintf("%+v", enrollmentDetails),
)
return nil
}

current := *enrollmentDetails

k.Slogger().Log(context.Background(), slog.LevelDebug,
"updating enrollment details",
"old_details", fmt.Sprintf("%+v", enrollmentDetails),
"new_details", fmt.Sprintf("%+v", current),
)
enrollmentDetails = &current

return nil
}

func (k *knapsack) GetEnrollmentDetails() (types.EnrollmentDetails, error) {
if enrollmentDetails == nil {
return types.EnrollmentDetails{}, nil
}
return *enrollmentDetails, nil
}
32 changes: 32 additions & 0 deletions ee/agent/types/enrollment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package types

type EnrollmentStatus string

const (
NoEnrollmentKey EnrollmentStatus = "no_enrollment_key"
Unenrolled EnrollmentStatus = "unenrolled"
Enrolled EnrollmentStatus = "enrolled"
Unknown EnrollmentStatus = "unknown"
)

// EnrollmentDetails is the set of details that are collected from osqueryd
// that are sent to the Kolide server during enrollment.
type EnrollmentDetails struct {
OSVersion string `json:"os_version"`
OSBuildID string `json:"os_build_id"`
OSPlatform string `json:"os_platform"`
Hostname string `json:"hostname"`
HardwareVendor string `json:"hardware_vendor"`
HardwareModel string `json:"hardware_model"`
HardwareSerial string `json:"hardware_serial"`
OsqueryVersion string `json:"osquery_version"`
LauncherHardwareKey string `json:"launcher_hardware_key"`
LauncherHardwareKeySource string `json:"launcher_hardware_key_source"`
LauncherLocalKey string `json:"launcher_local_key"`
LauncherVersion string `json:"launcher_version"`
OSName string `json:"os_name"`
OSPlatformLike string `json:"os_platform_like"`
GOOS string `json:"goos"`
GOARCH string `json:"goarch"`
HardwareUUID string `json:"hardware_uuid"`
}
4 changes: 4 additions & 0 deletions ee/agent/types/knapsack.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ type Knapsack interface {
CurrentEnrollmentStatus() (EnrollmentStatus, error)
// GetRunID returns the current launcher run ID
GetRunID() string
// GetEnrollmentDetails returns the enrollment details for the launcher installation
GetEnrollmentDetails() (EnrollmentDetails, error)
// SetEnrollmentDetails sets the enrollment details for the launcher installation
SetEnrollmentDetails(details EnrollmentDetails) error
}
90 changes: 0 additions & 90 deletions ee/agent/types/mocks/flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading