[GH-ISSUE #397] Make all programs start with firejail automatically #288

Closed
opened 2026-05-05 05:31:40 -06:00 by gitea-mirror · 17 comments
Owner

Originally created by @ghost on GitHub (Mar 31, 2016).
Original GitHub issue: https://github.com/netblue30/firejail/issues/397

Is there a way to tell firejail to start all userspace programs with it automatically? If not can it be added?

Originally created by @ghost on GitHub (Mar 31, 2016). Original GitHub issue: https://github.com/netblue30/firejail/issues/397 Is there a way to tell firejail to start all userspace programs with it automatically? If not can it be added?
gitea-mirror 2026-05-05 05:31:40 -06:00
Author
Owner

@netblue30 commented on GitHub (Apr 1, 2016):

It is kind of difficult, it would require same sort of kernel support. So far we can only start firejail automatically if the application is started from a .desktop file. Such is the case with desktop manager menus and icons, or from command line. The relevant information is this:

DESKTOP INTEGRATION
       A  symbolic link to /usr/bin/firejail under the name of a program, will
       start the program in Firejail sandbox.  The  symbolic  link  should  be
       placed  in  the  first $PATH position. On most systems, a good place is
       /usr/local/bin directory. Example:

              Make a firefox symlink to /usr/bin/firejail:

              $ ln -s /usr/bin/firejail /usr/local/bin/firefox

              Verify $PATH

              $ which -a firefox
              /usr/local/bin/firefox
              /usr/bin/firefox

              Starting firefox in this moment, automatically invokes “firejail
              firefox”.

       This  works  for  clicking on desktop environment icons, menus etc. Use
       "firejail --tree" to verify the program is sandboxed.

              $ firejail --tree
              1189:netblue:firejail firefox
                1190:netblue:firejail firefox
                  1220:netblue:/bin/sh -c "/usr/lib/firefox/firefox"
                    1221:netblue:/usr/lib/firefox/firefox

<!-- gh-comment-id:204366191 --> @netblue30 commented on GitHub (Apr 1, 2016): It is kind of difficult, it would require same sort of kernel support. So far we can only start firejail automatically if the application is started from a .desktop file. Such is the case with desktop manager menus and icons, or from command line. The relevant information is this: ``` DESKTOP INTEGRATION A symbolic link to /usr/bin/firejail under the name of a program, will start the program in Firejail sandbox. The symbolic link should be placed in the first $PATH position. On most systems, a good place is /usr/local/bin directory. Example: Make a firefox symlink to /usr/bin/firejail: $ ln -s /usr/bin/firejail /usr/local/bin/firefox Verify $PATH $ which -a firefox /usr/local/bin/firefox /usr/bin/firefox Starting firefox in this moment, automatically invokes “firejail firefox”. This works for clicking on desktop environment icons, menus etc. Use "firejail --tree" to verify the program is sandboxed. $ firejail --tree 1189:netblue:firejail firefox 1190:netblue:firejail firefox 1220:netblue:/bin/sh -c "/usr/lib/firefox/firefox" 1221:netblue:/usr/lib/firefox/firefox ```
Author
Owner

@HulaHoopWhonix commented on GitHub (Apr 8, 2016):

What if something like incron is used to monitor the filesystem and execute the firejail command upon detecting the start-up of a program file which has a confinement profile? The original access would be terminated by closing the file and instead the firejail command is executed in its place.

(inotify cron daemon) is a daemon which monitors filesystem events (such as add a new file, delete a file and so on) and executes commands or shell scripts. It’s use is generally similar to cron.

http://www.cyberciti.biz/faq/linux-inotify-examples-to-replicate-directories/

Available in Debian:

https://packages.debian.org/stretch/incron

EDIT:

Additionally there could be a global setting that forces any other programs without profiles to run under the generic one which is a step up in protection even if its not as secure as a tailored profile.

END OF EDIT


If the above idea doesn't work, the way Oz is doing this is:

Enabling a profile

Once installed you can enable profiles using the oz-setup command as such (using the profile for the 'evince' application):

$ sudo oz-setup install evince

This will install a symlink to the oz client executable in place of the original, the original executable will be moved to dirname(path)-oz/basename(path).unsafe. This behavior can be altered using the divert_path and divert_suffix configuration flags.
Disabling a profile

If you want to disable a profile that you're not using or prior to uninstalling Oz, you can run the following command (once again with 'evince' as the target application):

$ sudo oz-setup remove evince

If you have already uninstalled Oz you can remove the divertions manually using the dpkg-divert command.

https://github.com/subgraph/oz

<!-- gh-comment-id:207639643 --> @HulaHoopWhonix commented on GitHub (Apr 8, 2016): What if something like incron is used to monitor the filesystem and execute the firejail command upon detecting the start-up of a program file which has a confinement profile? The original access would be terminated by closing the file and instead the firejail command is executed in its place. > (inotify cron daemon) is a daemon which monitors filesystem events (such as add a new file, delete a file and so on) and executes commands or shell scripts. It’s use is generally similar to cron. http://www.cyberciti.biz/faq/linux-inotify-examples-to-replicate-directories/ Available in Debian: https://packages.debian.org/stretch/incron EDIT: Additionally there could be a global setting that forces any other programs without profiles to run under the generic one which is a step up in protection even if its not as secure as a tailored profile. END OF EDIT --- If the above idea doesn't work, the way Oz is doing this is: > Enabling a profile > > Once installed you can enable profiles using the oz-setup command as such (using the profile for the 'evince' application): > > $ sudo oz-setup install evince > > This will install a symlink to the oz client executable in place of the original, the original executable will be moved to dirname(path)-oz/basename(path).unsafe. This behavior can be altered using the divert_path and divert_suffix configuration flags. > Disabling a profile > > If you want to disable a profile that you're not using or prior to uninstalling Oz, you can run the following command (once again with 'evince' as the target application): > > $ sudo oz-setup remove evince > > If you have already uninstalled Oz you can remove the divertions manually using the dpkg-divert command. https://github.com/subgraph/oz
Author
Owner

@netblue30 commented on GitHub (Apr 9, 2016):

inotify: the problem is by the time you get the notification, the kernel already started the program. The events you receive from the kernel are asynchronous.

For Oz people is easy, they are a distribution and they can control what gets installed on the user system. On a regular disro, once you update a program like Firefox, the update will replace the link with whatever is in the new package.

<!-- gh-comment-id:207817520 --> @netblue30 commented on GitHub (Apr 9, 2016): inotify: the problem is by the time you get the notification, the kernel already started the program. The events you receive from the kernel are asynchronous. For Oz people is easy, they are a distribution and they can control what gets installed on the user system. On a regular disro, once you update a program like Firefox, the update will replace the link with whatever is in the new package.
Author
Owner

@HulaHoopWhonix commented on GitHub (Apr 10, 2016):

Orthogonal to the first idea is to use some form of hooking https://en.wikipedia.org/wiki/Hooking#Linux to control the execution of other processes. ptrace might not work on Grsec kernels however.

For Oz people is easy, they are a distribution and they can control what gets installed on the user system. On a regular disro, once you update a program like Firefox, the update will replace the link with whatever is in the new package.

You can use Dpkg hooks (DPkg::Post-Invoke) to ensure symlinks are maintained even across software updates.

<!-- gh-comment-id:207893272 --> @HulaHoopWhonix commented on GitHub (Apr 10, 2016): Orthogonal to the first idea is to use some form of hooking https://en.wikipedia.org/wiki/Hooking#Linux to control the execution of other processes. ptrace might not work on Grsec kernels however. > For Oz people is easy, they are a distribution and they can control what gets installed on the user system. On a regular disro, once you update a program like Firefox, the update will replace the link with whatever is in the new package. You can use Dpkg hooks (DPkg::Post-Invoke) to ensure symlinks are maintained even across software updates.
Author
Owner

@netblue30 commented on GitHub (Apr 10, 2016):

Ptrace syscall is disabled by seccomp.

Dpkg hooks will give firejail too much control over the user desktop, I think we should stay away. The user still can implement it, but for us to change how the package manager works would be very intrusive.

<!-- gh-comment-id:207987805 --> @netblue30 commented on GitHub (Apr 10, 2016): Ptrace syscall is disabled by seccomp. Dpkg hooks will give firejail too much control over the user desktop, I think we should stay away. The user still can implement it, but for us to change how the package manager works would be very intrusive.
Author
Owner

@FedericoCeratto commented on GitHub (Apr 10, 2016):

dpkg-divert and update-alternatives, used together, can do the trick - but for one application at a time:

# Create a wrapper
cat > /opt/firejail_shim <<EOF
#!/bin/sh
/usr/bin/firejail $0.firejailed
EOF
chmod +x /opt/firejail_shim

# Divert the real binary
dpkg-divert --divert /usr/bin/nmap.firejailed --rename /usr/bin/nmap
update-alternatives --install /usr/bin/nmap nmap /opt/firejail_shim 40

# Now /usr/bin/nmap is a symlink that will run the wrapper that will run firejail
file /usr/bin/nmap

# Reinstalling nmap will not break this little kludge
apt-get install --reinstall nmap

# Cleanup
update-alternatives --remove nmap /opt/firejail_shim; dpkg-divert --remove /usr/bin/nmap; rm /opt/firejail_shim
<!-- gh-comment-id:208001280 --> @FedericoCeratto commented on GitHub (Apr 10, 2016): dpkg-divert and update-alternatives, used together, can do the trick - but for one application at a time: ``` bash # Create a wrapper cat > /opt/firejail_shim <<EOF #!/bin/sh /usr/bin/firejail $0.firejailed EOF chmod +x /opt/firejail_shim # Divert the real binary dpkg-divert --divert /usr/bin/nmap.firejailed --rename /usr/bin/nmap update-alternatives --install /usr/bin/nmap nmap /opt/firejail_shim 40 # Now /usr/bin/nmap is a symlink that will run the wrapper that will run firejail file /usr/bin/nmap # Reinstalling nmap will not break this little kludge apt-get install --reinstall nmap # Cleanup update-alternatives --remove nmap /opt/firejail_shim; dpkg-divert --remove /usr/bin/nmap; rm /opt/firejail_shim ```
Author
Owner

@HulaHoopWhonix commented on GitHub (Apr 10, 2016):

Dpkg hooks will give firejail too much control over the user desktop, I think we should say away. The user still can implement it, but for us to change how the package manager works would be very intrusive.

Not really. GRsec's paxctl uses a similar technique for re-applying PaX flags to updated binaries. You can make this behavior optional on Firejail's first start by asking the user if they want to enable it.

Automatically starting programs under protection is the single biggest usability feature IMO. A regular user should not have to use the command line or even know what a symlink is to benefit from Firejail. Making this opt-in sets the right balance.


Lets say a user wants to easily reverse this for some specific program. Firetools should immediately delete the symlink for any application whose icon is dragged outside its widget.

<!-- gh-comment-id:208012149 --> @HulaHoopWhonix commented on GitHub (Apr 10, 2016): > Dpkg hooks will give firejail too much control over the user desktop, I think we should say away. The user still can implement it, but for us to change how the package manager works would be very intrusive. Not really. GRsec's paxctl uses a similar technique for re-applying PaX flags to updated binaries. You can make this behavior optional on Firejail's first start by asking the user if they want to enable it. Automatically starting programs under protection is the single biggest usability feature IMO. A regular user should not have to use the command line or even know what a symlink is to benefit from Firejail. Making this opt-in sets the right balance. --- Lets say a user wants to easily reverse this for some specific program. Firetools should immediately delete the symlink for any application whose icon is dragged outside its widget.
Author
Owner

@requiredregistration commented on GitHub (Apr 11, 2016):

an ignorant and careless user will never be safe for long.

ease of use is something good, but making it easier to use must never lower security.

<!-- gh-comment-id:208175070 --> @requiredregistration commented on GitHub (Apr 11, 2016): an ignorant and careless user will never be safe for long. ease of use is something good, but making it easier to use must never lower security.
Author
Owner

@adrelanos commented on GitHub (Apr 19, 2016):

So far we can only start firejail automatically if the application is started from a .desktop file.

Which is problematic, since lots of users occasionally also start applications from the command line.

Dpkg hooks will give firejail too much control over the user desktop, I think we should stay away. The user still can implement it, but for us to change how the package manager works would be very intrusive.

So perhaps implemented in a separate optional package?

it would require same sort of kernel support.

Are the kernel developers already aware of the need for this feature? Is there a feature request already? Is this something you could implement into the kernel?

<!-- gh-comment-id:212075471 --> @adrelanos commented on GitHub (Apr 19, 2016): > So far we can only start firejail automatically if the application is started from a .desktop file. Which is problematic, since lots of users occasionally also start applications from the command line. > Dpkg hooks will give firejail too much control over the user desktop, I think we should stay away. The user still can implement it, but for us to change how the package manager works would be very intrusive. So perhaps implemented in a separate optional package? > it would require same sort of kernel support. Are the kernel developers already aware of the need for this feature? Is there a feature request already? Is this something you could implement into the kernel?
Author
Owner

@ghost commented on GitHub (Apr 19, 2016):

@netblue30 Please reopen the issue

<!-- gh-comment-id:212100691 --> @ghost commented on GitHub (Apr 19, 2016): @netblue30 Please reopen the issue
Author
Owner

@netblue30 commented on GitHub (Apr 20, 2016):

Reopened!

<!-- gh-comment-id:212406105 --> @netblue30 commented on GitHub (Apr 20, 2016): Reopened!
Author
Owner

@HulaHoopWhonix commented on GitHub (May 10, 2016):

@netblue30 why didn't you mention firecfg? It does what I was looking for and the symlinks survive package upgrades :)

One thing I ran into was firecfg didn't create symlinks for Iceweasel although its installed and has a supported profile.

The link is created for firefox (which is rebranded on Debian to Iceweasel) but all the links on the system point to the name of the latter.

$ sudo firecfg --list
/usr/local/bin/icedove
/usr/local/bin/vlc
/usr/local/bin/xchat
/usr/local/bin/firefox

<!-- gh-comment-id:218048781 --> @HulaHoopWhonix commented on GitHub (May 10, 2016): @netblue30 why didn't you mention firecfg? It does what I was looking for and the symlinks survive package upgrades :) One thing I ran into was firecfg didn't create symlinks for Iceweasel although its installed and has a supported profile. The link is created for firefox (which is rebranded on Debian to Iceweasel) but all the links on the system point to the name of the latter. $ sudo firecfg --list /usr/local/bin/icedove /usr/local/bin/vlc /usr/local/bin/xchat /usr/local/bin/firefox
Author
Owner

@HulaHoopWhonix commented on GitHub (May 10, 2016):

Turns out the problem is caused because the Iceweasel profile redirects to the Firefox one for confinement rules. To fix this a full custom rule-set is needed for Iceweasel because its directory names are different.

<!-- gh-comment-id:218175553 --> @HulaHoopWhonix commented on GitHub (May 10, 2016): Turns out the problem is caused because the Iceweasel profile redirects to the Firefox one for confinement rules. To fix this a full custom rule-set is needed for Iceweasel because its directory names are different.
Author
Owner

@netblue30 commented on GitHub (May 11, 2016):

The version in github repository decouples firefox and iceweasel profiles. Each one has its own file in /etc/firejail directory. I have a new release coming in about one week - hopefully!

This is what you can do if you are on 0.9.38:

Create a ~/.config/firejail directory

$ mkdir ~/.config/firejail

Copy firefox.profile there as iceweasel.profile

$ cp /etc/firejail/firefox.profile ~/.config/firejail/iceweasel.profile

Open ~/.config/firejail/iceweasel.profile in a text editor and modify it.

<!-- gh-comment-id:218447761 --> @netblue30 commented on GitHub (May 11, 2016): The version in github repository decouples firefox and iceweasel profiles. Each one has its own file in /etc/firejail directory. I have a new release coming in about one week - hopefully! This is what you can do if you are on 0.9.38: Create a ~/.config/firejail directory ``` $ mkdir ~/.config/firejail ``` Copy firefox.profile there as iceweasel.profile ``` $ cp /etc/firejail/firefox.profile ~/.config/firejail/iceweasel.profile ``` Open ~/.config/firejail/iceweasel.profile in a text editor and modify it.
Author
Owner

@HulaHoopWhonix commented on GitHub (May 11, 2016):

Thank you. Sounds good. Feel free to close this ticket as the original topic has been covered.

EDIT:

I noticed a typo in the manpage where --clear is mentioned though it has been deprecated in favor of --clean.

https://firejail.wordpress.com/features-3/man-firecfg/

<!-- gh-comment-id:218496216 --> @HulaHoopWhonix commented on GitHub (May 11, 2016): Thank you. Sounds good. Feel free to close this ticket as the original topic has been covered. EDIT: I noticed a typo in the manpage where --clear is mentioned though it has been deprecated in favor of --clean. https://firejail.wordpress.com/features-3/man-firecfg/
Author
Owner

@netblue30 commented on GitHub (May 12, 2016):

clear/clean is fixed in git.

<!-- gh-comment-id:218785763 --> @netblue30 commented on GitHub (May 12, 2016): clear/clean is fixed in git.
Author
Owner

@hfont commented on GitHub (Feb 24, 2019):

Would it be possible to do this in the shell?

I was looking at this code here:

https://unix.stackexchange.com/questions/250713/modify-all-bash-commands-through-a-program-before-executing-them

<!-- gh-comment-id:466729786 --> @hfont commented on GitHub (Feb 24, 2019): Would it be possible to do this in the shell? I was looking at this code here: [https://unix.stackexchange.com/questions/250713/modify-all-bash-commands-through-a-program-before-executing-them](https://unix.stackexchange.com/questions/250713/modify-all-bash-commands-through-a-program-before-executing-them)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#288
No description provided.