Wanting to achieve something similar, I read through this thread, but believe I have found a simpler solution, taking some inspiration from debguy's earlier post. Perhaps my solution is not as secure as running the web browser in a jail, however it may well be 'good enough' and has minimum complexity, requiring neither a jail, nor having to use ssh, nor having to xhost + the display server.
Let's recap what I was trying to do when I found this useful and interesting thread. I have a single computer running freebsd 11 and X11. I want to have a 'clean' userid that is used for doing things like online banking. And I want to have a 'dirty' userid that can be used for general browsing anywhere on the web that might be exposed to picking up website browser exploits.
So I start by making two userids: 'clean' and 'dirty'. They both get separate home directories, and I set up the permissions so that neither can gain access to each others home directories, eg:-
drwxr-x--- 22 clean clean 1536 2 Jun 20:26 clean
drwxr-x--- 18 dirty dirty 3072 2 Jun 20:35 dirty
Assuming the machine is set up to run an X display manager (eg xdm), login as 'dirty'.
The X server is hence started as a process owned by 'dirty' userid.
Now dirty can start X clients like a browser without any further issue.
Most of time on the machine is spent logged in as 'dirty', but if I want to do something like read email or do some online banking, I would prefer to login as 'clean' and run a separate instance of the browser.
We can arrange for the 'clean' userid to also be able to run X clients on the same X display.
In an xterm, login as 'clean' by running
# login clean
Once logged in as 'clean', it will be found that attempts to run a client (eg another xterm) will be
rejected by the display server due to failed authorisation.
We don't need to resort to ssh'ing to localhost or unlocking the X server using xhost +;
there is instead a simpler method using xauth. The 'dirty' userid already has an xauth security
token to be allowed to run clients on the X server it started. This token can be exported by 'dirty' userid
and imported by 'clean' userid, which will then allow 'clean' to run clients on the X server owned by 'dirty'.
To set this up do the following:
1. in an xterm logged in as 'dirty', run
# xauth extract - $DISPLAY > /tmp/myauth
(Note that $DISPLAY should already have been set to :0)
2. In a separate xterm logged in as 'clean', run the command
# xauth merge /tmp/myauth
# export DISPLAY=:0 (I'm running bash)
Delete /tmp/myauth afterwards.
And hey presto, the 'clean' userid is now able to start any X client it desires running on the X server
owned by 'dirty' userid. So the 'clean' userid can now start a separate instance of the web browser.
Because there are two isloated home directories, each with their own browser cache and config,
there is no collision in the filesystem. And ps shows that the two web browser instances result in process trees owned by the two different userids, so there should be address space isolation between the two browser instances. Now 'clean' can go ahead and do his online banking, and 'dirty' can go mess around looking at general websites, in isolation from each other.
The nice thing about this approach is its simplicity; we don't need a jail, we don't need to ssh back in, and we don't need to open the server to other connections using xhost +. We just use the filesystem permissions and xauth security provided by the X server. I'm not qualified to say whether an approach like this would be safe from exploits like spectre and meltdown, but it might be good enough to keep a first level of isolation between websites that you want to keep private and general browsing. Especially if you don't go searching for dodgy warez sites in the 'dirty' browser ;-)
I would be interested in people's thoughts on this approach...