「Firejail」の版間の差分
Kusanaginoturugi (トーク | 投稿記録) (→インストール) |
Kusanaginoturugi (トーク | 投稿記録) (→Firetools: add == Creating custom profiles ==) |
||
72行目: | 72行目: | ||
他の設定も存在します。firejail の開発は変更が激しいので詳しくは firejail の man ページを参照してください。 |
他の設定も存在します。firejail の開発は変更が激しいので詳しくは firejail の man ページを参照してください。 |
||
+ | |||
+ | == Creating custom profiles == |
||
+ | |||
+ | === Whitelists and Blacklists === |
||
+ | |||
+ | Blacklists are permissive: |
||
+ | |||
+ | * Permit everything not explicitly forbidden: {{ic|blacklist <location/file>}} |
||
+ | * Permit file or location in any later blacklist: {{ic|noblacklist <location/file>}} |
||
+ | |||
+ | Whitelists are restrictive: |
||
+ | |||
+ | * Forbid everything not explicitly permitted: {{ic|whitelist <location/file>}} |
||
+ | * Forbid file or location in any later whitelist: {{ic|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 {{ic|include /etc/firejail/default.local}} to {{ic|include /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 |
||
+ | # [https://firejail.wordpress.com/documentation-2/building-custom-profiles/#whitelisted Build a whitelist] of permitted locations. For portability, it may be advisable to place at least some of this list it in a {{ic|.local}} file |
||
+ | # Test the profile for security holes, see [[#Testing profiles]] |
||
+ | # Once satisfied, copy your new profile to either {{ic|/etc/firejail/}} or {{ic|~/.config/firejail/}} |
||
+ | |||
+ | You may find the following to be useful: |
||
+ | |||
+ | # {{ic|firejail --debug $OtherOptions $PathToProfile $Program > $PathToOutputFile}} Gives a detailed breakdown of the sandbox |
||
+ | # {{ic|firejail --debug-caps}} gives a list of caps supported by the current Firejail software build. This is useful when building a [https://l3net.wordpress.com/2015/03/16/firejail-linux-capabilities-guide/ caps whitelist]. |
||
+ | # {{ic|firejail --help}} for a full list of {{ic|--debug}} options |
||
+ | # {{ic|firemon PID}} monitors the running process. See {{ic|firemon --help}} for details |
||
+ | # {{Pkg|checksec}} may also be useful in testing which standard security features are being used |
||
+ | |||
+ | {{Note|<nowiki></nowiki> |
||
+ | * 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 {{ic|seccomp.keep}} to build a custom whitelist of filters for an application. [https://firejail.wordpress.com/documentation-2/seccomp-guide/]. |
||
+ | * The list of possible options for a firejail profile is extensive, and users should consult the firejail-profile(5) man page. |
||
+ | }} |
||
+ | |||
+ | ==== Persistent local customisation ==== |
||
+ | |||
+ | The standard profile layout now includes the capability to make persistent local customisations through the inclusion of {{ic|.local}} files. Basically, each officially supported profile contains the lines {{ic|include /etc/firejail/ProgramName.local}} and {{ic|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 [https://github.com/netblue30/firejail/issues/1510#issuecomment-326443650 this firejail question], to globally enable Apparmor and disable Internet connectivity, one could simply create/edit {{ic|/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 {{ic|/etc/firejail/curl.local}} to include the lines. |
||
+ | |||
+ | # enable internet for curl |
||
+ | ignore net |
||
+ | |||
+ | Since {{ic|curl.local}} is read before {{ic|globals.local}}, {{ic|ignore net}} overrides {{ic|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 {{ic|faudit}} program distributed with Firejail. (Note: A custom test program supplied by the user can also be used.) |
||
+ | Examples: |
||
+ | |||
+ | # Run the default audit program: {{ic|$ firejail --audit transmission-gtk}} |
||
+ | # Run a custom audit program: {{ic|1=$ 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. |
||
+ | |||
+ | {{Note|The audit feature is not implemented for --x11 commands.}} |
||
==Firetools== |
==Firetools== |
2021年1月27日 (水) 11:45時点における版
関連記事
Firejail は Linux の名前空間や seccomp-bpf、Linux のケイパビリティを使うことで、信頼のおけないアプリケーションの実行環境を制限することでセキュリティのリスクを減らす、使いやすい SUID サンドボックスプログラムです。単体で使えるだけでなく、Grsecurity などの他のカーネル防護システムと一緒に使用することでセキュリティをさらに高めることができます。Firejail はブラウザやデスクトップアプリケーション、デーモン/サーバーなどで使うのに適しています。
インストール
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
設定
Firejail は実行するアプリケーションごとにプロファイルを使います。デフォルトのプロファイルは /etc/firejail/application.profile
にあります。デフォルトのプロファイルを修正したり、デフォルトに含まれていないアプリケーションのカスタムプロファイルを作成する場合、~/.config/firejail
に新しいルールやデフォルトのコピーを配置することができます。
空白が含まれるパス
カスタムプロファイルを使ってディレクトリを参照したりホワイトリスト・ブラックリストに入れる場合、次のように絶対パスを使ってください (例: palemoonAUR): /home/user/.moonchild productions
。
使用方法
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.
Firetools
Firejail を使用するための GUI アプリケーションが存在します: firetools。
トラブルシューティング
PulseAudio
Firejail で PulseAudio が上手く動作しないという 既知の問題 が存在します。一時的に解決する方法:
cp /etc/pulse/client.conf ~/.config/pulse/
echo "enable-shm = no" >> ~/.config/pulse/client.conf