「Firejail」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
108行目: 108行目:
   
 
$ firejail --list
 
$ firejail --list
  +
  +
A more comprehensive output is produced by
  +
  +
$ firejail --tree
   
 
== カスタムのプロファイルを作成する ==
 
== カスタムのプロファイルを作成する ==

2022年5月22日 (日) 13:06時点における版

関連記事

Firejail は使いやすい SUID サンドボックスプログラムであり、Linux の名前空間や seccomp-bpf、Linux ケイパビリティを使うことで、信頼のおけないアプリケーションの実行環境を制限することにより、セキュリティ侵害のリスクを軽減します。

インストール

firejail または firejail-gitAUR パッケージをインストールしてください。Firejail で使用するためのGUIアプリケーション、firetools も用意されています。

ノート: Arch Linux の諸カーネルにおける user_namespaces(7) のサポートに関する情報は セキュリティ#アプリケーションのサンドボックス化 を見てください。Firejail は user_namespaces を使用できます(たとえ無効化されていたとしても)
警告: アップストリームでは徐々にホワイトリスト制が採用されつつありますが(/etc/firejail/firefox.profile を参照)、提供されているプロファイルの殆どがまだブラックリスト制に強く依存しています。これは、プロファイルによって明示的に禁止されていなければ、アプリケーションにアクセスを許してしまうことを意味します。例えば、btrfs のスナップショットを /mnt/btrfs に保存しているとします。隔離されたプログラムは $HOME/.ssh へのアクセスは禁じられているでしょうが、/mnt/btrfs/@some-snapshot/$HOME/.ssh へはアクセスできてしまいます。使用するプロファイルを検査するようにしてください。#プロファイルのテストを参照。

設定

ほとんどのユーザはカスタムの設定をする必要はないでしょう。その場合、#使用方法 に進むことができます。

Firejail は、サンドボックス内で実行されるアプリケーションのそれぞれに対してセキュリティ保護を設定するプロファイルを使用します。デフォルトのプロファイルは /etc/firejail/application.profile で見ることができます。含まれていないアプリケーションに対するカスタムのプロファイルが必要な場合や、デフォルトのプロファイルを変更したい場合、新しいルールや、デフォルトのプロファイルのコピーを ~/.config/firejail/ ディレクトリ内に置くことができます。1つのアプリケーションに対して複数のカスタムのプロファイルを設定することもでき、複数のアプリケーションの間で同一のプロファイルを共有させることもできます。

Firejail に特定のアプリケーションのプロファイルが存在しない場合、システム全体の制限付きデフォルトプロファイルを使用します。これにより、カスタムのプロファイルや制限を緩めたプロファイルを先に作成しないと、アプリケーションが期待通りに動作しない可能性があります。

firejail-profile(5) を参照してください。

使用方法

そのアプリケーションに対する firejail のデフォルトの保護(デフォルトのプロファイル)を使用してアプリケーションを実行するには、以下を実行します:

$ firejail <program name>

デフォルトプロファイルへの1回限りの追加は、コマンドラインオプションとして追加できます(マニュアルページを参照)。たとえば、seccomp 保護を使用して okular を実行するには、次のコマンドを実行します:

$ firejail --seccomp okular

1つのプログラムにデフォルト以外の複数のプロファイルを定義できます。プロファイルファイルを作成したら、次のコマンドを実行して使用できます:

$ firejail --profile=/absolute/path/to/profile <program name>

デフォルトで firejail を使う

Firejail のプロファイルを持つすべてのアプリケーションに対して Firejail を使用するようにするには、firecfg ツールを root として実行してください。

# firecfg

このツールは、Firejail がデフォルトのプロファイルを持つすべてのアプリケーションに対して、/usr/bin/firejail を指すシンボリックリンクを /usr/local/bin 内に作成します。

