ThePorgs / Exegol

Fully featured and community-driven hacking environment
https://exegol.readthedocs.io/
GNU General Public License v3.0
1.95k stars 191 forks source link

[BUG] xhost unable to open display (+ fix) #148

Closed XVanilor closed 1 year ago

XVanilor commented 1 year ago

Describe the bug

Hello,

[Situation]

I discovered a tiny bug with Exegol while trying to launch a GUI app. As it might rely on xhost, if the DISPLAY environment variable is not set on the host's machine, Exegol command will crash with xhost: unable to open display ""

I'm using Ubuntu 20.04.5 LTS, Linux kernel 5.13.0-51 and Gnome Desktop

[Tries]

Before all of those command, I installed xorg and openbox using apt install xorg openbox

I tried several fixes found on Internet in order to get the correct DISPLAY variable. However, those failed:

[Fix]

The one that worked for me was export DISPLAY=:0. Writing this at the end of your ~/.profile file will ensure that the fix is permanent. Commands which involves GUI in Exegol now works

Steps To Reproduce

  1. Your system does not have DISPLAY environment variable, or use unset DISPLAY to reproduce
  2. Start Exegol with exegol start (regular or sudo user). You should see xhost: unable to open display "" in starting logs
  3. Try to launch a GUI app (for example, firefox)
  4. Command should fail with xhost: unable to open display ""

Exegol Wrapper Version

> exegol version -vvv

[*] Exegol is currently in version v4.1.1
[*] Exegol Discord serv.: https://discord.gg/cXThyp7D6P
[*] Exegol documentation: https://exegol.rtfd.io/
[+] We thank Capgemini for supporting the project (helping with dev) šŸ™                                                                                                                                            
[+] We thank HackTheBox for sponsoring the multi-arch support šŸ’š                                                                                                                                                   
[D] Pip installation: Off šŸŖ“                                                                                                                                                                                       
[D] Git source installation: On āœ”                                                                                                                                                                                  
[D] Host OS: Linux                                                                                                                                                                                                 
[D] Arch: amd64                                                                                                                                                                                                    
[D] Raw arch: x86_64                                                                                                                                                                                               
[D] Docker desktop: Off šŸŖ“                                                                                                                                                                                         
[D] Shell type: Linux                                                                                                                                                                                              
[D] Last update check: 14/03/2023

Host OS

Linux

Configuration of the concerned container

No response

Execution logs in debug mode

> exegol -vvv start

[*] Exegol is currently in version v4.1.1
[*] Exegol Discord serv.: https://discord.gg/cXThyp7D6P
[*] Exegol documentation: https://exegol.rtfd.io/
[+] We thank Capgemini for supporting the project (helping with dev) šŸ™                                                                                                                                            
[+] We thank HackTheBox for sponsoring the multi-arch support šŸ’š                                                                                                                                                   
[*] Starting exegol                                                                                                                                                                                                

šŸ‘½ Available containers                                         
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
ā”‚ Container tag  ā”‚ State   ā”‚ Image tag ā”‚ Configurations        ā”‚
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
ā”‚ <redacted>     ā”‚ Running ā”‚ nightly   ā”‚ Default configuration ā”‚
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

[*] You can use a name that does not already exist to create a new container                                                                                                                                       
[?] Select a container by its name (<redacted>): 
[*] Location of the exegol workspace on the host : <redacted>                                                                                                                         
[+] Opening shell in Exegol '<redacted>'                                                                                                                                                                       
xhost:  unable to open display ""
[Mar 14, 2023 - 10:46:49 (CET)] exegol-<redacted> /workspace # firefox                                            
No protocol specified
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0

Exception

No response

Anything else?

No response

Dramelac commented 1 year ago

Hello

Thank you for the feedback

The wrapper already uses a fallback to ":0" if the environment variable is not present. (See the last line of execution in the section "Execution logs in debug mode") but this is only applicable inside the container, we don't change the host environment configuration. The wrapper tries to call xhost but indeed if the host is not correctly configured it will cause problems.

The problem being rather on the side of the host (/ DISPLAY service) I don't see what to add on the wrapper side...

Maybe add a warning message if the xhost commands fail ? Or maybe add this use case in the documentation for troubleshooting ? What do you think @ShutdownRepo ?

ShutdownRepo commented 1 year ago

Agreed, this is a host issue. However, we could probably raise a warning message at wrapper level if we feel like the DISPLAY env is messed up and user didn't use --disable-X11

XVanilor commented 1 year ago

Initially, I wrote this bug report to provide troubleshooting to anyone which might encounter it, as Exegol does not indicate what could have gone wrong. It would be great to raise a message to indicate what's missing (DISPLAY environment variable on the host) instead of the default error message of xhost

ShutdownRepo commented 1 year ago

Agreed, we'll make the necessary changes to the wrapper Thank you for raising the suggestion