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

uninstall via extension / jsonrpc / grpc #1712

Merged
61 changes: 48 additions & 13 deletions pkg/osquery/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/kolide/launcher/ee/agent"
"github.com/kolide/launcher/ee/agent/startupsettings"
"github.com/kolide/launcher/ee/agent/types"
"github.com/kolide/launcher/ee/uninstall"
"github.com/kolide/launcher/pkg/backoff"
"github.com/kolide/launcher/pkg/osquery/runtime/history"
"github.com/kolide/launcher/pkg/service"
Expand Down Expand Up @@ -449,13 +450,20 @@ func (e *Extension) Enroll(ctx context.Context) (string, bool, error) {
// If no cached node key, enroll for new node key
// note that we set invalid two ways. Via the return, _or_ via isNodeInvaliderr
keyString, invalid, err := e.serviceClient.RequestEnrollment(ctx, enrollSecret, identifier, enrollDetails)
if isNodeInvalidErr(err) {

switch {
case errors.Is(err, service.ErrDeviceDisabled{}):
Copy link
Contributor

Choose a reason for hiding this comment

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

hahahaha. This really points at how this method signature was limiting. This feels like a reasonable workaround, but definitely points to needing to refresh this code.

uninstall.Uninstall(ctx, e.knapsack, true)
James-Pickett marked this conversation as resolved.
Show resolved Hide resolved

case isNodeInvalidErr(err):
invalid = true
} else if err != nil {
err := fmt.Errorf("transport error in enrollment: %w", err)
traces.SetError(span, err)
return "", true, err

case err != nil:
return "", true, fmt.Errorf("transport error getting queries: %w", err)

default: // pass through no error
}

if invalid {
if err == nil {
err = errors.New("no further error")
Expand Down Expand Up @@ -554,10 +562,17 @@ var reenrollmentInvalidErr = errors.New("enrollment invalid, reenrollment invali
// Helper to allow for a single attempt at re-enrollment
func (e *Extension) generateConfigsWithReenroll(ctx context.Context, reenroll bool) (string, error) {
config, invalid, err := e.serviceClient.RequestConfig(ctx, e.NodeKey)
if isNodeInvalidErr(err) {
switch {
case errors.Is(err, service.ErrDeviceDisabled{}):
uninstall.Uninstall(ctx, e.knapsack, true)
James-Pickett marked this conversation as resolved.
Show resolved Hide resolved

case isNodeInvalidErr(err):
invalid = true
} else if err != nil {
return "", fmt.Errorf("transport error retrieving config: %w", err)

case err != nil:
return "", fmt.Errorf("transport error getting queries: %w", err)

default: // pass through no error
}

if invalid {
Expand Down Expand Up @@ -791,6 +806,11 @@ func (e *Extension) writeBufferedLogsForType(typ logger.LogType) error {
// Helper to allow for a single attempt at re-enrollment
func (e *Extension) writeLogsWithReenroll(ctx context.Context, typ logger.LogType, logs []string, reenroll bool) error {
_, _, invalid, err := e.serviceClient.PublishLogs(ctx, e.NodeKey, typ, logs)

if errors.Is(err, service.ErrDeviceDisabled{}) {
uninstall.Uninstall(ctx, e.knapsack, true)
}

invalid = invalid || isNodeInvalidErr(err)
if !invalid && err == nil {
// publication was successful- update logPublicationState and move on
Expand Down Expand Up @@ -899,10 +919,18 @@ func (e *Extension) getQueriesWithReenroll(ctx context.Context, reenroll bool) (

// Note that we set invalid two ways -- in the return, and via isNodeinvaliderr
queries, invalid, err := e.serviceClient.RequestQueries(ctx, e.NodeKey)
if isNodeInvalidErr(err) {

switch {
case errors.Is(err, service.ErrDeviceDisabled{}):
uninstall.Uninstall(ctx, e.knapsack, true)

case isNodeInvalidErr(err):
invalid = true
} else if err != nil {

case err != nil:
return nil, fmt.Errorf("transport error getting queries: %w", err)

default: // pass through no error
}

if invalid {
Expand Down Expand Up @@ -945,10 +973,17 @@ func (e *Extension) writeResultsWithReenroll(ctx context.Context, results []dist
defer span.End()

_, _, invalid, err := e.serviceClient.PublishResults(ctx, e.NodeKey, results)
if isNodeInvalidErr(err) {
switch {
case errors.Is(err, service.ErrDeviceDisabled{}):
uninstall.Uninstall(ctx, e.knapsack, true)

case isNodeInvalidErr(err):
invalid = true
} else if err != nil {
return fmt.Errorf("transport error writing results: %w", err)

case err != nil:
return fmt.Errorf("transport error getting queries: %w", err)

default: // pass through no error
}

if invalid {
Expand Down
2 changes: 1 addition & 1 deletion pkg/pb/launcher/launcher.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package launcher

//go:generate protoc --go_out=plugins=grpc:. launcher.proto
//go:generate protoc --go-grpc_out=. --go_out=. launcher.proto
Loading
Loading