From c6d2c420869673a0bcebc15f5b1966282e4d085c Mon Sep 17 00:00:00 2001 From: james pickett Date: Mon, 5 Feb 2024 14:12:22 -0800 Subject: [PATCH] remove console users from local server request id --- ee/localserver/request-id.go | 54 ++----------------------------- ee/localserver/request-id_test.go | 11 ------- 2 files changed, 2 insertions(+), 63 deletions(-) diff --git a/ee/localserver/request-id.go b/ee/localserver/request-id.go index c5ce8b292..8d1beb77e 100644 --- a/ee/localserver/request-id.go +++ b/ee/localserver/request-id.go @@ -1,19 +1,14 @@ package localserver import ( - "context" "encoding/json" "errors" "fmt" "log/slog" "net/http" - "os/user" - "runtime" "time" "github.com/kolide/kit/ulid" - "github.com/kolide/launcher/ee/consoleuser" - "github.com/kolide/launcher/pkg/backoff" "github.com/kolide/launcher/pkg/traces" ) @@ -26,9 +21,8 @@ type identifiers struct { type requestIdsResponse struct { RequestId string identifiers - Nonce string - Timestamp time.Time - ConsoleUsers []*user.User + Nonce string + Timestamp time.Time } const ( @@ -78,19 +72,6 @@ func (ls *localServer) requestIdHandlerFunc(w http.ResponseWriter, r *http.Reque } response.identifiers = ls.identifiers - consoleUsers, err := consoleUsers() - if err != nil { - traces.SetError(span, err) - ls.slogger.Log(r.Context(), slog.LevelError, - "getting console users", - "err", err, - ) - - response.ConsoleUsers = []*user.User{} - } else { - response.ConsoleUsers = consoleUsers - } - jsonBytes, err := json.Marshal(response) if err != nil { traces.SetError(span, err) @@ -104,34 +85,3 @@ func (ls *localServer) requestIdHandlerFunc(w http.ResponseWriter, r *http.Reque w.Write(jsonBytes) } - -func consoleUsers() ([]*user.User, error) { - const maxDuration = 1 * time.Second - context, cancel := context.WithTimeout(context.Background(), maxDuration) - defer cancel() - - var users []*user.User - - return users, backoff.WaitFor(func() error { - uids, err := consoleuser.CurrentUids(context) - if err != nil { - return err - } - - for _, uid := range uids { - var err error - var u *user.User - if runtime.GOOS == "windows" { - u, err = user.Lookup(uid) - } else { - u, err = user.LookupId(uid) - } - if err != nil { - return err - } - - users = append(users, u) - } - return nil - }, maxDuration, 250*time.Millisecond) -} diff --git a/ee/localserver/request-id_test.go b/ee/localserver/request-id_test.go index fac867e9b..57c76a162 100644 --- a/ee/localserver/request-id_test.go +++ b/ee/localserver/request-id_test.go @@ -7,8 +7,6 @@ import ( "log/slog" "net/http" "net/http/httptest" - "os" - "runtime" "strings" "testing" @@ -55,15 +53,6 @@ func Test_localServer_requestIdHandler(t *testing.T) { // convert the response to a struct var response requestIdsResponse require.NoError(t, json.Unmarshal(rr.Body.Bytes(), &response)) - - // in the current CI environment (GitHub Actions) the linux runner - // does not have a console user, so we expect an empty list - if os.Getenv("CI") == "true" && runtime.GOOS == "linux" { - assert.Empty(t, response.ConsoleUsers) - return - } - - assert.GreaterOrEqual(t, len(response.ConsoleUsers), 1, "should have at least one console user") } func testServer(t *testing.T, k types.Knapsack) *localServer {