A few months ago I set this up and here is the write up on it since yesterday, while talking to a fellow Linux user, they found it intriguing.
Any URL I click in Slack, Signal desktop app, or launch via terminal actions should launch into the correct sandboxed, user-profile web browser instance (in precedence order):
https://github.com/<workorg>.*should open in theworkFirefox profilehttps://github.com/<sideproj>.*should open in thesideprojFirefox profilehttps://github.com/.*(all others) should open in thepersonalFirefox profile- All exclusively work related URLs should open in the
workFirefox profile (gathered URLs) https://twitter.com/.*should open inpersonalFirefox profile- All staging environment URLs should open in the
qaFirefox profile (which doesn’t have AdBlock Plus installed)
- Set
BROWSERenvironment variable to an executable script in myPATHnamedweb. - Create a
web.desktopfile in~/.local/share/applications/(seeweb.desktopin this snippet for the example) - Set this desktop file as the default web browser for GUI applications to know what to use to delegate URLs to open
browsers, running:
xdg-settings set default-web-browser web.desktop - Write
~/bin/webscript that inspects the URL given by the forwarding application and decides which browser profile to open a tab in. Usingfirejailto sandbox firefox and opera.
firefox -CreateProfile myemployerfirefox -CreateProfile sideprojfirefox -CreateProfile personal
Then downloaded the Firefox extensions I wanted to install:
rm -rf ~/.cache/web/addons
mkdir -p ~/.cache/web/addons
wget -O ~/.cache/web/addons/lastpass.xpi https://lastpass.com/lastpassffx/xpi.php
firefox -P myemployer ~/.cache/web/addons/lastpass.xpiThe last command launches the browser in GUI mode because installing an addon requires a prompt.
- TODO research how to automate without the GUI prompt and use the headless command-line option.
mkdir -p ~/.config/firejail- Find your profile directory paths, like so:
readlink -f ~/.mozilla/firefox/*.myemployer - Find your cache directory paths, like so:
readlink -f ~/.cache/mozilla/firefox/*.myemployer
These paths will be put into your firejail profile below:
Create ~/.config/firejail/web-myemployer.profile with the basic structure like so:
include firefox.local
include global.local
# You have to find the generated profile directory to put in here
noblacklist ${HOME}/.cache/mozilla/firefox/ydwbdjcx.myemployer
noblacklist ${HOME}/mozilla/firefox/ydwbdjcx.myemployer
whitelist ${HOME}/.cache/mozilla/firefox/ydwbdjcx.myemployer
whitelist ${HOME}/mozilla/firefox/ydwbdjcx.myemployer
Similarly for the other profiles needed.
To make firejail work on NixOS (or any other Linux distro) you need setup firejail with a setuid wrapper. Here is how you do that in NixOS specifically (other distro users are on your own):
In your system’s configuration.nix you will need to add something like this:
security.wrappers.firejail = {
source = "${pkgs.firejail}/bin/firejail";
};