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

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

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

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
"unsafe"
)

func Detect(reason string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For Windows, I think we're going to want something like

Suggested change
func Detect(reason string) (bool, error) {
func Detect(credentialName string, reason string) (bool, string, error) {

where the string returned is the new credential name, if the credential didn't exist yet and had to be provisioned. I think we'd also want knapsack/store access in this package, so that we can store the credential name.

I can add both of those changes in a follow-up PR, but wanted to mention it in case it affected anything about what you're doing in this PR!

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

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?

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.

4 participants