Skip to content

Commit

Permalink
remove console users from local server request id (#1581)
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett authored Feb 6, 2024
1 parent cc3f2e8 commit a85f44d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 63 deletions.
54 changes: 2 additions & 52 deletions ee/localserver/request-id.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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 (
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
11 changes: 0 additions & 11 deletions ee/localserver/request-id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"log/slog"
"net/http"
"net/http/httptest"
"os"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a85f44d

Please sign in to comment.