Docker: Seccomp & circleci

Mar 16, 2023 23:07 · 269 words · 2 minute read

CirclCI と docker と Seccomp と。 🔗

CircleCI で docker build しようとすると、apt upgrade でエラーになった。

Reading package lists...
W: https://download.docker.com/linux/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
E: Problem executing scripts APT::Update::Post-Invoke-Success '/usr/bin/test -e /usr/share/dbus-1/system-services/org.freedesktop.PackageKit.service && /usr/bin/test -S /var/run/dbus/system_bus_socket && /usr/bin/gdbus call --system --dest org.freedesktop.PackageKit --object-path /org/freedesktop/PackageKit --timeout 4 --method org.freedesktop.PackageKit.StateHasChanged cache-update > /dev/null; /bin/echo > /dev/null'
E: Sub-process returned an error code
E: Problem executing scripts APT::Update::Post-Invoke 'rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true'
E: Sub-process returned an error code
The command '/bin/bash -exo pipefail -c sudo apt-get update -y &&     sudo apt-get install -y     gcc     python3.9     python3-setuptools     apt-transport-https     lsb-release     jq     openssh-client &&     sudo apt-get clean' returned a non-zero code: 100

Exited with code exit status 100

CircleCI の remote docker engine は以下の通り。

Allocating a remote Docker Engine
Requesting version: default
Waiting for a Docker Engine assignment: .......................

~~~

Server Engine Details:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            2021-06-02T11:54:50.000000000+00:00
  OS/Arch:          linux/amd64
  Experimental:     false

WHY? 🔗

前に調べたもの と同じ。。

Linux カーネルのセキュリティ機構に Secure Computing Mode (Seccomp) というのがある。
これは危険なシステムコールの利用を禁止するための設定。

docker system info コマンドで、有効かどうかを確認できる。

Client:
 ...

Server:
 ...
 Security Options:
  apparmor
  seccomp
   Profile: default
 ...

デフォルトのプロファイルだと、禁止されているシステムコールの一覧:
https://docs.docker.com/engine/security/seccomp/#significant-syscalls-blocked-by-the-default-profile

コンテナ内に入って、エラーの出ている PostInvokeSuccess のコマンドを順に叩いていくと、

$ /usr/bin/gdbus call --system --dest org.freedesktop.PackageKit --object-path /org/freedesktop/PackageKit --timeout 4 --method org.freedesktop.PackageKit.StateHasChanged cache-update

GLib-ERROR **: 07:41:35.069: file ../../../glib/gthread-posix.c: line 1339 (g_system_thread_new): error 'Operation not permitted' during 'pthread_create'

どうも pthread_create が seccomp に引っかかっていた模様。

どうする? 🔗

docker run の場合は、--security-opt で必要なシステムコールを許可してあげれば良い。
(雑にやるなら、seccomp:unconfined--priviledged でも…)

docker build の場合は、どうやらバージョン次第でサポートされていないらしい。

Error response from daemon: The daemon on this platform does not support setting security options on build

CircleCI 管理部門の対応を待ちつつ、一旦 apt upgrade したイメージをベースイメージとして push しておいてワークアラウンド…ぐぬぬ。