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

remove console users from local server request id #1581

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading