Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont run browser as root #5058

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

halfline
Copy link
Contributor

@halfline halfline commented Aug 20, 2023

Right now firefox gets run as root which it really doesn't like doing. We have a workaround in place (unset XAUTHORITY) to prevent it from even erroring on start up.

There's no good reason to run it as root though. We can just run it unprivileged since all the heavy lifting is in privileged backend code anyway.

@@ -66,21 +66,23 @@ esac

# prepare empty firefox profile dir with theme based on the passed profile id
FIREFOX_THEME_DIR="/usr/share/anaconda/firefox-theme"
FIREFOX_PROFILE_PATH="/tmp/anaconda-firefox-profile"
LIVEUSER=$(id -n -u $PKEXEC_UID)
Copy link
Contributor

Choose a reason for hiding this comment

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

So this same script is also used on the boot.iso to run the Web UI there & I don't think there is a live user account available there. I'll try to build a boot.iso with this PR & also a Live image when I'm at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be okay, if $PKEXEC_UID is unset LIVEUSER should just get set to the current running user.

Maybe the variable LIVEUSER could have a better name (INSTALLER_USER?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course that means firefox continues to run as root on boot.iso, which is less than ideal, but it shouldn't complain in that case, because it won't think it's a user elevated to root, but root all the way through

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think renaming the variable would be best, plus maybe a comment we expect it to be liveuser on live?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think renaming the variable would be best, plus maybe a comment we expect it to be liveuser on live?

Agreed with both.

@M4rtinK
Copy link
Contributor

M4rtinK commented Aug 21, 2023

/boot-iso --webui

ui/webui/webui-desktop Fixed Show resolved Hide resolved
ui/webui/webui-desktop Fixed Show resolved Hide resolved
@github-actions
Copy link

boot.iso built successfully based on commit b3cd860. Download it from the bottom of the job status page.

@VladimirSlavik
Copy link
Contributor

/kickstart-test --testtype smoke

@VladimirSlavik
Copy link
Contributor

So, I triggered the tests and it looks like something did not work for webui...

machine_core.exceptions.Failure: SSH master process exited with code: 255

@halfline
Copy link
Contributor Author

So, I triggered the tests and it looks like something did not work for webui...

machine_core.exceptions.Failure: SSH master process exited with code: 255

hmm i just tried it locally again, and it seems to work fine here. do you have more logs ?

@halfline
Copy link
Contributor Author

note this pull request will need some changes if #5057 lands first

(we'll need to stop unsetting XAUTHORITY and XDG_RUNTIME_DIR in webui-desktop)

@halfline
Copy link
Contributor Author

i've now rebased this on top of #5057 so let's not land this until it lands.

@halfline halfline mentioned this pull request Sep 5, 2023
readarray -t user_environment < <(pkexec --user "${INSTALLER_USER}" env XDG_RUNTIME_DIR="/run/user/${PKEXEC_UID}" systemctl --user show-environment)

for variable in "${user_environment[@]}"; do
export "$variable"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shellcheck says:

data/liveinst/liveinst:34:16: warning: This does not export 'variable'. Remove $/${} for that, or use ${var?} to quiet. [SC2163]

If you know what you're doing (you do), alternatively, # shellcheck disable=SC2163

@M4rtinK
Copy link
Contributor

M4rtinK commented Sep 6, 2023

I strongly suggest we only merge this after we are done with F39 Beta, as I don't think we will realistically have the time to properly test this and fix any possible breakage.

readarray -t user_environment < <(pkexec --user "${INSTALLER_USER}" env XDG_RUNTIME_DIR="/run/user/${PKEXEC_UID}" systemctl --user show-environment)

for variable in "${user_environment[@]}"; do
export "$variable"

Check warning

Code scanning / shellcheck

This does not export 'variable'. Remove $/${} for that, or use ${var?} to quiet. Warning

This does not export 'variable'. Remove $/${} for that, or use ${var?} to quiet.
@M4rtinK
Copy link
Contributor

M4rtinK commented Sep 18, 2023

Rebased on top of latest master & pushed the updated version.

@M4rtinK
Copy link
Contributor

M4rtinK commented Sep 18, 2023

/kickstart-test --testtype smoke

@M4rtinK
Copy link
Contributor

M4rtinK commented Sep 18, 2023

/build-image --live

@M4rtinK
Copy link
Contributor

M4rtinK commented Sep 18, 2023

/boot-iso --webui

@M4rtinK
Copy link
Contributor

M4rtinK commented Sep 18, 2023

@halfline Just a heads up that I had to rewrite the first commit message a bit as some of the changes I've previously cherry-picked to the Firefox styling PR that has been merged a while ago. :)

@github-actions
Copy link

Images built based on commit cb62a85:

  • Live: success

Download the images from the bottom of the job status page.

@M4rtinK
Copy link
Contributor

M4rtinK commented Sep 19, 2023

/boot-iso --webui

@M4rtinK
Copy link
Contributor

M4rtinK commented Sep 19, 2023

/build-image --boot.iso --webui

@github-actions
Copy link

github-actions bot commented Oct 9, 2023

Images built based on commit a1de17d:

  • boot.iso: success

  • Live: success

Download the images from the bottom of the job status page.

@M4rtinK
Copy link
Contributor

M4rtinK commented Oct 11, 2023

So status as of today:

  • boot.iso starts the Firefox webview that immediately terminates, so far I have not found any suspicious log messages in Journal that would say why but I will continue to look
  • Live image, directly from GIS - almost immediate reboot, likely same issue - web view starting & terminating immediately (will have to patch this to not reboot immediately after the Firefox process terminates so I can grab logs, if any)
  • Live image, launched from desktop - I was actually able to launch the Web UI & install successfully
    • there are still some strange errors, that are visible if you launch Anaconda from the terminal using the liveinst script:
umount: /mnt/sysimage/tmp: must be superuser to unmount.
umount: /mnt/sysimage/sys/fs/selinux: must be superuser to unmount.
umount: /mnt/sysimage/sys: must be superuser to unmount.
umount: /mnt/sysimage/run: must be superuser to unmount.
umount: /mnt/sysimage/proc: must be superuser to unmount.
umount: /mnt/sysimage/home: must be superuser to unmount.
umount: /mnt/sysimage/dev/shm: must be superuser to unmount.
umount: /mnt/sysimage/dev/pts: must be superuser to unmount.
umount: /mnt/sysimage/dev: must be superuser to unmount.
umount: /mnt/sysimage/boot: must be superuser to unmount.
umount: /mnt/sysimage: must be superuser to unmount.
sr0: Failed to write 'change' to '/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sr0/uevent': Permission denied
sda: Failed to write 'change' to '/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sda/uevent': Permission denied
sda1: Failed to write 'change' to '/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sda/sda1/uevent': Permission denied
sda2: Failed to write 'change' to '/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sda/sda2/uevent': Permission denied
sda3: Failed to write 'change' to '/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sda/sda3/uevent': Permission denied
loop0: Failed to write 'change' to '/sys/devices/virtual/block/loop0/uevent': Permission denied
loop1: Failed to write 'change' to '/sys/devices/virtual/block/loop1/uevent': Permission denied
loop2: Failed to write 'change' to '/sys/devices/virtual/block/loop2/uevent': Permission denied
zram0: Failed to write 'change' to '/sys/devices/virtual/block/zram0/uevent': Permission denied
dm-0: Failed to write 'change' to '/sys/devices/virtual/block/dm-0/uevent': Permission denied
dm-1: Failed to write 'change' to '/sys/devices/virtual/block/dm-1/uevent': Permission denied
Traceback (most recent call last):
  File "/usr/lib64/python3.12/site-packages/gi/overrides/BlockDev.py", line 1226, in wrapped
    ret = orig_obj(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/gi/overrides/BlockDev.py", line 866, in lvm_lvs
    return _lvm_lvs(vg_name)
           ^^^^^^^^^^^^^^^^^
gi.repository.GLib.GError: g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Sender is not authorized to send message (9)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/anaconda-cleanup", line 82, in <module>
    devicetree.populate(cleanup_only=True)
  File "/usr/lib/python3.12/site-packages/blivet/threads.py", line 53, in run_with_lock
    return m(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/blivet/populator/populator.py", line 446, in populate
    self._populate()
  File "/usr/lib/python3.12/site-packages/blivet/threads.py", line 53, in run_with_lock
    return m(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/blivet/populator/populator.py", line 490, in _populate
    self.handle_device(dev)
  File "/usr/lib/python3.12/site-packages/blivet/threads.py", line 53, in run_with_lock
    return m(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/blivet/populator/populator.py", line 284, in handle_device
    self._add_name(name)
  File "/usr/lib/python3.12/site-packages/blivet/threads.py", line 53, in run_with_lock
    return m(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/blivet/populator/populator.py", line 146, in _add_name
    if name not in self.names:
                   ^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/blivet/threads.py", line 53, in run_with_lock
    return m(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/blivet/devicetree.py", line 148, in names
    lv_info = list(lvs_info.cache.keys())
                   ^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/blivet/static_data/lvm_info.py", line 44, in cache
    lvs = blockdev.lvm.lvs()
          ^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/site-packages/gi/overrides/BlockDev.py", line 1248, in wrapped
    raise transform[1](msg)
gi.overrides.BlockDev.LVMError: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Sender is not authorized to send message
anaconda must be run as root.
/usr/sbin/setenforce:  security_setenforce() failed:  Permission denied

Looks like the PR might have dropped root privileges not just from the Firefox process or also from the launching script ofr even the backend ? Definitely does not look healthy.

The titlebar with "Mozilla Firefox" has been fixed but there
are some more bits that can be cleaned up.

This commit achieves that by:

1. Make sure more of the environment is bubbled through anaconda to
   the webui launcher. In particular, we need XDG_CURRENT_DESKTOP, but
   this commit brings it all through, so firefox runs in an environment
   as close to getting run directly by the live user as possible.
2. Two exceptions are XAUTHORITY and XDG_RUNTIME_DIR which need to
   remain unset until we can run firefox as a normal user instead of root.
At the moment most of the firefox command line is getting placed
in a variable named $BROWSER and then getting run as

$BROWSER http://url

This only works if $BROWSER is at the very front of the line or if
it's run through eval.

Instead, make BROWSER into an array so it's positional arguments
get expanded positionally.
It's not a good idea to run UI code as root if we can help it, and
since the webui separates front end from backend, we don't need to
run the front end code as root.

This commit changes webui-desktop to start firefox as the liveuser.

The entire script could probably be run unprivileged with a few
changes to the cockpit parts (different port, new polkit policy,
cockpit.spawn changes to run as superuser), but that's a change
for another time.
@M4rtinK
Copy link
Contributor

M4rtinK commented Oct 23, 2023

/build-image --boot.iso --live --webui

@github-actions
Copy link

Images built based on commit 28ea45b:

  • boot.iso: success

  • Live: failure

Download the images from the bottom of the job status page.

@M4rtinK
Copy link
Contributor

M4rtinK commented Oct 23, 2023

/kickstart-test --testtype smoke

@M4rtinK
Copy link
Contributor

M4rtinK commented Oct 23, 2023

/build-image --live

@github-actions
Copy link

Images built based on commit 28ea45b:

  • Live: success

Download the images from the bottom of the job status page.

@jkonecny12
Copy link
Member

Hi all, I was just pinged by Red Hatters who tested accessibility of web UI. They found that our solution doesn't work because root applications don't have access to accessibility DBus. So, I think this information is raising a priority to merge this.

@KKoukiou
Copy link
Contributor

KKoukiou commented Nov 7, 2023

Hi all, I was just pinged by Red Hatters who tested accessibility of web UI. They found that our solution doesn't work because root applications don't have access to accessibility DBus. So, I think this information is raising a priority to merge this.

I don't see how org.a11y.Bus is involved here. Can you ask for some more insights? Is the testing of the accessibility prohibited or the accessibility of the new UI itself is hindered? I am assuming it's the former?

@tyrylu
Copy link

tyrylu commented Nov 7, 2023

Before this MR, unfortunately the latter. I have no idea how a root process can even find the correct a11y bus. And I can't test with a test image without building a new one of this PR, as they're all expired now.

@VladimirSlavik
Copy link
Contributor

/build-image --live

Copy link

github-actions bot commented Nov 7, 2023

Images built based on commit 28ea45b:

  • Live: failure

Download the images from the bottom of the job status page.

Copy link

github-actions bot commented Jan 7, 2024

This PR is stale because it has been open 60 days with no activity.
Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the stale label Jan 7, 2024
@tyrylu
Copy link

tyrylu commented Jan 8, 2024

Could we push this forward, please? From the perspective of a11y, we'd have to do a huge and ugly environment variables hack to tell the browser about the unprivileged a11y bus, or we do it cleanly.

@KKoukiou
Copy link
Contributor

KKoukiou commented Jan 8, 2024

@tyrylu thanks for ping. I added this in our current quarter planning. I see the current pr is terribly outdated, it needs a nontrivial amount of work.

@tyrylu
Copy link

tyrylu commented Jan 8, 2024

Thanks for that. But, if I could set the criteria, when the web UI is the default (no idea when that's planned), and this is not resolved, I'd call it a critical regression, of course, only for the users needing Orca, I know...

Copy link

This PR is stale because it has been open 60 days with no activity.
Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the stale label Apr 30, 2024
@tyrylu
Copy link

tyrylu commented Apr 30, 2024

Alright, now, F41 has the web-ui installer, and this situation is not resolved, so, we have a return to the dark ages where a visually impaired person could not install an OS...

@github-actions github-actions bot removed the stale label May 1, 2024
@jkonecny12
Copy link
Member

We are currently working on even keep it there. It's still not accepted by FESCO. We definitely want to add this, however first we need to resolve how to keep Web UI in Fedora 😔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants