Skip to content

Run fleet desktop with user SELinux context when applicable - #30882

Merged
sgress454 merged 31 commits into
mainfrom
sgress454/use-runuser-to-launch-desktop
Jul 25, 2025
Merged

Run fleet desktop with user SELinux context when applicable#30882
sgress454 merged 31 commits into
mainfrom
sgress454/use-runuser-to-launch-desktop

Conversation

@sgress454

@sgress454 sgress454 commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

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). 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.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • For Orbit and Fleet Desktop changes:
    • Make sure fleetd is compatible with the latest released version of Fleet (see Must rule).
    • Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (runtime.GOOS).
    • Manual QA must be performed in the three main OSs, macOS, Windows and Linux. (n/a, code is linux only)
    • Auto-update manual QA, from released version of component to new version (see tools/tuf/test). n/a

Testing

  • Ubuntu with SELinux on
  • Ubuntu with SELinux off
  • Fedora with SELinux on
  • Fedora with SELinux off
  • Debian with SELinux on
  • Debian with SELinux off
  • runWithOutput still works (tested with go run ./tools/dialog/main.go --dialog=zenity)
  • runWithStdin still works (this isn't currently used by Linux)

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.

@coderabbitai

coderabbitai Bot commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes update how the fleet desktop application is launched on Linux. Instead of using sudo, the code now uses runuser and, when needed, runcon to set the correct user and SELinux context. Environment variables are handled more clearly, and a new function retrieves the user's SELinux context.

Changes

File(s) Change summary
orbit/pkg/execuser/execuser_linux.go Refactored command execution to use runuser and runcon for correct user and SELinux context. Added baserun helper. Improved env handling.
orbit/pkg/user/user_linux.go Added GetUserContext function to fetch the SELinux context of a user.

Sequence Diagram(s)

sequenceDiagram
    participant Launcher as Fleet Desktop Launcher
    participant User as Target User
    participant SELinux as SELinux Context
    participant OS as Linux OS

    Launcher->>User: Get user info and environment
    Launcher->>SELinux: Get SELinux context (if enabled)
    alt SELinux context present
        Launcher->>OS: Launch process with runcon + runuser (correct context and user)
    else SELinux context absent
        Launcher->>OS: Launch process with runuser (correct user)
    end
    OS-->>Launcher: Process started under correct user and context
Loading
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sgress454/use-runuser-to-launch-desktop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sgress454 sgress454 changed the title Sgress454/use runuser to launch desktop Run fleet desktop with user SELinux context when applicable Jul 15, 2025
@codecov

codecov Bot commented Jul 15, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 80 lines in your changes missing coverage. Please review.

Project coverage is 64.01%. Comparing base (e898814) to head (c8d9506).
Report is 84 commits behind head on main.

Files with missing lines Patch % Lines
orbit/pkg/execuser/execuser_linux.go 0.00% 48 Missing ⚠️
orbit/pkg/user/user_linux.go 0.00% 32 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #30882      +/-   ##
==========================================
- Coverage   64.01%   64.01%   -0.01%     
==========================================
  Files        1905     1896       -9     
  Lines      187625   187405     -220     
  Branches     5369     5287      -82     
==========================================
- Hits       120108   119966     -142     
+ Misses      58073    57993      -80     
- Partials     9444     9446       +2     
Flag Coverage Δ
backend 64.86% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sgress454
sgress454 marked this pull request as ready for review July 16, 2025 15:08
@sgress454
sgress454 requested a review from a team as a code owner July 16, 2025 15:08
@sgress454

Copy link
Copy Markdown
Contributor Author

@lucasmrod this is ready for code review, I still need to test it on a few OSs to check I didn't break anything.

lucasmrod
lucasmrod previously approved these changes Jul 16, 2025

@lucasmrod lucasmrod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Left some nit comments

Comment thread orbit/pkg/execuser/execuser_linux.go Outdated
Comment thread orbit/pkg/execuser/execuser_linux.go Outdated
Comment thread orbit/pkg/user/user_linux.go Outdated
@sgress454

Copy link
Copy Markdown
Contributor Author

@lucasmrod addressed your comments, thanks!

@sgress454
sgress454 merged commit f4cc1a2 into main Jul 25, 2025
53 of 54 checks passed
@sgress454
sgress454 deleted the sgress454/use-runuser-to-launch-desktop branch July 25, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants