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

macos presence detection #1867

Merged

Conversation

James-Pickett
Copy link
Contributor

@James-Pickett James-Pickett commented Sep 13, 2024

This PR adds a presence detection endpoint to the DesktopUserServer which will call the OS specific implementation of presence detection and return the result. The call to DesktopUserServer is made by middleware in the LocalServer. The LocalServer looks for values in cmdRequest (krypto) headers to determine when it needs to detect presence.

More docs here: https://github.com/kolide/monorepo/pull/240

relates to #1838

Copy link
Contributor

@RebeccaMahany RebeccaMahany left a comment

Choose a reason for hiding this comment

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

Nice!!

@@ -182,9 +184,10 @@ func runDesktop(_ *multislogger.MultiSlogger, args []string) error {
}
}()

// block until a send on showDesktopChan
<-showDesktopChan
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh, this is tidy!

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 was torn between this route and just passing a flag when we spin up desktop. We are able to show the desktop on demand, but as far as I can tell, there is no way to hide the desktop on demand. When you tell systray to shutdown, it exits the program completely. So if we ever want to hide it, we have to kill the process and let a new one spin up hidden.

I chose this route because I think it's rare that we would turn off the desktop and I don't want to be starting / killing processes on a first install where a user is trying auth for the first time.

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 it's rare that we would turn off the desktop

I agree, I think that's a reasonable assumption -- this route makes sense to me

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 users will, but I think your reasoning is sound.

ee/desktop/user/server/server.go Outdated Show resolved Hide resolved
ee/presencedetection/presencedetection.go Outdated Show resolved Hide resolved
ee/desktop/runner/runner.go Outdated Show resolved Hide resolved
ee/desktop/runner/runner.go Outdated Show resolved Hide resolved
ee/desktop/runner/runner.go Show resolved Hide resolved
ee/localserver/server.go Outdated Show resolved Hide resolved
@James-Pickett James-Pickett changed the title first pass poc at macos presence detection macos presence detection Sep 23, 2024
Copy link
Contributor

@zackattack01 zackattack01 left a comment

Choose a reason for hiding this comment

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

🔥

@James-Pickett James-Pickett marked this pull request as ready for review September 24, 2024 20:29
Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

love it

ee/localserver/server.go Outdated Show resolved Hide resolved
@@ -182,9 +184,10 @@ func runDesktop(_ *multislogger.MultiSlogger, args []string) error {
}
}()

// block until a send on showDesktopChan
<-showDesktopChan
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 users will, but I think your reasoning is sound.

ee/desktop/user/client/client.go Show resolved Hide resolved
ee/presencedetection/presencedetection.go Outdated Show resolved Hide resolved
ee/presencedetection/presencedetection.go Outdated Show resolved Hide resolved
const DetectionFailedDurationValue = -1 * time.Second

type PresenceDetector struct {
lastDetectionUTC time.Time
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is time.Time maybe drop the UTC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will drop it, but we still want UTC instead of local time I'm assuming

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally it's better to keep things in UTC, yes. And when we emit to k2, we should use one of the standard formats, or just integer unix time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, we don't emit the time for this to K2, just the go style duration since last detection like 0s or 1m30s

ee/presencedetection/presencedetection_darwin_test.go Outdated Show resolved Hide resolved
@@ -334,6 +344,14 @@ func (e *kryptoEcMiddleware) Wrap(next http.Handler) http.Handler {

w.Header().Add(kolideKryptoHeaderKey, kolideKryptoEccHeader20230130Value)

for k, v := range bhr.Header() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These headers are outside the krypto box, is that okay?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better if they were signed, but also not fatal. I thought if we put them into the CmdReq they'd be inside?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The headers of the request are inside the CmdReq (in krypto box). We don't have a mechanism currently to add headers from the response to the krypto box. Currently we just grab the body from the response and put it in the krypto box. We could come up with some kind of base response that we imbed in each of the local server responses.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused. We have too many layers

I think it's important for the response from launcher to k2, to be in the box. Otherwise it's a bit too trivial to slap whatever you want in flight.

Copy link
Contributor

Choose a reason for hiding this comment

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

But I'm not sure I'm concerned about what's happening between localserver and the desktop.

@@ -334,6 +344,14 @@ func (e *kryptoEcMiddleware) Wrap(next http.Handler) http.Handler {

w.Header().Add(kolideKryptoHeaderKey, kolideKryptoEccHeader20230130Value)

for k, v := range bhr.Header() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to blindly copy all headers or cherry pick?

directionless
directionless previously approved these changes Oct 1, 2024
Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

I'm game to try! wooo!

ee/localserver/krypto-ec-middleware.go Outdated Show resolved Hide resolved
ee/localserver/krypto-ec-middleware.go Show resolved Hide resolved
directionless
directionless previously approved these changes Oct 1, 2024
RebeccaMahany
RebeccaMahany previously approved these changes Oct 1, 2024
Copy link
Contributor

@RebeccaMahany RebeccaMahany left a comment

Choose a reason for hiding this comment

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

A couple very small comments -- feel free to ignore them or punt to another PR. LGTM!

ee/desktop/user/server/server.go Outdated Show resolved Hide resolved
ee/localserver/server.go Outdated Show resolved Hide resolved
ee/presencedetection/auth.m Outdated Show resolved Hide resolved
@James-Pickett James-Pickett added this pull request to the merge queue Oct 2, 2024
Merged via the queue into kolide:main with commit a6ba352 Oct 2, 2024
29 checks passed
@James-Pickett James-Pickett deleted the james/presence-detection-macos branch October 2, 2024 15:07
@RebeccaMahany RebeccaMahany added the features-improvements Features and Improvements label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
features-improvements Features and Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants