Firejail 是一款轻量级安全工具,旨在通过设置受限环境来运行(可能不受信任的)应用程序,从而保护 Linux 系统。
具体来说,它是一个 SUID 沙箱程序,通过使用 Linux 命名空间(namespaces)、seccomp-bpf 和 Linux capabilities 来降低发生安全破坏的风险。它允许一个进程及其所有子进程拥有对全局共享内核资源(如网络栈、进程表和挂载表)的私有视图。Firejail 可以在 SELinux 或 AppArmor 环境中运行,并且已与 Linux 控制组(Control Groups)集成。
该软件使用 C 语言编写,几乎没有依赖项,可在任何运行 3.x 或更高版本内核的 Linux 计算机上运行。它可以对任何类型的进程进行沙箱化:服务器、图形应用程序,甚至用户登录会话。该软件包含许多常见 Linux 程序的沙箱配置文件,例如 Mozilla Firefox、Chromium、VLC、Transmission 等。
沙箱非常轻量,开销很低。无需编辑复杂的配置文件,无需打开套接字连接,也无需在后台运行守护进程。所有安全功能都直接在 Linux 内核中实现,并可在任何 Linux 计算机上使用。
参见 SECURITY.md。
受支持的版本请参见 SECURITY.md。
注意:Debian stable 和 backports 中的版本可能已经过时,因此目前我们建议从最新版本下载并安装 .deb 软件包:
或者从源码构建。
Debian stable(bullseye):我们建议使用 backports 软件包。
注意:发行版和 PPA 中的版本可能已经过时,因此目前我们建议从最新版本下载并安装 .deb 软件包:
或者从源码构建。
注意:PPA 建议主要针对 firejail 本身;如果 firetools 和 firejail 相关工具不在 PPA 中,直接从发行版安装也没有问题,因为它们往往更新频率较低。
对于 Ubuntu 18.04+ 及其衍生版本(如 Linux Mint),强烈建议用户使用 PPA。
如何添加并从 PPA 安装:
sudo add-apt-repository ppa:deki/firejail
sudo apt-get update
sudo apt-get install firejail firejail-profiles
原因:Ubuntu 20.04 的 firejail 软件包在 Launchpad 上发布补丁后数月内,仍存在 CVE-2021-26910 漏洞:
另请参阅 https://wiki.ubuntu.com/SecurityTeam/FAQ:
Ubuntu 安全团队支持哪些软件?
Ubuntu 目前分为四个组件:main、restricted、universe 和 multiverse。main 和 restricted 中的所有二进制软件包在 Ubuntu 版本的生命周期内均由 Ubuntu 安全团队提供支持,而 universe 和 multiverse 中的二进制软件包则由 Ubuntu 社区提供支持。
此外,PPA 版本可能更新,并且包含更多配置文件修复。
详情请参阅以下讨论:
Firejail 可用于多个 Linux 发行版:
除上述例外情况外,只要您的发行版提供受支持版本的 firejail,通常建议从发行版安装。
安装后可通过 firejail --version 检查版本。
您也可以安装已发布的软件包之一。
从源码构建并安装当前开发版本的说明。
在适用的情况下,建议使用下面针对特定发行版的说明,因为它们会生成原生软件包,从而更易于与系统其他部分集成并方便软件包管理。
对于其他发行版,请参阅通用说明。
另请参阅 .gitlab-ci.yml 了解如何在 CI 中完成特定发行版的构建。
注意:AUR 软件包并非由我们维护。
从 AUR 安装 firejail-git。
示例:
yay -S firejail-git
适用于 Debian、Ubuntu 及其衍生版本:
注意:任何 ./configure 标志都应传递给 mkdeb.sh(例如 ./mkdeb.sh --enable-foo)。
sudo apt-get update -qy
sudo apt-get install -qy \
git build-essential fakeroot lintian libapparmor-dev pkg-config gawk
git clone 'https://github.com/netblue30/firejail.git' &&
cd firejail &&
./configure &&
make dist &&
./mkdeb.sh &&
sudo dpkg -i ./*.deb &&
make installcheck
适用于 Fedora 及其衍生版本:
注意:任何 ./configure 标志都应传递给 mkrpm.sh(例如 ./platform/rpm/mkrpm.sh --enable-foo)。
sudo dnf update -y
sudo dnf install -y rpm-build gcc make
git clone 'https://github.com/netblue30/firejail.git' &&
cd firejail &&
./configure &&
make dist &&
./platform/rpm/mkrpm.sh &&
sudo rpm -i ./*.rpm &&
make installcheck
通用构建/安装说明:
git clone 'https://github.com/netblue30/firejail.git' &&
cd firejail &&
./configure &&
make -j "$(nproc)" &&
sudo make install-strip &&
make installcheck
在 Debian/Ubuntu 上,您需要安装 git 和 gcc。
若要启用 AppArmor 支持进行构建(通常用于 Debian、Ubuntu、openSUSE 及其衍生版本),请安装 AppArmor 开发库和 pkg-config,并使用 --enable-apparmor ./configure 选项:
sudo apt-get install git build-essential libapparmor-dev pkg-config gawk
若要启用 SELinux 支持进行构建(通常用于 Fedora、RHEL 及其衍生版本),请安装 libselinux1-dev(Fedora 上为 libselinux-devel),并使用 --enable-selinux ./configure 选项。
有关从 git 使用 firejail 的详细信息,请参阅 wiki。
注意:请确保使用程序的完整路径(例如,使用 firejail /usr/bin/firefox 而不是 firejail firefox),以避免潜在的 firejail 嵌套(firejail-in-firejail)问题(参见 #2877)。
要启动沙箱,请在命令前加上 firejail:
firejail /usr/bin/firefox # starting Mozilla Firefox
firejail /usr/bin/transmission-gtk # starting Transmission BitTorrent
firejail /usr/bin/vlc # starting VideoLAN Client
sudo firejail /etc/init.d/nginx start
在终端中运行 firejail --list 可列出所有活动沙箱。示例:
$ firejail --list
1617:netblue:/usr/bin/firejail /usr/bin/firefox-esr
7719:netblue:/usr/bin/firejail /usr/bin/transmission-qt
7779:netblue:/usr/bin/firejail /usr/bin/galculator
7874:netblue:/usr/bin/firejail /usr/bin/vlc --started-from-file file:///home/netblue/firejail-whitelist.mp4
7916:netblue:firejail --list
通过运行以下两条命令将您的沙箱集成到桌面:
firecfg --fix-sound
sudo firecfg
第一条命令解决了 PulseAudio 9.0 之前版本中的一些共享内存/PID 命名空间错误。第二条命令将 Firejail 集成到您的桌面中。您需要注销并重新登录才能应用 PulseAudio 更改。
以您习惯的方式启动程序:桌面管理器菜单、文件管理器、桌面启动器。
此集成适用于 Firejail 默认支持的所有程序。当前 Firejail 版本包含 900 多个默认应用程序,而且这个数字随着每个新版本不断增长。
我们将应用程序列表保存在 src/firecfg/firecfg.config(安装后位于 /etc/firejail/firecfg.config)。
大多数 Firejail 命令行选项都可以通过配置文件传递给沙箱。
您可以在 etc/(安装后为 /etc/firejail/)中找到所有受支持应用程序的配置文件。
我们还在 etc-fixes/ 中保留了针对先前发布版本的配置文件修复列表。
如果您在公共仓库中维护额外的 Firejail 安全配置文件,请提供链接给我们:
使用此 issue 来请求新的配置文件:
您也可以使用此工具获取程序所需的系统调用列表:
firecfg 会在 /usr/local/bin 中创建符号链接,因此要完全移除 firejail,请在卸载前运行以下命令:
sudo firecfg --clean
详情请参阅 man firecfg。
注意:在 $PATH 中搜索可执行文件时会忽略损坏的符号链接,因此不执行上述操作直接卸载也不会引发问题。
LANDLOCK
Landlock is a Linux security module first introduced in version 5.13 of
the Linux kernel. It allows unprivileged processes to restrict their
access to the filesystem. Once imposed, these restrictions can never
be removed, and all child processes created by a Landlock-restricted
processes inherit these restrictions. Firejail supports Landlock as an
additional sandboxing feature. It can be used to ensure that a sand‐
boxed application can only access files and directories that it was ex‐
plicitly allowed to access. Firejail supports populating the ruleset
with both a basic set of rules (see --landlock) and with a custom set
of rules.
Important notes:
- A process can install a Landlock ruleset only if it has either
CAP_SYS_ADMIN in its effective capability set, or the "No New
Privileges" restriction enabled. Because of this, enabling the
Landlock feature will also cause Firejail to enable the "No New
Privileges" restriction, regardless of the profile or the
--nonewprivs command line option.
- Access to the /proc directory is managed through the --land‐
lock.proc command line option.
- Access to the /etc directory is automatically allowed. To
override this, use the --writable-etc command line option. You
can also use the --private-etc option to restrict access to the
/etc directory.
To enable Landlock self-restriction on top of your current Firejail se‐
curity features, pass --landlock flag to Firejail command line. You
can also use --landlock.read, --landlock.write, --landlock.special and
--landlock.execute options together with --landlock or instead of it.
Example:
$ firejail --landlock --landlock.read=/media --landlock.proc=ro /usr/bin/mc
一个用于打印配置文件统计信息的小工具。照常编译并安装。该工具安装在 /usr/lib/firejail 目录中。
对 /etc/profiles 中的配置文件运行它:
$ /usr/lib/firejail/profstats /etc/firejail/*.profile
No include .local found in /etc/firejail/noprofile.profile
Warning: multiple caps in /etc/firejail/tidal-hifi.profile
Warning: multiple caps in /etc/firejail/tqemu.profile
Warning: multiple caps in /etc/firejail/transmission-daemon.profile
Warning: multiple caps in /etc/firejail/trivalent.profile
Stats:
profiles 1342
include local profile 1341 (include profile-name.local)
include globals 1307 (include globals.local)
blacklist ~/.ssh 1201 (include disable-common.inc)
seccomp 1213
capabilities 1335
noexec 1214 (include disable-exec.inc)
noroot 1105
memory-deny-write-execute 320
restrict-namespaces 1048
apparmor 869
private-bin 817
private-dev 1172
private-etc 842
private-cache 865
private-lib 86
private-tmp 1036
whitelist home directory 662
whitelist var 975 (include whitelist-var-common.inc)
whitelist run/user 1305 (include whitelist-runuser-common.inc
or blacklist ${RUNUSER})
whitelist usr/share 760 (include whitelist-usr-share-common.inc
net none 452
dbus-user none 766
dbus-user filter 206
dbus-system none 970
dbus-system filter 13
高级浏览器安全 |
Tor 浏览器安全 |