systemd-nspawnを使用して限られたシステムコールの*ホワイトリスト*を作成するには?

systemd-nspawnを使用して限られたシステムコールの*ホワイトリスト*を作成するには?

ロック装置を使用しようとしていsystemd-nspawnます。ただ特定のシステムコールをホワイトリストに追加できるようにします。すべて文書、基本的にはかなり緩いフィルタがあり、数百の異なるシステムコールで構成される大規模なホワイトリストで構成されています。SystemCallFilter=特定の通貨をブラックリストまたはホワイトリストに追加できると主張するデバイスオプションがあります。私はこれを試して、そこにシステムコールを入れて、完全な失敗を期待しました。

[Exec]
...
# We use way more syscalls than this! This whitelist should fail, but it doesn't because it's not a real whitelist.
SystemCallFilter=open,write,close
...

代わりにプログラムがうまく実行されます。使用中のシステムコールを明示的に無効にすると失敗する可能性があります。

[Exec]
...
# This actually fails, because open's been explicitly blacklisted.
SystemCallFilter=~open,~write
...

また、ブラックリストは「ホワイトリスト」よりも優先されるため、すべてを無効にして必要なものだけをオンにすることはできません。ホワイトリストは無視されます。

[Exec]
...
# Doesn't work, as ~@default takes precedence over the allowlist so *nothing* is allowed
SystemCallFilter=~@default
# full list is much longer and generated automatically from a docker seccomp .json
SystemCallFilter=open,write,close,...

私が望むことを達成する方法はありますか?私はデフォルトのホワイトリストに何百ものシステムコールをすべて含むブラックリストを維持したくありません。現在ではこれが唯一の方法のようです。

ベストアンサー1

まず、seccompが有効になっていることを確認してください。 systemd-execによると、特定の呼び出しは常に許可されます。実行、書き込み、オープン、読み取り、および他の多くの呼び出しが許可されます。 SystemCallFilter =は有効で、人生にSystemCallLog=~chown不明なものを簡単に追加できます。使用法システムコールと使用されているすべてのシステムコールが記録されます。で検索してみてくださいjournalctl _AUDIT_TYPE_NAME=SECCOMP

お客様の回答の詳細についてはこちらをご覧ください。

--system-call-filter=

    Alter the system call filter applied to containers. Takes a space-separated list of system call names or group names (the latter prefixed with "@", as listed by the syscall-filter command of systemd-analyze(1)). Passed system calls will be permitted. The list may optionally be prefixed by "~", in which case all listed system calls are prohibited. If this command line option is used multiple times the configured lists are combined. If both a positive and a negative list (that is one system call list without and one with the "~" prefix) are configured, the negative list takes precedence over the positive list. Note that systemd-nspawn always implements a system call allow list (as opposed to a deny list!), and this command line option hence adds or removes entries from the default allow list, depending on the "~" prefix. Note that the applied system call filter is also altered implicitly if additional capabilities are passed using the --capabilities=.`enter code here

https://www.freedesktop.org/software/systemd/man/latest/systemd-nspawn.html

おすすめ記事