「Firejail」の版間の差分
Kusanaginoturugi (トーク | 投稿記録) |
Kusanaginoturugi (トーク | 投稿記録) (→設定: 英語版に差し替え) |
||
31行目: | 31行目: | ||
==設定== |
==設定== |
||
+ | Most users will not require any custom configuration and can proceed to [[#Usage]]. |
||
− | Firejail は実行するアプリケーションごとにプロファイルを使います。デフォルトのプロファイルは {{ic|/etc/firejail/''application''.profile}} にあります。デフォルトのプロファイルを修正したり、デフォルトに含まれていないアプリケーションのカスタムプロファイルを作成する場合、{{ic|~/.config/firejail}} に新しいルールやデフォルトのコピーを配置することができます。 |
||
+ | Firejail uses profiles to set the security protections for each of the applications executed inside of it - you can find the default profiles in {{ic|/etc/firejail/''application''.profile}}. Should you require custom profiles for applications not included, or wish to modify the defaults, you may place new rules or copies of the defaults in the {{ic|~/.config/firejail/}} directory. You may have multiple custom profile files for a single application, and you may share the same profile file among several applications. |
||
− | ===空白が含まれるパス=== |
||
+ | If firejail does not have a profile for a particular application, it uses its restrictive system-wide default profile. This can result in the application not functioning as desired, without first creating a custom, and less restrictive profile. |
||
− | カスタムプロファイルを使ってディレクトリを参照したりホワイトリスト・ブラックリストに入れる場合、次のように絶対パスを使ってください (例: {{aur|palemoon}}): {{ic|/home/user/.moonchild productions}}。 |
||
+ | |||
+ | Refer to {{man|5|firejail-profile}}. |
||
==使用方法== |
==使用方法== |
2021年1月27日 (水) 11:53時点における版
関連記事
Firejail は Linux の名前空間や seccomp-bpf、Linux のケイパビリティを使うことで、信頼のおけないアプリケーションの実行環境を制限することでセキュリティのリスクを減らす、使いやすい SUID サンドボックスプログラムです。単体で使えるだけでなく、Grsecurity などの他のカーネル防護システムと一緒に使用することでセキュリティをさらに高めることができます。Firejail はブラウザやデスクトップアプリケーション、デーモン/サーバーなどで使うのに適しています。
目次
- 1 インストール
- 2 設定
- 3 使用方法
- 4 Creating custom profiles
- 5 Firejail with Xephyr
- 6 Tips and tricks
- 7 トラブルシューティング
- 7.1 Remove Firejail symbolic links
- 7.2 Desktop files
- 7.3 PulseAudio
- 7.4 Hidepid
- 7.5 Proprietary Nvidia drivers
- 7.6 --net options and Linux kernel >=4.20.0
- 7.7 Warning: Cannot confine the application using AppArmor
- 7.8 /usr/bin/patch: **** Can't open patch file
- 7.9 Graphical applications hang on start with AMDGPU
- 8 参照
インストール
firejail または firejail-gitAUR パッケージをインストールしてください。Firejail で使用するためのGUIアプリケーション、firetools も用意されています。
Apparmor integration
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
To quote the manual:
- The installed profile is supplemental for main firejail functions and among other things does the following:
- Disable ptrace. With ptrace it is possible to inspect and hijack running programs. Usually this is needed only for debugging.
- Whitelist write access to several files under
/run
,/proc
and/sys
. - Allow running programs only from well-known system paths, such as
/bin
,/sbin
,/usr/bin
etc. Those paths are available as read-only. Running programs and scripts from user home or other directories writable by the user is not allowed. - Prevent using non-standard network sockets. Only
unix
,inet
,inet6
,netlink
,raw
and packet are allowed. - Deny access to known sensitive paths like
.snapshots
.
Local customizations of the apparmor profile are supported by editing the file /etc/apparmor.d/local/firejail-local
設定
Most users will not require any custom configuration and can proceed to #Usage.
Firejail uses profiles to set the security protections for each of the applications executed inside of it - you can find the default profiles in /etc/firejail/application.profile
. Should you require custom profiles for applications not included, or wish to modify the defaults, you may place new rules or copies of the defaults in the ~/.config/firejail/
directory. You may have multiple custom profile files for a single application, and you may share the same profile file among several applications.
If firejail does not have a profile for a particular application, it uses its restrictive system-wide default profile. This can result in the application not functioning as desired, without first creating a custom, and less restrictive profile.
Refer to firejail-profile(5).
使用方法
firejail で seccomp を使ってアプリケーションを実行するには (例: okular)、以下を実行:
$ firejail --seccomp okular
プライベートモード
Firejail にはワンタイムのプライベートモードも存在します。プライベートモードでは chroot でホームディレクトリのマウントがされません。ディスクに何の痕跡も残さないでアプリケーションを実行することが可能です。例えば、okular をプライベートモードで実行するには、以下を実行:
$ firejail --seccomp --private okular
デフォルトで Firejail を使う
デフォルトで Firejail でアプリケーションを実行するには、以下のように /usr/bin/firejail
のシンボリックリンクを作成してください:
$ ln -s /usr/bin/firejail /usr/local/bin/okular
また、コンソールや .desktop
ファイルからアプリケーションを起動している場合、それぞれのアプリケーションのランチャーを /usr/local/bin
に作成することができます。例えば、okular なら以下のファイルを作成して実行可能権限を付与してください:
/usr/local/bin/okular
firejail --seccomp /usr/bin/okular $@
デスクトップファイル
標準のパスを使わないアプリケーションも存在します。そのようなアプリケーションでは /usr/share/applications/*.desktop
の .desktop
ランチャーを ~/.local/share/applications/
にコピーして EXEC 行に firejail (や seccomp) を記述すれば firejail を使うことができます。
デーモン
デーモンの場合、デーモンの systemd ユニットファイルを上書きして firejail を呼び出すようにしてください。systemd#ユニットファイルの編集を参照。
ノート
Firejail では上手く動作しないアプリケーションや、特別な設定を必要とするアプリケーションが存在します。特定のアプリケーションで全てのディレクトリが使用できない、ブラックリストに入れられている場合、プロファイルを編集してアプリケーションからアクセスする必要がある非標準のディレクトリを有効化してください。例えば Wine がそれに当てはまります。Wine は大抵の場合 seccomp を使用していると動作しません。
他の設定も存在します。firejail の開発は変更が激しいので詳しくは firejail の man ページを参照してください。
Creating custom profiles
Whitelists and Blacklists
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>
Profile writing
The basic process is:
- Copy the default profile (which uses blacklists) to your work folder and give it a unique name
- Change the line
include /etc/firejail/default.local
toinclude /etc/firejail/ProfileName.local
- Gradually comment/uncomment the various options while checking at each stage that the application runs inside the new sandbox
- Desirable options not available in the copied default profile can be found by consulting the manual
- 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 - Test the profile for security holes, see #Testing profiles
- Once satisfied, copy your new profile to either
/etc/firejail/
or~/.config/firejail/
You may find the following to be useful:
firejail --debug $OtherOptions $PathToProfile $Program > $PathToOutputFile
Gives a detailed breakdown of the sandboxfirejail --debug-caps
gives a list of caps supported by the current Firejail software build. This is useful when building a caps whitelist.firejail --help
for a full list of--debug
optionsfiremon PID
monitors the running process. Seefiremon --help
for details- checksec may also be useful in testing which standard security features are being used
Persistent local customisation
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.
Testing profiles
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:
- Run the default audit program:
$ firejail --audit transmission-gtk
- 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.
Firejail with Xephyr
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.
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.
Sandboxing a browser
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"
Tips and tricks
Paths containing spaces
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
Private mode
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
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
.