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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

James-Pickett
Copy link
Contributor

@James-Pickett James-Pickett commented May 8, 2024

  • updates kolide svc functions to look for disable_device field in jsonRpc / gRPC responses and return a ErrDeviceDisabled if found
  • updates extension to check for ErrDeviceDisabled when it receives and error and perform uninstall if found

@James-Pickett James-Pickett changed the title device disable via public logs uninstall via device server May 8, 2024
@James-Pickett James-Pickett changed the title uninstall via device server uninstall via extension / jsonrpc May 9, 2024
Comment on lines +105 to 108
jsonRpcResponse: jsonRpcResponse{
DisableDevice: req.DisableDevice,
},
Message: req.Message,
Copy link
Contributor

Choose a reason for hiding this comment

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

Naive question -- why are the other things really obvious looking struct members, but this one is a nested thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is because the jsonRpc implementation is doing a standard json unmarshalling where as the grpc implementation is taking the auto-generated protobuf structpb.AgentApiResponse and converting it the struct type publishLogsResponse via manually setting the fields

we could also probably just marshall the protobuf to json then unmarshall it into the publishLogsResponse

Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm. Caveat, I'm not sure what correct is...

My hunch is that we should do the same thing for jsonrpc and grpc, but I'm not sure if we should improve the conversion or just go the manual route.

At some point, I think we should level up all the API surfaces via some kind of API specification, but that feels a bit out of scope for this.

@James-Pickett James-Pickett changed the title uninstall via extension / jsonrpc uninstall via extension / jsonrpc / grpc May 24, 2024
@James-Pickett James-Pickett marked this pull request as ready for review May 24, 2024 21:15
t.Parallel()

// set up JSON-RPC test server
jsonRpcServerResult := `{"disable_device": false}`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the service package became a little frankensteiny over the years. Mixing jsonRPC and gRPC implementations. I'm tempted to split them up and perhaps have a common types package. Not sure if it's worth the effort at this time since we're not really using the grpc portion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think go-kit has a recommendation for how to do this. It's core design is all about splitting up transport implementation from protocol definition.

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.


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

Choose a reason for hiding this comment

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

Should we return here? Falling through looks wrong

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

Choose a reason for hiding this comment

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

same -- should we return?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants