Files
teleport/lib/auth/linuxdesktop/linuxdesktopv1/desktop_test.go
T
a2e3c53e42 [v18] Add Linux desktop support (#68401)
* Add LinuxDesktop protos and generated code (#62971)

* Add LinuxDesktop gRPC and backend (#62974)

* Add LinuxDesktop gRPC and backend

* Remove CloneResource

* Review comments

* Fix logins

* Update lib/auth/linuxdesktop/linuxdesktopv1/service.go

Co-authored-by: Zac Bergquist <[email protected]>

* Fix role

---------

Co-authored-by: Zac Bergquist <[email protected]>

* Add LinuxDesktop resource to unified resources (#63101)

* Add LinuxDesktop gRPC and backend

* Add LinuxDesktop resource to unified resources

* Remove CloneResource

* Review comments

* Fix logins

* Review comment

* Add ClonableResourceWithLabels

* Fix missing CloneResource

* Update lib/auth/linuxdesktop/linuxdesktopv1/service.go

Co-authored-by: Zac Bergquist <[email protected]>

* Fix role

* Update lib/auth/auth_with_roles.go

Co-authored-by: Zac Bergquist <[email protected]>

* Update lib/web/ui/server.go

Co-authored-by: Zac Bergquist <[email protected]>

* Fix compilation

* e

* skip gogoproto

* e

* fix test

* Update api/client/proto/linuxdesktop.go

Co-authored-by: Zac Bergquist <[email protected]>

---------

Co-authored-by: Zac Bergquist <[email protected]>

* Add tctl support for Linux desktop (#63273)

* Add LinuxDesktop gRPC and backend

* Add tctl support for Linux desktop

* Add LinuxDesktop gRPC and backend

* Remove CloneResource

* Review comments

* Fix logins

* Update lib/auth/linuxdesktop/linuxdesktopv1/service.go

Co-authored-by: Zac Bergquist <[email protected]>

* Fix role

* Remove duplicate code

* Cleanup

* Fix test

---------

Co-authored-by: Zac Bergquist <[email protected]>

* Proto changes for Linux Desktop (#65692)

* Add LinuxDesktop gRPC and backend

* Add LinuxDesktop resource to unified resources

* Remove CloneResource

* Review comments

* Fix logins

* Review comment

* Add ClonableResourceWithLabels

* Fix missing CloneResource

* Update lib/auth/linuxdesktop/linuxdesktopv1/service.go

Co-authored-by: Zac Bergquist <[email protected]>

* Proto changes for Linux Desktop

* Fix role

* Update lib/auth/auth_with_roles.go

Co-authored-by: Zac Bergquist <[email protected]>

* Update lib/web/ui/server.go

Co-authored-by: Zac Bergquist <[email protected]>

* Fix compilation

* Review comments

* Review comments

* e

* skip gogoproto

* e

* fix test

---------

Co-authored-by: Zac Bergquist <[email protected]>

* Add locks support for Linux desktop (#65761)

* Add LinuxDesktop gRPC and backend

* Add LinuxDesktop resource to unified resources

* Remove CloneResource

* Review comments

* Fix logins

* Review comment

* Add ClonableResourceWithLabels

* Fix missing CloneResource

* Update lib/auth/linuxdesktop/linuxdesktopv1/service.go

Co-authored-by: Zac Bergquist <[email protected]>

* Proto changes for Linux Desktop

* Add locks support for Linux desktop

* Fix role

* Update lib/auth/auth_with_roles.go

Co-authored-by: Zac Bergquist <[email protected]>

* Update lib/web/ui/server.go

Co-authored-by: Zac Bergquist <[email protected]>

* Fix compilation

* Review comments

* Review comments

* fix e

---------

Co-authored-by: Zac Bergquist <[email protected]>

* Fix compilation

* Operator CRD

* Fix test

* Add Linux desktop support (#65841)

* Implement support for TDPB in Desktop Agent.

* Add LinuxDesktop gRPC and backend

* Add LinuxDesktop resource to unified resources

* Add Linux desktop service

* Remove CloneResource

* Review comments

* Unifide fix

* routing

* Fix logins

* Fix logins

* Fix CA cache and write basic loop

* Review comment

* Fix components and handleConnection

* Review comment

* Add ClonableResourceWithLabels

* Fix missing CloneResource

* Add Xvfb handlers

* Add Xephyr

* Add Xvfb controller

* Add QOI encoder

* encoder + xsession

* reexec

* ChildLogConfig

* session

* add forceloginshell

* update frontend + fix session

* Review comments

* Fix code, update docs

* Fix TARGETS format, reuse waiting

* Remove direct mode

* Update lib/auth/linuxdesktop/linuxdesktopv1/service.go

Co-authored-by: Zac Bergquist <[email protected]>

* Add MFA and cert usage support

* Add RemoteAddr

* Revert Uacc setup

* Add session selector

* Refactor code

* Add session recording, tracking and events

* Add session recording, tracking and events

* Refactor command reexecution

* Review comments

* Use reexec.ConfigureCommand

* Proto changes for Linux Desktop

* Proto changes for Linux Desktop

* Add locks support for Linux desktop

* Add guard around m.ScreenSpec

* Cleanup

* Add activity monitor

* Cleanup

* Fix compilation

* Cleanup unified view

* Refactor linux session

* Add logging

* Add logging

* go mod tidy

* Adjust logging

* go mod tidy

* Grab stderr from reexec

* Fix UACC

* pass remote addr to uacc

* TMP: debug images

* Fix panic

* TMP: debug images

* limit change size

* Monitor resolution and restore it

* TMP: debug images

* TMP: debug images

* TMP: debug images

* Modify screen resize

* TMP: debug images

* TMP: debug images

* Add XDG env variable

* Use dbus-run-session

* pam

* variables fix

* variables fix

* revert uacc

* cleanup

* EncodeQOIZ noop

* EncodeQOIZ noop

* Fix auditing

* Cleanup

* Fix type check

* Fix formatting

* Fix licenses

* Fix lint

* go mod tidy

* Fix audit reference

* Fix log

* Fix tests

* Fix tests

* Remove testing from xgb

* go mod tidy

* Fix tests

* xgb 1.3.1

* Handle multiple SessionSelection messages

* Add filters for sessions

* fix events

* Fix compilation + events

* Fix test

* Fix test

* Fix UI

* cleanup

* review comments

* Rework poll eq

* Fix bounds clipping

* fix imports

* lint

* lint

* err

* Fix locking in resize

* Fix ReadChildError

* remove dependabot exclusion

* Fix session end

* Cleanup metedata

* Fix session events

* Ignore multiple ClientHello

* Use slices.IndexFunc in setScreenSize

* Cleanup unused code

* Update lib/service/linux_desktop.go

Co-authored-by: Zac Bergquist <[email protected]>

* Use slices.Clone

* Update lib/srv/desktop/x11/xsession.go

Co-authored-by: Zac Bergquist <[email protected]>

* Fix import

* Use filepath.Glob

* Simplify testdata path calculation

* Cleanup comment

* Cleanup endpoints

* Update lib/web/apiserver.go

Co-authored-by: Zac Bergquist <[email protected]>

* Update lib/web/desktop.go

Co-authored-by: Zac Bergquist <[email protected]>

* Cleanup createDesktopConnection signature

* Cleanup createDesktopConnection signature

* Use server capabilities

* Remove dep override

* Add bounds check

* Cleanup

* Add EndTime to reconstructed event

* use cleanupCtx

* cleanup

* Add configuration test

* Add horizontal scroll

* Review comments

* Fix scrolling

* Fix scrolling

* Sort available sessions

* Fix build

* Add bounds check

* Fix tests

* Move expiry

* lint

* Add back metadata nil check

* lint

* Add usage reporting

* Fix error handling

* Fix resizing, add lock prevention

* Move backend creation after authorization

* Fix possible panic in handleSessionSelection

* Check if clipboard is allowed

* Cleanup errors during normal session ending

* use errgroup for all backround tasks

* Review comments

* fix heartbeat

* add guard for root

* fix tests

* add negative check in changes

* cleanup

* cleanup

* add guard

* Review comments

* Review comments

* Review comments

* Review comments

* Review comments

* Read only access for RoleLinuxDesktop

* use dbus-launch

* Add Linux Desktops to inventory UI

* Use X11 launcher script to start sessions

Use a launch script instead of executing the Exec= line from the
Xsession file directly. This handles the "default" case on Debian
systems where the Xsession file reads `Exec=default`.

The launcher can be explicitly configured at the agent level or
left blank, in which case we probe a set of well-known launchers.

* Compositing support

* Fix dbus launcher

Support both `dbus-run-session` and the older `dbus-launch`.

* Fix error messages when Xvfb is not installed

* Add non-root warning

* Use forceFullDamage for resize

* Fix Open API usage

* invalid user test fix

* remove commented code

* Complete TLS handshake

* Improve error message

* Logged wrapped command

* Add dbus-daemon as dependency for dbus-launch

* Update dbus warning and add llvm check to macos build

* Add LinuxDesktop to role list in new token dialog

* Fix teleport start role validation

* Run messageLoop in separate goroutine

* Add LinuxDesktop labels to Admin role

* Add handling for extended keys and ID reuse

* Cleanup shut down logs

* Xsession cleanup

* Rework llvm requirement in Makefile

---------

Co-authored-by: Ryan Hammonds <[email protected]>
Co-authored-by: Zac Bergquist <[email protected]>

* Add support for `internal.linux_desktop_logins` trait (#67777)

* Add support for internal.linux_desktop_logins trait

* Fix xsession test

* Check Linux Desktop Kind is valid (#68675)

* Fix compilation

* Validate Kind at service level (#68710)

* tctl fix

* Fix reexecution

* Fix UI and service

* Fix Windows webassets build

* Add desktop name to active session

* Fix tctl get/edit linux_desktop

* imports

* fix logging

* fix logging

* License

* lint

* Clean logs

* Add xauth entry before starting Xvfb

* Fix release build

* Fix release build

* Fix labels handling

* lint

* tsh recordings export: support Linux desktop recordings

* Fix ListLinuxDesktops

---------

Co-authored-by: Zac Bergquist <[email protected]>
Co-authored-by: Ryan Hammonds <[email protected]>
Co-authored-by: Dan Share <[email protected]>
2026-07-28 17:02:35 +00:00

152 lines
3.7 KiB
Go

/*
* Teleport
* Copyright (C) 2026 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package linuxdesktopv1
import (
"testing"
"github.com/gravitational/trace"
"github.com/stretchr/testify/require"
headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1"
linuxdesktopv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/linuxdesktop/v1"
"github.com/gravitational/teleport/api/types"
)
func TestNewLinuxDesktop(t *testing.T) {
t.Parallel()
spec := linuxdesktopv1pb.LinuxDesktopSpec_builder{
Addr: "127.0.0.1:22",
Hostname: "desktop-1",
}.Build()
desktop, err := NewLinuxDesktop("desktop-1", spec)
require.NoError(t, err)
require.Equal(t, types.KindLinuxDesktop, desktop.GetKind())
require.Equal(t, types.V1, desktop.GetVersion())
require.Equal(t, "desktop-1", desktop.GetMetadata().GetName())
require.Equal(t, spec, desktop.GetSpec())
}
func TestValidateLinuxDesktop(t *testing.T) {
t.Parallel()
valid := linuxdesktopv1pb.LinuxDesktop_builder{
Kind: types.KindLinuxDesktop,
Version: types.V1,
Metadata: &headerv1.Metadata{
Name: "desktop-1",
},
Spec: linuxdesktopv1pb.LinuxDesktopSpec_builder{
Addr: "127.0.0.1:22",
Hostname: "host",
}.Build(),
}.Build()
tests := []struct {
name string
desktop *linuxdesktopv1pb.LinuxDesktop
wantErr bool
}{
{
name: "valid",
desktop: valid,
},
{
name: "nil desktop",
desktop: nil,
wantErr: true,
},
{
name: "missing metadata",
desktop: linuxdesktopv1pb.LinuxDesktop_builder{
Spec: valid.GetSpec(),
}.Build(),
wantErr: true,
},
{
name: "missing name",
desktop: linuxdesktopv1pb.LinuxDesktop_builder{
Metadata: &headerv1.Metadata{},
Spec: valid.GetSpec(),
}.Build(),
wantErr: true,
},
{
name: "missing spec",
desktop: linuxdesktopv1pb.LinuxDesktop_builder{
Metadata: valid.GetMetadata(),
}.Build(),
wantErr: true,
},
{
name: "missing addr",
desktop: linuxdesktopv1pb.LinuxDesktop_builder{
Metadata: valid.GetMetadata(),
Spec: linuxdesktopv1pb.LinuxDesktopSpec_builder{
Hostname: "host",
}.Build(),
}.Build(),
wantErr: true,
},
{
name: "missing hostname",
desktop: linuxdesktopv1pb.LinuxDesktop_builder{
Metadata: valid.GetMetadata(),
Spec: linuxdesktopv1pb.LinuxDesktopSpec_builder{
Addr: "127.0.0.1:22",
}.Build(),
}.Build(),
wantErr: true,
},
{
name: "incorrect kind",
desktop: linuxdesktopv1pb.LinuxDesktop_builder{
Kind: "node",
Version: types.V1,
Metadata: valid.GetMetadata(),
Spec: valid.GetSpec(),
}.Build(),
wantErr: true,
},
{
name: "empty kind",
desktop: linuxdesktopv1pb.LinuxDesktop_builder{
Kind: "",
Version: types.V1,
Metadata: valid.GetMetadata(),
Spec: valid.GetSpec(),
}.Build(),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateLinuxDesktop(tt.desktop)
if tt.wantErr {
require.Error(t, err)
require.True(t, trace.IsBadParameter(err))
return
}
require.NoError(t, err)
})
}
}