fleet/orbit/pkg/execuser/execuser_linux.go

337 lines
10 KiB
Go
Raw Normal View History

package execuser
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"
"syscall"
Don't attempt to start fleet desktop if no user is logged in on Linux (#30261) for #29942 # Details This PR addresses an issue on Linux where Orbit repeatedly attempts to launch Fleet Desktop even though no GUI user is logged in. The fix is similar to one implemented for MacOS, where we have Orbit check for the presence of a real user (not a system user like `gdm` or `root`) before trying to launch the desktop app. Part of this work involved moving some functionality from the `execuser` package to the `user` package, to avoid duplicating functionality. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - [x] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. The changed code is only executed on Linux, so I tested on Ubuntu, Fedora and Debian. Also verified that it still works on MacOS and Windows. --------- Co-authored-by: Lucas Manuel Rodriguez <lucas@fleetdm.com>
2025-06-27 13:41:13 +00:00
userpkg "github.com/fleetdm/fleet/v4/orbit/pkg/user"
"github.com/rs/zerolog/log"
)
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
// base command to setup an exec.Cmd using `runuser`
func baserun(path string, opts eopts) (cmd *exec.Cmd, err error) {
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
if opts.user == "" {
return nil, errors.New("missing user")
}
args, env, err := getConfigForCommand(opts.user, path)
2024-11-20 16:44:40 +00:00
if err != nil {
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
return nil, fmt.Errorf("get args: %w", err)
2024-11-20 16:44:40 +00:00
}
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
env = append(env,
2024-11-20 16:44:40 +00:00
// Append the packaged libayatana-appindicator3 libraries path to LD_LIBRARY_PATH.
//
// Fleet Desktop doesn't use libayatana-appindicator3 since 1.18.3, but we need to
// keep this to support older versions of Fleet Desktop.
fmt.Sprintf("LD_LIBRARY_PATH=%s:%s", filepath.Dir(path), os.ExpandEnv("$LD_LIBRARY_PATH")),
)
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
for _, nv := range opts.env {
env = append(env, fmt.Sprintf("%s=%s", nv[0], nv[1]))
}
// Hold any command line arguments to pass to the command.
cmdArgs := make([]string, 0, len(opts.args)*2)
if len(opts.args) > 0 {
for _, arg := range opts.args {
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
cmdArgs = append(cmdArgs, arg[0])
if arg[1] != "" {
cmdArgs = append(cmdArgs, arg[1])
}
}
}
Fix orbit process launch issues that can hit /proc/keys limits (#32309) for #32112 # Details This PR reverts some earlier work using `runuser` and `runcon` intended to allow Orbit to launch Fleet Desktop in the logged-in user's SELinux context. This didn't work for out-of-the-box SELinux enforcement setups, with a side-effect of each failed attempt to launch the desktop app creating a new kernel keyring that doesn't get cleaned up until Orbit quits (or GC runs, although I didn't see that happen in testing). While using `runuser` has some possible benefits over using `sudo` to launch processes, it also (when using `-l` to start a login shell) creates a new keyring. This is not an issue if the command to launch the process succeeds, but if it fails and retries over and over, we start amassing keyrings. It is the opinion of several other engineers (and now myself as well) that the real solution to various Fleet Desktop launching issues is to launch the desktop app as a user service using `systemctl --user` so that it automatically inherits the user's environment, context, etc. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. # Testing - [X] QA'd all new/changed functionality manually - [ ] ~Ubuntu with SELinux on~ this is a very uncommon setup - [x] Ubuntu with SELinux off - [X] Fedora with SELinux on - double checked that `getenforce` returned `Enforcing` this time - [X] Fedora with SELinux off - [ ] ~Debian with SELinux on~ this is a very uncommon setup - [X] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity` on all platforms) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) ## fleetd/orbit/Fleet Desktop - [X] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [X] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [X] Verified that fleetd runs on macOS, Linux and Windows - [ ] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
2025-08-28 14:20:32 +00:00
// Run `env` to setup the environment.
args = append(args, "env")
args = append(args, env...)
// Pass the command and its arguments.
args = append(args, path)
args = append(args, cmdArgs...)
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
Fix orbit process launch issues that can hit /proc/keys limits (#32309) for #32112 # Details This PR reverts some earlier work using `runuser` and `runcon` intended to allow Orbit to launch Fleet Desktop in the logged-in user's SELinux context. This didn't work for out-of-the-box SELinux enforcement setups, with a side-effect of each failed attempt to launch the desktop app creating a new kernel keyring that doesn't get cleaned up until Orbit quits (or GC runs, although I didn't see that happen in testing). While using `runuser` has some possible benefits over using `sudo` to launch processes, it also (when using `-l` to start a login shell) creates a new keyring. This is not an issue if the command to launch the process succeeds, but if it fails and retries over and over, we start amassing keyrings. It is the opinion of several other engineers (and now myself as well) that the real solution to various Fleet Desktop launching issues is to launch the desktop app as a user service using `systemctl --user` so that it automatically inherits the user's environment, context, etc. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. # Testing - [X] QA'd all new/changed functionality manually - [ ] ~Ubuntu with SELinux on~ this is a very uncommon setup - [x] Ubuntu with SELinux off - [X] Fedora with SELinux on - double checked that `getenforce` returned `Enforcing` this time - [X] Fedora with SELinux off - [ ] ~Debian with SELinux on~ this is a very uncommon setup - [X] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity` on all platforms) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) ## fleetd/orbit/Fleet Desktop - [X] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [X] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [X] Verified that fleetd runs on macOS, Linux and Windows - [ ] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
2025-08-28 14:20:32 +00:00
// Use sudo to run the command as the login user.
args = append([]string{"sudo"}, args...)
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
// If a timeout is set, prefix the command with "timeout".
if opts.timeout > 0 {
args = append([]string{"timeout", fmt.Sprintf("%ds", int(opts.timeout.Seconds()))}, args...)
}
cmd = exec.Command(args[0], args[1:]...) // #nosec G204
return
}
// run a command, passing its output to stdout and stderr.
func run(path string, opts eopts) (lastLogs string, err error) {
cmd, err := baserun(path, opts)
if err != nil {
return "", err
}
2024-11-20 16:44:40 +00:00
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
log.Info().Str("cmd", cmd.String()).Msg("running command")
2024-11-20 16:44:40 +00:00
if err := cmd.Start(); err != nil {
return "", fmt.Errorf("open path %q: %w", path, err)
}
return "", nil
}
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
// runWithOutput runs a command and return its output and exit code.
2024-11-20 16:44:40 +00:00
func runWithOutput(path string, opts eopts) (output []byte, exitCode int, err error) {
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
cmd, err := baserun(path, opts)
2024-11-20 16:44:40 +00:00
if err != nil {
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
return nil, -1, err
}
2024-11-20 16:44:40 +00:00
output, err = cmd.Output()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
exitCode = exitErr.ExitCode()
return output, exitCode, fmt.Errorf("%q exited with code %d: %w", path, exitCode, err)
}
return output, -1, fmt.Errorf("%q error: %w", path, err)
}
return output, exitCode, nil
}
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
func getUserID(user string) (string, error) {
uid_, err := exec.Command("id", "-u", user).Output()
if err != nil {
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
return "", fmt.Errorf("failed to execute id command for %q: %w", user, err)
}
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
uid := strings.TrimSpace(string(uid_))
if uid == "" {
return "", errors.New("failed to get uid")
}
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
return uid, nil
}
func getDisplayVariableForSession(userID string, displaySessionType userpkg.GuiSessionType) string {
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
if displaySessionType == userpkg.GuiSessionTypeX11 {
x11Display, err := getUserX11Display(userID)
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
if err != nil {
log.Error().Err(err).Msg("failed to get X11 display, using default :0")
// TODO(lucas): Revisit when working on multi-user/multi-session support.
// Default to display ':0' if user display could not be found.
// This assumes there's only one desktop session and belongs to the
// user returned in `getLoginUID'.
return ":0"
}
return x11Display
}
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
waylandDisplay, err := getUserWaylandDisplay(userID)
if err != nil {
log.Error().Err(err).Msg("failed to get wayland display, using default wayland-0")
// TODO(lucas): Revisit when working on multi-user/multi-session support.
// Default to display 'wayland-0' if user display could not be found.
// This assumes there's only one desktop session and belongs to the
// user returned in `getLoginUID'.
return "wayland-0"
}
return waylandDisplay
}
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
func getConfigForCommand(user string, path string) (args []string, env []string, err error) {
// Get user ID
userID, err := getUserID(user)
if err != nil {
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
return nil, nil, fmt.Errorf("get user ID: %w", err)
}
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
log.Info().Str("user", user).Str("id", userID).Msg("attempting to get user session type and display")
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
// Get user's display session type.
userDisplaySession, err := userpkg.GetUserDisplaySessionType(userID)
if err != nil {
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
// Wayland is the default for most distributions,
// thus we assume wayland if we couldn't determine the session type.
log.Error().Err(err).Msg("assuming wayland session")
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
userDisplaySession = &userpkg.UserDisplaySession{
Type: userpkg.GuiSessionTypeWayland,
}
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
} else if userDisplaySession.Type == userpkg.GuiSessionTypeTty {
return nil, nil, fmt.Errorf("user %q (%s) is not running a GUI session", user, userID)
}
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
// Get user's "display" variable for the GUI session.
display := getDisplayVariableForSession(userID, userDisplaySession.Type)
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
log.Info().
Str("path", path).
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
Str("user", user).
Str("id", userID).
Str("display", display).
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
Str("session_type", userDisplaySession.Type.String()).
Fix orbit process launch issues that can hit /proc/keys limits (#32309) for #32112 # Details This PR reverts some earlier work using `runuser` and `runcon` intended to allow Orbit to launch Fleet Desktop in the logged-in user's SELinux context. This didn't work for out-of-the-box SELinux enforcement setups, with a side-effect of each failed attempt to launch the desktop app creating a new kernel keyring that doesn't get cleaned up until Orbit quits (or GC runs, although I didn't see that happen in testing). While using `runuser` has some possible benefits over using `sudo` to launch processes, it also (when using `-l` to start a login shell) creates a new keyring. This is not an issue if the command to launch the process succeeds, but if it fails and retries over and over, we start amassing keyrings. It is the opinion of several other engineers (and now myself as well) that the real solution to various Fleet Desktop launching issues is to launch the desktop app as a user service using `systemctl --user` so that it automatically inherits the user's environment, context, etc. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. # Testing - [X] QA'd all new/changed functionality manually - [ ] ~Ubuntu with SELinux on~ this is a very uncommon setup - [x] Ubuntu with SELinux off - [X] Fedora with SELinux on - double checked that `getenforce` returned `Enforcing` this time - [X] Fedora with SELinux off - [ ] ~Debian with SELinux on~ this is a very uncommon setup - [X] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity` on all platforms) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) ## fleetd/orbit/Fleet Desktop - [X] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [X] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [X] Verified that fleetd runs on macOS, Linux and Windows - [ ] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
2025-08-28 14:20:32 +00:00
Msg("running sudo")
Fix Fleet Desktop not launching on OpenSUSE 16 (#44482) This pull request addresses a startup issue with Fleet Desktop on openSUSE Leap 16 and similar Linux distributions. The main change is to adjust how Fleet Desktop and key-escrow dialogs are launched to avoid environment variable loss caused by login shell profile scripts. The fix is scoped specifically to openSUSE Leap 16+ to avoid impacting other distributions. **Distribution-specific sudo invocation changes:** * The `-i` (login shell) flag is now omitted from the `sudo` command when launching Fleet Desktop and key-escrow dialogs on openSUSE Leap 16 and newer, preventing environment variables from being lost due to profile script interference. [[1]](diffhunk://#diff-633ab361af6795ef458233819e2806dfba4ca56f684866d956321825b8fd2e91R1) [[2]](diffhunk://#diff-3e8315d9f12512bce490457c5d20bd7c5aebaa2a8e18b1abf50e504815dd7a9dR178-R193) * For all other supported distributions, the previous behavior (using `-i`) is preserved to maintain compatibility and avoid unnecessary re-testing. **Detection logic:** * Introduced a new helper function `isOpenSUSELeap16Plus` in `execuser_linux.go` to detect if the host is running openSUSE Leap 16 or newer by parsing `/etc/os-release`. This ensures the workaround is only applied where necessary. --- **Related issue:** N/A — surfaced via field investigation on openSUSE Leap 16 (arm64). This PR addresses two distinct issues that together prevent Fleet Desktop from working on openSUSE Leap 16, both validated end-to-end on a real Leap 16 (arm64) host. ## 1. Launch reliability — drop `sudo -i` `orbit/pkg/execuser/execuser_linux.go` On Linux, Orbit launches Fleet Desktop with: ``` sudo -n -i -u <user> -H env WAYLAND_DISPLAY=… … FLEET_DESKTOP_DEVICE_IDENTIFIER_PATH=/opt/orbit/identifier … /…/fleet-desktop ``` The `-i` flag makes sudo "simulate initial login" — it runs the target user's shell as a login shell and wraps the rest of the command in `bash --login -c '<escaped>'`. That sources `/etc/profile` and every script in `/etc/profile.d/*` before our `env KEY=val … fleet-desktop` line runs, and shell metacharacters (`=`, `:`, `/`, `.`) get backslash-escaped through the shell layer. On **openSUSE Leap 16 (arm64)**, that indirection causes the inline env-var assignments to not reach `fleet-desktop`, which exits immediately with: ``` FTL missing URL environment FLEET_DESKTOP_DEVICE_IDENTIFIER_PATH ``` Orbit then respawns it every ~15 s in a tight kill-and-respawn loop, so the tray icon never appears. **Fix:** drop `-i` from the sudo invocation. We don't need a login shell: - `-H` already sets `HOME` to the target user. - sudo's default `env_reset` sets `USER` / `LOGNAME` / `SHELL` / `MAIL` and `PATH` to `secure_path`. - All session vars (`WAYLAND_DISPLAY`, `DISPLAY`, `DBUS_SESSION_BUS_ADDRESS`, `LD_LIBRARY_PATH`) and every `FLEET_DESKTOP_*` var are already passed explicitly via `env KEY=val …`. After the change, sudo `execve()`s `env` directly with no shell layer in between, so `/etc/profile.d` sourcing and shell-escaping are out of the picture. The `runuser -l` /proc/keys-leak regression from PR #32309 does not apply — that was specific to `runuser -l` creating session keyrings; sudo without `-i` doesn't. # Checklist for submitter - [x] Changes file added: `orbit/changes/fleet-desktop-linux-no-login-shell` - [x] Input data is properly validated; untrusted data interpolated into shell scripts/commands is validated against shell metacharacters. - [x] Timeouts are implemented and retries are limited to avoid infinite loops (script's wait loop now bounded at 90s). - [x] If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes — N/A. ## Testing Manual QA needed before merge: - [x] **openSUSE Leap 16 (arm64)** — Fleet Desktop process starts, stays running, env vars present, no FTL respawn loop. Done via `sudo` shim. - [x] **openSUSE Leap 16 (arm64) — extension fallback** — manual tarball install + schema compilation produces a working tray icon (matching what the script automates). - [ ] **Ubuntu 22.04 / 24.04** — regression check: Fleet Desktop tray icon still appears, key-escrow zenity dialog still renders, AppIndicator script still installs via the official path. - [ ] **Fedora (recent)** — regression check: same as above. - [ ] **Debian** — regression check: same as above. - [ ] **openSUSE Tumbleweed** — confirm `InstallRemoteExtension` path still works (no fallback path triggered). ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet — pure launch-flag change plus a script update; no protocol or schema impact. - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes — Go change is in `execuser_linux.go`, only built on Linux. The script is Linux-only by construction. - [ ] Verified that fleetd runs on macOS, Linux and Windows — Linux re-verification pending QA above; macOS/Windows code paths unchanged. - [ ] Verified auto-update works from the released version of component to the new version. ## Notes for reviewers - The tray-icon visibility issue is an OS-side prerequisite (GNOME 3.26+ has no native tray), so the AppIndicator extension is required regardless. Even after installing it, Wayland requires a logout/login to pick up new extensions — this is documented behavior and not specific to the fallback path.
2026-05-02 04:26:56 +00:00
// On openSUSE Leap 16+ we drop -i (login shell). With -i, sudo runs the target
// user's shell as a login shell and passes the rest of the command via
// `bash --login -c`, which sources /etc/profile and /etc/profile.d/* and
// shell-escapes the inline command. On Leap 16 that environment indirection
// causes our `env KEY=val ... fleet-desktop` invocation to lose env vars, so
// fleet-desktop exits with "missing URL environment ..." and Orbit respawns it
// in a tight loop. -H sets HOME to the target user; sudo's default env_reset
// already sets USER/LOGNAME/SHELL.
//
// We keep -i on every other supported distribution to preserve the previously
// QA'd behavior.
if isOpenSUSELeap16Plus() {
args = []string{"-n", "-u", user, "-H"}
} else {
args = []string{"-n", "-i", "-u", user, "-H"}
}
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
env = make([]string, 0)
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
if userDisplaySession.Type == userpkg.GuiSessionTypeWayland {
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
env = append(env, "WAYLAND_DISPLAY="+display)
// For xdg-open to work on a Wayland session we still need to set the DISPLAY variable.
x11Display := ":" + strings.TrimPrefix(display, "wayland-")
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
env = append(env, "DISPLAY="+x11Display)
} else {
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
env = append(env, "DISPLAY="+display)
}
Run fleet desktop with user SELinux context when applicable (#30882) For #29793 # Details This PR changes the way that Orbit launches processes such as the desktop app on Linux, in order to ensure that on SELinux-enabled systems the correct user context is set when running the command. Previously, `sudo -u` was used to launch commands on Linux. This PR switches to use `runuser` instead, which is recommended in situations where the root user wants to execute a command as a user with reduced privileges (see [the blog post by one of the creators of runuser](https://danwalsh.livejournal.com/55588.html)). This avoids certain errors that can come from interacting with PAM modules as the system user. Additionally, if we detect that SELinux is set up on a system, we now use `runcon` to force the command to run using the logged-in user's SELinux context. It's possible that on some systems they may have configuration where `sudo` will switch to the user's SELinux context automatically, but this is not guaranteed. Using `runuser` + `runcon` is our best bet for ensuring that the desktop app (and anything that it spawns) runs under the correct context. This PR also does some refactoring so that the three `run` methods for Linux (`run`, `runWithOutput` and `runWithStdin`) all use the same base code to create the command with the correct args and env vars, and differ only in how they handle the i/o. # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - For Orbit and Fleet Desktop changes: - [x] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)). - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [x] ~Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ (n/a, code is linux only) - [x] ~Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ n/a # Testing - [x] Ubuntu with SELinux on - [x] Ubuntu with SELinux off - [ ] Fedora with SELinux on - [ ] Fedora with SELinux off - [ ] Debian with SELinux on - [x] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity`) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved security and user context handling when launching the fleet desktop application on Linux systems. * **Refactor** * Enhanced process launch mechanism to use proper SELinux context and user session, ensuring processes start under the correct user and security environment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-25 13:44:13 +00:00
env = append(env,
// DBUS_SESSION_BUS_ADDRESS sets the location of the user login session bus.
// Required by the libayatana-appindicator3 library to display a tray icon
// on the desktop session.
//
// This is required for Ubuntu 18, and not required for Ubuntu 21/22
// (because it's already part of the user).
Fix orbit active GUI session detection to start Fleet Desktop and key escrowing on Linux (#39777) Resolves #36024 and #34501. Main change is about stop using the first user in the `users` command output [*] and instead use `loginctl` commands to pick the correct current active GUI user. [*] `users` was returning empty on some new distributions, and in multi-sessions we were always picking the first one (even if it wasn't active). - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Fixed Fleet Desktop startup to correctly detect and use the active GUI session on Linux systems. * Improved GUI user detection for dialog prompts, ensuring system dialogs run in the proper user context. * **Improvements** * Enhanced error reporting and logging clarity for GUI session detection failures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-16 14:41:16 +00:00
fmt.Sprintf("DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%s/bus", userID),
)
Fix orbit process launch issues that can hit /proc/keys limits (#32309) for #32112 # Details This PR reverts some earlier work using `runuser` and `runcon` intended to allow Orbit to launch Fleet Desktop in the logged-in user's SELinux context. This didn't work for out-of-the-box SELinux enforcement setups, with a side-effect of each failed attempt to launch the desktop app creating a new kernel keyring that doesn't get cleaned up until Orbit quits (or GC runs, although I didn't see that happen in testing). While using `runuser` has some possible benefits over using `sudo` to launch processes, it also (when using `-l` to start a login shell) creates a new keyring. This is not an issue if the command to launch the process succeeds, but if it fails and retries over and over, we start amassing keyrings. It is the opinion of several other engineers (and now myself as well) that the real solution to various Fleet Desktop launching issues is to launch the desktop app as a user service using `systemctl --user` so that it automatically inherits the user's environment, context, etc. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. # Testing - [X] QA'd all new/changed functionality manually - [ ] ~Ubuntu with SELinux on~ this is a very uncommon setup - [x] Ubuntu with SELinux off - [X] Fedora with SELinux on - double checked that `getenforce` returned `Enforcing` this time - [X] Fedora with SELinux off - [ ] ~Debian with SELinux on~ this is a very uncommon setup - [X] Debian with SELinux off - [x] `runWithOutput` still works (tested with `go run ./tools/dialog/main.go --dialog=zenity` on all platforms) - [ ] ~`runWithStdin` still works~ (this isn't currently used by Linux) ## fleetd/orbit/Fleet Desktop - [X] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [X] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [X] Verified that fleetd runs on macOS, Linux and Windows - [ ] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))
2025-08-28 14:20:32 +00:00
return args, env, nil
}
Fix Fleet Desktop not launching on OpenSUSE 16 (#44482) This pull request addresses a startup issue with Fleet Desktop on openSUSE Leap 16 and similar Linux distributions. The main change is to adjust how Fleet Desktop and key-escrow dialogs are launched to avoid environment variable loss caused by login shell profile scripts. The fix is scoped specifically to openSUSE Leap 16+ to avoid impacting other distributions. **Distribution-specific sudo invocation changes:** * The `-i` (login shell) flag is now omitted from the `sudo` command when launching Fleet Desktop and key-escrow dialogs on openSUSE Leap 16 and newer, preventing environment variables from being lost due to profile script interference. [[1]](diffhunk://#diff-633ab361af6795ef458233819e2806dfba4ca56f684866d956321825b8fd2e91R1) [[2]](diffhunk://#diff-3e8315d9f12512bce490457c5d20bd7c5aebaa2a8e18b1abf50e504815dd7a9dR178-R193) * For all other supported distributions, the previous behavior (using `-i`) is preserved to maintain compatibility and avoid unnecessary re-testing. **Detection logic:** * Introduced a new helper function `isOpenSUSELeap16Plus` in `execuser_linux.go` to detect if the host is running openSUSE Leap 16 or newer by parsing `/etc/os-release`. This ensures the workaround is only applied where necessary. --- **Related issue:** N/A — surfaced via field investigation on openSUSE Leap 16 (arm64). This PR addresses two distinct issues that together prevent Fleet Desktop from working on openSUSE Leap 16, both validated end-to-end on a real Leap 16 (arm64) host. ## 1. Launch reliability — drop `sudo -i` `orbit/pkg/execuser/execuser_linux.go` On Linux, Orbit launches Fleet Desktop with: ``` sudo -n -i -u <user> -H env WAYLAND_DISPLAY=… … FLEET_DESKTOP_DEVICE_IDENTIFIER_PATH=/opt/orbit/identifier … /…/fleet-desktop ``` The `-i` flag makes sudo "simulate initial login" — it runs the target user's shell as a login shell and wraps the rest of the command in `bash --login -c '<escaped>'`. That sources `/etc/profile` and every script in `/etc/profile.d/*` before our `env KEY=val … fleet-desktop` line runs, and shell metacharacters (`=`, `:`, `/`, `.`) get backslash-escaped through the shell layer. On **openSUSE Leap 16 (arm64)**, that indirection causes the inline env-var assignments to not reach `fleet-desktop`, which exits immediately with: ``` FTL missing URL environment FLEET_DESKTOP_DEVICE_IDENTIFIER_PATH ``` Orbit then respawns it every ~15 s in a tight kill-and-respawn loop, so the tray icon never appears. **Fix:** drop `-i` from the sudo invocation. We don't need a login shell: - `-H` already sets `HOME` to the target user. - sudo's default `env_reset` sets `USER` / `LOGNAME` / `SHELL` / `MAIL` and `PATH` to `secure_path`. - All session vars (`WAYLAND_DISPLAY`, `DISPLAY`, `DBUS_SESSION_BUS_ADDRESS`, `LD_LIBRARY_PATH`) and every `FLEET_DESKTOP_*` var are already passed explicitly via `env KEY=val …`. After the change, sudo `execve()`s `env` directly with no shell layer in between, so `/etc/profile.d` sourcing and shell-escaping are out of the picture. The `runuser -l` /proc/keys-leak regression from PR #32309 does not apply — that was specific to `runuser -l` creating session keyrings; sudo without `-i` doesn't. # Checklist for submitter - [x] Changes file added: `orbit/changes/fleet-desktop-linux-no-login-shell` - [x] Input data is properly validated; untrusted data interpolated into shell scripts/commands is validated against shell metacharacters. - [x] Timeouts are implemented and retries are limited to avoid infinite loops (script's wait loop now bounded at 90s). - [x] If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes — N/A. ## Testing Manual QA needed before merge: - [x] **openSUSE Leap 16 (arm64)** — Fleet Desktop process starts, stays running, env vars present, no FTL respawn loop. Done via `sudo` shim. - [x] **openSUSE Leap 16 (arm64) — extension fallback** — manual tarball install + schema compilation produces a working tray icon (matching what the script automates). - [ ] **Ubuntu 22.04 / 24.04** — regression check: Fleet Desktop tray icon still appears, key-escrow zenity dialog still renders, AppIndicator script still installs via the official path. - [ ] **Fedora (recent)** — regression check: same as above. - [ ] **Debian** — regression check: same as above. - [ ] **openSUSE Tumbleweed** — confirm `InstallRemoteExtension` path still works (no fallback path triggered). ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet — pure launch-flag change plus a script update; no protocol or schema impact. - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes — Go change is in `execuser_linux.go`, only built on Linux. The script is Linux-only by construction. - [ ] Verified that fleetd runs on macOS, Linux and Windows — Linux re-verification pending QA above; macOS/Windows code paths unchanged. - [ ] Verified auto-update works from the released version of component to the new version. ## Notes for reviewers - The tray-icon visibility issue is an OS-side prerequisite (GNOME 3.26+ has no native tray), so the AppIndicator extension is required regardless. Even after installing it, Wayland requires a logout/login to pick up new extensions — this is documented behavior and not specific to the fallback path.
2026-05-02 04:26:56 +00:00
// isOpenSUSELeap16Plus reports whether the host is running openSUSE Leap 16 or
// newer. We scope the no-login-shell sudo workaround to that distribution since
// it is the one observed to break under sudo -i; other distributions retain the
// previous (login-shell) launch path so we don't have to re-QA them.
func isOpenSUSELeap16Plus() bool {
data, err := os.ReadFile("/etc/os-release")
if err != nil {
return false
}
var id, versionID string
for line := range strings.SplitSeq(string(data), "\n") {
key, value, ok := strings.Cut(line, "=")
if !ok {
continue
}
// /etc/os-release values may be quoted.
value = strings.Trim(value, `"'`)
switch key {
case "ID":
id = value
case "VERSION_ID":
versionID = value
}
}
if id != "opensuse-leap" {
return false
}
// VERSION_ID is typically "16" or "16.0"; compare the major component.
major, _, _ := strings.Cut(versionID, ".")
n, err := strconv.Atoi(major)
if err != nil {
return false
}
return n >= 16
}
// getUserWaylandDisplay returns the value to set on WAYLAND_DISPLAY for the given user.
func getUserWaylandDisplay(uid string) (string, error) {
matches, err := filepath.Glob("/run/user/" + uid + "/wayland-*")
if err != nil {
return "", fmt.Errorf("list wayland socket files: %w", err)
}
sort.Slice(matches, func(i, j int) bool {
return matches[i] < matches[j]
})
for _, match := range matches {
if strings.HasSuffix(match, ".lock") {
continue
}
return filepath.Base(match), nil
}
return "", errors.New("wayland socket not found")
}
// getUserX11Display returns the value to set on DISPLAY for the given user.
// It scans /proc to find a process owned by the user that has DISPLAY set
// in its environment.
func getUserX11Display(userID string) (string, error) {
uid, err := strconv.ParseUint(userID, 10, 32)
if err != nil {
return "", fmt.Errorf("parse user ID %q: %w", userID, err)
}
entries, err := os.ReadDir("/proc")
if err != nil {
return "", fmt.Errorf("read /proc: %w", err)
}
for _, entry := range entries {
if !entry.IsDir() {
continue
}
// Skip non-PID directories.
if _, err := strconv.Atoi(entry.Name()); err != nil {
continue
}
// Check if the process belongs to our target user.
info, err := entry.Info()
if err != nil {
continue
}
stat, ok := info.Sys().(*syscall.Stat_t)
if !ok || stat.Uid != uint32(uid) {
continue
}
// Try to read DISPLAY from this process's environment.
display, err := readEnvFromProc(entry.Name(), "DISPLAY")
if err != nil || display == "" {
continue
}
log.Debug().Msgf("found DISPLAY variable in %q", entry.Name())
return display, nil
}
return "", fmt.Errorf("DISPLAY not found in any process for user %s", userID)
}
// readEnvFromProc reads a specific environment variable from /proc/<pid>/environ.
func readEnvFromProc(pid string, envVar string) (string, error) {
return readEnvFromProcFile(fmt.Sprintf("/proc/%s/environ", pid), envVar)
}
// readEnvFromProcFile reads a specific environment variable from a /proc environ file.
// The file contains null-byte separated KEY=VALUE entries.
func readEnvFromProcFile(path string, envVar string) (string, error) {
data, err := os.ReadFile(path)
if err != nil {
return "", err
}
prefix := envVar + "="
for entry := range bytes.SplitSeq(data, []byte{0}) {
if s := string(entry); strings.HasPrefix(s, prefix) {
return s[len(prefix):], nil
}
}
return "", nil
}