jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.85k stars 612 forks source link

LaunchBrowser failing to run with error "need to run as root or suid" #770

Open ptgolden opened 1 year ago

ptgolden commented 1 year ago

I am trying to open a Web browser upon launching redbean with the command LaunchBrowser("/"). The server starts up fine, but the browser fails to open with the error message need to run as root or suid.

This is Ubuntu 22.04. My default browser is Firefox Beta installed via snap. Below is the output of ./redbean.com -vvv

$ ./redbean.com -vvv
D2023-03-21T10:44:55.343887:tool/net/redbean.c:4997:redbean:6599] (lua) LuaRunAsset("/.init.lua")
I2023-03-21T10:44:55+000159:tool/net/redbean.c:7057:redbean:6599] (srvr) listen http://127.0.0.1:8080
I2023-03-21T10:44:55+000059:tool/net/redbean.c:7057:redbean:6599] (srvr) listen http://192.168.1.12:8080
V2023-03-21T10:44:55+000229:tool/net/redbean.c:2003:redbean:6599] (ssl) could not find non-CA SSL certificate key pair with -addext keyUsage=digitalSignature -addext extendedKeyUsage=serverAuth
V2023-03-21T10:44:55+000013:tool/net/redbean.c:2006:redbean:6599] (ssl) could not find CA key signing key pair with -addext keyUsage=keyCertSign
V2023-03-21T10:44:55+000008:tool/net/redbean.c:2008:redbean:6599] (ssl) generating self-signed ssl certificates
D2023-03-21T10:44:55+003577:net/https/logcertificate.c:28:redbean:6599] generated EC certificate
 cert. version     : 3
 serial number     : 07:8C:CD:51:7E:F2:89:BE:97:7A:EC:6A:DD:12:AE:AE
 issuer name       : CN=localhost
 subject name      : CN=localhost
 issued  on        : 2023-03-20 17:44:55
 expires on        : 2024-03-21 17:44:55
 signed using      : ECDSA with SHA256
 EC key size       : 256 bits
 basic constraints : CA=false
 subject alt name  :
     dNSName : localhost
     dNSName : *.localhost
     dNSName : localhost.localdomain
     dNSName : *.localhost.localdomain
     iPAddress : 127.0.0.1
     iPAddress : 192.168.1.12
 key usage         : Digital Signature
 ext key usage     : TLS Web Server Authentication, TLS Web Client Authentication
V2023-03-21T10:44:55+000046:tool/net/redbean.c:680:redbean:6599] (ssl) using EC certificate "CN=localhost" for HTTPS server
D2023-03-21T10:44:55+234880:net/https/logcertificate.c:28:redbean:6599] generated RSA certificate
 cert. version     : 3
 serial number     : FD:44:81:8C:AB:61:CF:8D:86:7D:14:E7:63:50:29:18
 issuer name       : CN=localhost
 subject name      : CN=localhost
 issued  on        : 2023-03-20 17:44:55
 expires on        : 2024-03-21 17:44:55
 signed using      : RSA with SHA-256
 RSA key size      : 2048 bits
 basic constraints : CA=false
 subject alt name  :
     dNSName : localhost
     dNSName : *.localhost
     dNSName : localhost.localdomain
     dNSName : *.localhost.localdomain
     iPAddress : 127.0.0.1
     iPAddress : 192.168.1.12
 key usage         : Digital Signature, Key Encipherment
 ext key usage     : TLS Web Server Authentication, TLS Web Client Authentication
V2023-03-21T10:44:55+000021:tool/net/redbean.c:680:redbean:6599] (ssl) using RSA certificate "CN=localhost" for HTTPS server
D2023-03-21T10:44:55+001841:tool/net/redbean.c:2870:redbean:6599] (srvr) opening browser with command "/usr/bin/xdg-open" http://127.0.0.1:8080/
D2023-03-21T10:44:55+022644:tool/net/redbean.c:7126:redbean:6599] ReplEventLoop()
D2023-03-21T10:44:55+000096:tool/net/redbean.c:7095:redbean:6599] (repl) event loop
need to run as root or suid
>: 

It may be worth noting that running the command "/usr/bin/xdg-open" http://127.0.0.1:8080/ does work if I run it in my shell.

ptgolden commented 1 year ago

This code in .init.lua fails with the same message:

unix = require 'unix'
unix.execve('/snap/bin/firefox', {'/snap/bin/firefox', '--version'}, {})
unix.exit(1)
$ ./redbean.com 
need to run as root or suid

However, calling a non-snap version of Firefox works fine:

unix = require 'unix'
unix.execve('/home/ptgolden/Code/tools/firefox/firefox', {'/home/ptgolden/Code/tools/firefox/firefox', '--version'}, {})
unix.exit(1)
$ ./redbean.com 
Mozilla Firefox 97.0.1

This is certainly an issue with snaps, not with redbean. Unfortunately, the default method of installing Firefox and Chromium on Ubuntu is now snaps.