34. Docker and Kernel Security
Systems
Linuxのホスト・システムのセキュリティを強固なものにす
るために、kernelのセキュルティ・システムが存在する。
それには、 Linux capabilitiesとLinux Security
Module (LSM)が含まれる。 Linux capabilitiesは、そ
れぞれのプロセスに与えられた特権を制限し、LSMは、
Linux kernelが、異なったセキュリティ・モデルをサポー
トすることを可能にするフレームワークを提供する。公式
のLinux kernekに統合されたLSMには、
AppArmor 、SELinux、Seccompが含まれる。
35. Linux Capabilities
Linux capabilitiesのマニュアル・ページで述べられてい
るように、伝統的には、Unixシステムは、プロセスを二つ
のカテゴリーに分類する。(スーパー・ユーザーすなわち
rootに所有される)特権プロセスと、(通常のユーザーに
所有される)非特権プロセスである。
kernelは、特権プロセスについては、すべてのパーミッ
ション・チェックをスキップし、非特権プロセスについては
完全なパーミッション・チェックを行う。しかしながら、
Linux kernelは、バージョン 2.2以降は、スーパーユー
ザーの特権をCapabilityに分割し、kernelは、それを、
それぞれ独立に、有効にしたり無効にできる。
41. 6つのnamespace
名前空間 定数 分離対象
IPC CLONE_NEWIPC System V IPC, POSIX メッ
セージキュー
Network CLONE_NEWNET ネットワークデバイス、スタック、
ポートなど
Mount CLONE_NEWNS マウントポイント
PID CLONE_NEWPID プロセス ID
User CLONE_NEWUSER ユーザー ID とグループ ID
UTS CLONE_NEWUTS ホスト名と NIS ドメイン名
80. サンプル
/sys/fs/cgroup/cpuset/Charlie
mount -t tmpfs cgroup_root /sys/fs/cgroup
mkdir /sys/fs/cgroup/cpuset
mount -t cgroup cpuset -ocpuset /sys/fs/cgroup/cpuset
cd /sys/fs/cgroup/cpuset
mkdir Charlie
cd Charlie
/bin/echo 2-3 > cpuset.cpus
/bin/echo 1 > cpuset.mems
/bin/echo $$ > tasks
sh
https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt
81. Dockerとcgroup
# With the LXC driver
$ docker run -d --name='lxc_test'
--lxc-conf="lxc.cgroup.cpu.shares=50"
busybox
# With the libcontainer driver
$ docker run -d --name='libcontainer_test'
--cpu-shares=50
busybox
https://goo.gl/am2B4Y
82. Dockerとcgroup
Feature LXC Libcontainer
Relative CPU share -c, –cpu-shares
–lxc-
conf=”lxc.cgroup.cp
u.shares”
Lock to a CPU core –cpuset-cpus
–lxc-
conf=”lxc.cgroup.cp
uset.cpus”
Limit memory -m, –memory
–lxc-
conf=”lxc.cgroup.cp
uset.mems”
https://goo.gl/am2B4Y
83. Available Subsystems in
Red Hat Enterprise Linux
blkio — this subsystem sets limits on input/output
access to and from block devices such as physical drives
(disk, solid state, USB, etc.).
cpu — this subsystem uses the scheduler to provide
cgroup tasks access to the CPU.
cpuacct — this subsystem generates automatic reports
on CPU resources used by tasks in a cgroup.
cpuset — this subsystem assigns individual CPUs (on a
multicore system) and memory nodes to tasks in a
cgroup.
devices — this subsystem allows or denies access to
devices by tasks in a cgroup.
freezer — this subsystem suspends or resumes tasks in
a cgroup.
https://goo.gl/EHpRNb
84. Available Subsystems in
Red Hat Enterprise Linux
memory — this subsystem sets limits on memory use
by tasks in a cgroup, and generates automatic reports
on memory resources used by those tasks.
net_cls — this subsystem tags network packets with a
class identifier (classid) that allows the Linux traffic
controller (tc) to identify packets originating from a
particular cgroup task.
net_prio — this subsystem provides a way to
dynamically set the priority of network traffic per
network interface.
ns — the namespace subsystem
https://goo.gl/EHpRNb
99. 参考文献
Analysis of Docker Security
http://arxiv.org/pdf/1501.02967v1.pdf
Separation Anxiety: A Tutorial for Isolating
Your System with Linux Namespaces
http://www.toptal.com/linux/separation-anxiety-
isolating-your-system-with-linux-namespaces
PID namespaces in the 2.6.24 kernel
http://lwn.net/Articles/259217/
Bringing new security features to Docker
https://opensource.com/business/14/9/security-for-
docker