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

Just a bunch of debug logging for consoleuser.CurrentUids #1470

Closed
Closed
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
4 changes: 3 additions & 1 deletion ee/consoleuser/consoleuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package consoleuser
import (
"context"
"os/user"

"github.com/go-kit/kit/log"
)

func CurrentUsers(ctx context.Context) ([]*user.User, error) {
currentUids, err := CurrentUids(ctx)
currentUids, err := CurrentUids(ctx, log.NewNopLogger())
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion ee/consoleuser/consoleuser_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strconv"
"strings"

"github.com/go-kit/kit/log"
"github.com/kolide/launcher/pkg/allowedcmd"
)

Expand Down Expand Up @@ -90,7 +91,7 @@ const (
minConsoleUserUid = 501
)

func CurrentUids(ctx context.Context) ([]string, error) {
func CurrentUids(ctx context.Context, _ log.Logger) ([]string, error) {
cmd, err := allowedcmd.Scutil(ctx)
if err != nil {
return nil, fmt.Errorf("creating scutil command: %w", err)
Expand Down
17 changes: 16 additions & 1 deletion ee/consoleuser/consoleuser_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"fmt"
"strings"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/launcher/pkg/allowedcmd"
)

Expand All @@ -18,26 +20,34 @@ type listSessionsResult []struct {
Seat string `json:"seat"`
}

func CurrentUids(ctx context.Context) ([]string, error) {
func CurrentUids(ctx context.Context, logger log.Logger) ([]string, error) {
logger = log.With(logger, "method", "CurrentUids")

cmd, err := allowedcmd.Loginctl(ctx, "list-sessions", "--no-legend", "--no-pager", "--output=json")
if err != nil {
level.Error(logger).Log("msg", "creating loginctl command", "err", err)
return nil, fmt.Errorf("creating loginctl command: %w", err)
}
output, err := cmd.Output()
if err != nil {
level.Error(logger).Log("msg", "listing sessions", "err", err)
return nil, fmt.Errorf("loginctl list-sessions: %w", err)
}

level.Info(logger).Log("msg", "listed sessions", "output", string(output))

// unmarshall json output into listSessionsResult
var sessions listSessionsResult
if err := json.Unmarshal(output, &sessions); err != nil {
level.Error(logger).Log("msg", "loginctl list-sessions unmarshall json output", "err", err)
return nil, fmt.Errorf("loginctl list-sessions unmarshall json output: %w", err)
}

var uids []string
for _, s := range sessions {
// generally human users start at 1000 on linux
if s.UID < 1000 {
level.Info(logger).Log("msg", "user id under 1000", "uid", s.UID)
continue
}

Expand All @@ -47,14 +57,18 @@ func CurrentUids(ctx context.Context) ([]string, error) {
"--property=Active",
)
if err != nil {
level.Error(logger).Log("msg", "creating loginctl command", "err", err)
return nil, fmt.Errorf("creating loginctl command: %w", err)
}

output, err := cmd.Output()
if err != nil {
level.Error(logger).Log("msg", "showing session", "err", err, "session_id", s.Session)
return nil, fmt.Errorf("loginctl show-session (for sessionId %s): %w", s.Session, err)
}

level.Info(logger).Log("msg", "loginctl show-session output", "uid", s.UID, "session_id", s.Session, "output", string(output))

// to make remote session behave like local session and include systray icons on ubuntu 22.04
// had to create a ~/.xsessionrc file with the following content:
// export GNOME_SHELL_SESSION_MODE=ubuntu
Expand All @@ -65,6 +79,7 @@ func CurrentUids(ctx context.Context) ([]string, error) {
// local: remote=no
// rdp: remote=no
if strings.Contains(string(output), "Remote=no") && strings.Contains(string(output), "Active=yes") {
level.Info(logger).Log("msg", "adding user", "uid", s.UID)
uids = append(uids, fmt.Sprintf("%d", s.UID))
}
}
Expand Down
3 changes: 2 additions & 1 deletion ee/consoleuser/consoleuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"runtime"
"testing"

"github.com/go-kit/kit/log"
"github.com/stretchr/testify/assert"
)

func TestCurrentUids(t *testing.T) {
t.Parallel()

uids, err := CurrentUids(context.Background())
uids, err := CurrentUids(context.Background(), log.NewNopLogger())
assert.NoError(t, err)

// in the current CI environment (GitHub Actions) the linux runner
Expand Down
3 changes: 2 additions & 1 deletion ee/consoleuser/consoleuser_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"fmt"
"path/filepath"

"github.com/go-kit/kit/log"
"github.com/shirou/gopsutil/v3/process"
)

func CurrentUids(ctx context.Context) ([]string, error) {
func CurrentUids(ctx context.Context, _ log.Logger) ([]string, error) {
explorerProcs, err := explorerProcesses(ctx)
if err != nil {
return nil, fmt.Errorf("getting explorer processes: %w", err)
Expand Down
14 changes: 8 additions & 6 deletions ee/desktop/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,13 @@ func (r *DesktopUsersProcessesRunner) writeDefaultMenuTemplateFile() {
}

func (r *DesktopUsersProcessesRunner) runConsoleUserDesktop() error {
if !r.processSpawningEnabled {
// Desktop is disabled, kill any existing desktop user processes
r.killDesktopProcesses()
return nil
}
/*
if !r.processSpawningEnabled {
// Desktop is disabled, kill any existing desktop user processes
r.killDesktopProcesses()
return nil
}
*/

executablePath, err := r.determineExecutablePath()
if err != nil {
Expand All @@ -499,7 +501,7 @@ func (r *DesktopUsersProcessesRunner) runConsoleUserDesktop() error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

consoleUsers, err := consoleuser.CurrentUids(ctx)
consoleUsers, err := consoleuser.CurrentUids(ctx, r.logger)
if err != nil {
return fmt.Errorf("getting console users: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion ee/localserver/request-id.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"runtime"
"time"

"github.com/go-kit/kit/log"
"github.com/kolide/kit/ulid"
"github.com/kolide/launcher/ee/consoleuser"
"github.com/kolide/launcher/pkg/backoff"
Expand Down Expand Up @@ -113,7 +114,7 @@ func consoleUsers() ([]*user.User, error) {
var users []*user.User

return users, backoff.WaitFor(func() error {
uids, err := consoleuser.CurrentUids(context)
uids, err := consoleuser.CurrentUids(context, log.NewNopLogger())
if err != nil {
return err
}
Expand Down
Loading