From 8a91d139b5120615d77207f73ea86e8eaebe4a04 Mon Sep 17 00:00:00 2001 From: James Pickett Date: Mon, 18 Nov 2024 07:54:48 -0800 Subject: [PATCH] choose presence detection reason based on GOOS, enable windows (#1959) --- ee/localserver/krypto-ec-middleware.go | 3 ++- ee/localserver/krypto-ec-middleware_test.go | 4 ++-- ee/localserver/server.go | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ee/localserver/krypto-ec-middleware.go b/ee/localserver/krypto-ec-middleware.go index 8ae5fcde1..ff943cab2 100644 --- a/ee/localserver/krypto-ec-middleware.go +++ b/ee/localserver/krypto-ec-middleware.go @@ -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" diff --git a/ee/localserver/krypto-ec-middleware_test.go b/ee/localserver/krypto-ec-middleware_test.go index d2605b50c..51b8977a9 100644 --- a/ee/localserver/krypto-ec-middleware_test.go +++ b/ee/localserver/krypto-ec-middleware_test.go @@ -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]) }) } diff --git a/ee/localserver/server.go b/ee/localserver/server.go index 8bb6b228a..a606e4df2 100644 --- a/ee/localserver/server.go +++ b/ee/localserver/server.go @@ -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 @@ -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)