ヒント: pacman の操作のたびに、firecfg を自動で実行するには pacman フック を使用することができます:
/etc/pacman.d/hooks/firejail.hook
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Operation = Remove
Target = usr/bin/*
Target = usr/local/bin/*
Target = usr/share/applications/*.desktop

[Action]
Description = Configure symlinks in /usr/local/bin based on firecfg.config...
When = PostTransaction
Depends = firejail
Exec = /bin/sh -c 'firecfg &>/dev/null'

アプリケーションごとに手動で設定するには以下を実行してください:

# ln -s /usr/bin/firejail /usr/local/bin/<application>
ノート:
  • PATH 環境変数では、/usr/local/bin/usr/bin の前に設定する必要があります。
  • カスタムの Firejail の設定を使用してシンボリックリンクのプログラムを実行するには、#使用方法で書かれてあるように、単純に firejail を前につけて実行してください。
  • デーモンに対しては、systemd のユニットファイルを上書きして、デーモンが Firejail を呼び出すようにする必要があります。systemd#ユニットファイルの編集 を参照してください。
  • firecfg は一部の CLI シェルにおいて動作しません。例えば、tarcurlwgetgit。これらは手動でシンボリックリンクを作成する必要があります。
  • gzipxz へのシンボリックリンクは makepkglibfakeroot.so をプリロードする機能と干渉します。BBS#230913 を参照してください。
警告: アップストリームは gpggpg-agent に対するプロファイルを提供しています。gpg に対して、その提供されたプロファイルを使用するようにシンボリックリンクが作成されていた場合、pacmanarchlinux-keyring をアップデートできなくなります。

hardened_malloc を使う

hardened_mallocAUR is a hardened implementation of glibc's malloc() allocator, originally written for Android but extended for use on the desktop. While not integrated into glibc yet, it can be used selectively with LD_PRELOAD. The proper way to launch an application within firejail using hardened_malloc is demonstrated below. To make it permanent, you would need to create your own entry in /usr/local/bin for the desired application.

$ firejail --env=LD_PRELOAD='/usr/lib/libhardened_malloc.so' /usr/bin/firefox

Alternatively, add the following to a custom profile:

env LD_PRELOAD=/usr/lib/libhardened_malloc.so

The various environment variables and settings that can be used to tune hardened_malloc can be found on its github page.

Enable AppArmor support

Since 0.9.60-1, Firejail has supported more direct integration with AppArmor through a generic AppArmor profile. During installation, the profile, firejail-default, is placed in /etc/apparmor.d directory, and needs to be loaded into the kernel by running the following command as root:

# apparmor_parser -r /etc/apparmor.d/firejail-default

See firejail(1) § APPARMOR.

Local customizations of the apparmor profile are supported by editing the file /etc/apparmor.d/local/firejail-local

AppArmor is already enabled for a large number of Firejail profiles. There are several ways to enable AppArmor confinement on top of a Firejail security profile:

  • Pass the --apparmor flag to Firejail in the command line, e.g. $ firejail --apparmor firefox
  • Use a custom profile and add the apparmor command.
  • Enable Apparmor globally in /etc/firejail/globals.local and disable as needed through the use of ignore apparmor in /etc/firejail/<ProgramName>.local.

Note that enabling AppArmor by above methods always means that /etc/apparmor.d/firejail-default is used. If you rather want to use a specific AppArmor profile for an application, you have to use the above mentioned ignore apparmor command. However, that is not recommended, as using both Firejail and AppArmor for the same applications often creates problems.

Firejail が使用中かを確認する

$ firejail --list

A more comprehensive output is produced by

$ firejail --tree

カスタムのプロファイルを作成する

ホワイトリストとブラックリスト

Blacklists are permissive:

  • Permit everything not explicitly forbidden: blacklist <location/file>
  • Permit file or location in any later blacklist: noblacklist <location/file>

Whitelists are restrictive:

  • Forbid everything not explicitly permitted: whitelist <location/file>
  • Forbid file or location in any later whitelist: nowhitelist <location/file>

プロファイルの記述法

The basic process is:

  1. Copy the default profile (which uses blacklists) to your work folder and give it a unique name
  2. Change the line include /etc/firejail/default.local to include /etc/firejail/ProfileName.local
  3. Gradually comment/uncomment the various options while checking at each stage that the application runs inside the new sandbox
  4. Desirable options not available in the copied default profile can be found by consulting the manual
  5. Build a whitelist of permitted locations. For portability, it may be advisable to place at least some of this list it in a .local file
  6. Test the profile for security holes, see #Testing profiles
  7. Once satisfied, copy your new profile to either /etc/firejail/ or ~/.config/firejail/

You may find the following to be useful:

  1. firejail --debug $OtherOptions $PathToProfile $Program > $PathToOutputFile Gives a detailed breakdown of the sandbox
  2. firejail --debug-caps gives a list of caps supported by the current Firejail software build. This is useful when building a caps whitelist.
  3. firejail --help for a full list of --debug options
  4. firemon PID monitors the running process. See firemon --help for details
  5. checksec may also be useful in testing which standard security features are being used
ノート:
  • The idea is to be as restrictive as possible, while still maintaining usability. This may involve sacrificing potentially dangerous functionality and a change in cavalier work habits.
  • By default, seccomp filters work on a blacklist (which can be found in the manual). It is possible to use seccomp.keep to build a custom whitelist of filters for an application. [1].
  • The list of possible options for a firejail profile is extensive, and users should consult the firejail-profile(5) man page.

ローカルのカスタムプロファイルを永続化する

The standard profile layout now includes the capability to make persistent local customisations through the inclusion of .local files. Basically, each officially supported profile contains the lines include /etc/firejail/ProgramName.local and include /etc/firejail/globals.local. Since the order of precedence is determined by which is read first, this makes for a very powerful way of making local customisations. For example, with reference this firejail question, to globally enable Apparmor and disable Internet connectivity, one could simply create/edit /etc/firejail/globals.local to include the lines

# enable Apparmor and disable Internet globally
net none
apparmor

Then, to allow, for example, "curl" to connect to the internet, yet still maintain its apparmor confinement, one would create/edit /etc/firejail/curl.local to include the lines.

# enable internet for curl
ignore net

Since curl.local is read before globals.local, ignore net overrides net none, and, as a bonus, the above changes would be persistent across future updates.

プロファイルのテスト

Firejail's built in audit feature allows the user to find gaps in a security profile by replacing the program to be sandboxed with a test program. By default, firejail uses the faudit program distributed with Firejail. (Note: A custom test program supplied by the user can also be used.) Examples:

  1. Run the default audit program: $ firejail --audit transmission-gtk
  2. Run a custom audit program: $ firejail --audit=~/sandbox-test transmission-gtk

In the examples above, the sandbox configures the transmission-gtk profile and starts the test program. The real program, transmission-gtk, will not be started.

ノート: The audit feature is not implemented for --x11 commands.

Xephyr と合わせて Firejail を使う

Xephyr will allow you to sandbox Xorg. If you want to be able to resize windows, install a window manager such as Openbox.

xephyr-screen WidthxHeight can be set in /etc/firejail/firejail.config where Width and Height are in pixels and based on your screen resolution.

To open the sandbox:

$ firejail --x11 --net=device openbox

device is your active network interface. Then right click and select your applications to run.

ノート: If you use Unbound, dnsmasq, Pdnsd or any other local cache as your resolver on 127.0.0.1 for example, you would leave --net=device out of the command as your network should work automatically.

A great guide can be found on the Firejail Wordpress.

According to the guide:

The sandbox replaces the regular X11 server with Xpra or Xephyr server. This prevents X11 keyboard loggers and screenshot utilities from accessing the main X11 server.

Note that the statement:

The only way to disable the abstract socket @/tmp/.X11-unix/X0 is by using a network namespace. If for any reasons you cannot use a network namespace, the abstract socket will still be visible inside the sandbox. Hackers can attach keylogger and screenshot programs to this socket.

is incorrect, xserverrc can be edited to -nolisten local which disables the abstract sockets of X11 and helps isolate it.

ブラウザをサンドボックス化する

Openbox can be configured to start a certain browser at startup. program.profile is the respective profile contained in /etc/firejail, and --startup "command" is the command line used to start the program. For example, to start Chromium in the sandbox:

$ firejail --x11 --profile=/etc/firejail/chromium.profile openbox --startup "chromium"

ヒントとテクニック

スペースを含むパス

If you need to reference, whitelist, or blacklist a directory within a custom profile, such as with palemoonAUR, you must do so using the absolute path, without encapsulation or escapes:

/home/user/.moonchild productions

プライベートモード

Firejail also includes a one time private mode, in which no mounts are made in the chroots to your home directory. In doing this, you can execute applications without performing any changes to disk. For example, to execute okular in private mode, do the following:

$ firejail --seccomp --private okular

トラブルシューティング

Some applications do not work properly with Firejail, and others simply require special configuration. In the instance any directories are disallowed or blacklisted for any given application, you may have to further edit the profile to enable nonstandard directories that said application needs to access. One example is wine; wine will not work with seccomp in most cases.

Other configurations exist; it is suggested you check out the man page for firejail to see them all, as firejail is in rapid development.

Remove Firejail symbolic links

To remove Firejail created symbolic links (e.g. reset to default):

# firecfg --clean

Verify if any leftovers of Desktop entries are still overruled by Firejail.

Desktop files

Some GUI application launchers (.desktop files) are coded using absolute paths to an executable, which circumvents firejail's symlink method of ensuring that it is being used. The firecfg tool includes an option to over-ride this on a per-user basis by copying the .desktop files from /usr/share/applications/*.desktop to ~/.local/share/applications/ and replacing the absolute paths with simple file names.

$ firecfg --fix

There may be cases for which you need to manually modify the EXEC line of the .desktop file in ~/.local/share/applications/ to explicitly call Firejail.

PulseAudio

Firejail で PulseAudio が上手く動作しないという 既知の問題 が存在します。一時的に解決する方法:

cp /etc/pulse/client.conf ~/.config/pulse/
echo "enable-shm = no" >> ~/.config/pulse/client.conf

Hidepid

If you have hidepid installed, Firemon can only be run as root. This, among other things, will cause problems with the Firetools GUI incorrectly reporting "Capabilities", "Protocols" and the status of "Seccomp". See [2]

Proprietary Nvidia drivers

Some users report problems when using Firejail and proprietary graphic drivers from NVIDIA (e.g. [3], [4] or [5]). This can often be solved by disabling the noroot Firejail option in the application's profile file.

--net options and Linux kernel >=4.20.0

There is a bug on firejail 0.5.96 with linux >= 4.20.0, see [6] and [7]

Example error message:

$ firejail --noprofile --net=eth0 ls
Parent pid 8521, child pid 8522
Error send: arp.c:182 arp_check: Invalid argument
Error: proc 8521 cannot sync with peer: unexpected EOF
Peer 8522 unexpectedly exited with status 1

Warning: Cannot confine the application using AppArmor

この記事あるいはセクションは #Enable AppArmor support と合併することが議論されています。
ノート: The requirement to enable AppArmor should be made explicit in the previous text. And note that Manjaro references are irrelevant. (議論: トーク:Firejail#)

For some applications (e.g. Firefox [8]) starting with Firejail may result in warnings like:

Warning: Cannot confine the application using AppArmor.
Maybe firejail-default AppArmor profile is not loaded into the kernel.
As root, run "aa-enforce firejail-default" to load it.

When running the suggested command you might see:

ERROR: Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)

This means that AppArmor is not enabled as a kernel parameter, so you have to set it according to AppArmor#Installation.

/usr/bin/patch: **** Can't open patch file

This means the PKGBUILD uses patch with a -i switch so a whitelist for $SRCDEST in /etc/makepkg.conf is needed.

Create: /etc/firejail/patch.local with the value of your $SRCDEST:

whitelist /path/to/makepkg/sources

Changing the PKGBUILD to use stdin also works:

patch -p1 < ../the.patch

Graphical applications hang on start with AMDGPU

Some graphical applications, eg Firefox and mpv, will hang on start when using AMDGPU with Mesa >= 19.3.4. See [9]. The issue is fixed upstream, so firejail-gitAUR should work. Alternatively, for all affected applications, add seccomp !kcmp to their profiles in etc/firejail. If they already have a seccomp statement, you can concatenate them as a comma-separated list, eg seccomp !chroot,!kcmp.

参照