Skip to content

Commit

Permalink
choose presence detection reason based on GOOS, enable windows (#1959)
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett authored Nov 18, 2024
1 parent b97f6a9 commit 8a91d13
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ee/localserver/krypto-ec-middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const (
kolideKryptoHeaderKey = "X-Kolide-Krypto"
kolideSessionIdHeaderKey = "X-Kolide-Session"
kolidePresenceDetectionIntervalHeaderKey = "X-Kolide-Presence-Detection-Interval"
kolidePresenceDetectionReasonHeaderKey = "X-Kolide-Presence-Detection-Reason"
kolidePresenceDetectionReasonMacosHeaderKey = "X-Kolide-Presence-Detection-Reason-Macos"
kolidePresenceDetectionReasonWindowsHeaderKey = "X-Kolide-Presence-Detection-Reason-Windows"
kolideDurationSinceLastPresenceDetectionHeaderKey = "X-Kolide-Duration-Since-Last-Presence-Detection"
kolideOsHeaderKey = "X-Kolide-Os"
kolideArchHeaderKey = "X-Kolide-Arch"
Expand Down
4 changes: 2 additions & 2 deletions ee/localserver/krypto-ec-middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ func TestKryptoEcMiddleware(t *testing.T) {
require.Equal(t, runtime.GOOS, responseHeaders[kolideOsHeaderKey][0])

// check that the presence detection interval is present
if runtime.GOOS == "darwin" {
if runtime.GOOS != "linux" {
require.Equal(t, (0 * time.Second).String(), responseHeaders[kolideDurationSinceLastPresenceDetectionHeaderKey][0])
return
}

// not darwin
// linux
require.Equal(t, presencedetection.DetectionFailedDurationValue.String(), responseHeaders[kolideDurationSinceLastPresenceDetectionHeaderKey][0])
})
}
Expand Down
18 changes: 12 additions & 6 deletions ee/localserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (ls *localServer) presenceDetectionHandler(next http.Handler) http.Handler
}

// presence detection is only supported on macos currently
if runtime.GOOS != "darwin" {
if runtime.GOOS == "linux" {
w.Header().Add(kolideDurationSinceLastPresenceDetectionHeaderKey, presencedetection.DetectionFailedDurationValue.String())
next.ServeHTTP(w, r)
return
Expand All @@ -442,11 +442,17 @@ func (ls *localServer) presenceDetectionHandler(next http.Handler) http.Handler
return
}

// set a default reason, on macos the popup will look like "Kolide is trying to authenticate."
reason := "authenticate"
reasonHeader := r.Header.Get(kolidePresenceDetectionReasonHeaderKey)
if reasonHeader != "" {
reason = reasonHeader
reason := r.Header.Get(kolidePresenceDetectionReasonMacosHeaderKey)
if runtime.GOOS == "windows" {
reason = r.Header.Get(kolidePresenceDetectionReasonWindowsHeaderKey)
}

if reason == "" {
reason = "authenticate"
ls.slogger.Log(r.Context(), slog.LevelInfo,
"no reason found for presence detection, using default",
"reason", reason,
)
}

durationSinceLastDetection, err := ls.presenceDetector.DetectPresence(reason, detectionIntervalDuration)
Expand Down

0 comments on commit 8a91d13

Please sign in to comment.