15
LibCT One Lib to Rule Them All LibCT One Lib to Rule Them All Andrey Vagin Odin, Software Engineer ContainerCon, 2015

LibCT: One Lib to Rule Them All

Embed Size (px)

Citation preview

Page 1: LibCT: One Lib to Rule Them All

LibCTOne Lib to Rule Them AllLibCTOne Lib to Rule Them All

Andrey Vagin

Odin, Software Engineer

ContainerCon, 2015

Page 2: LibCT: One Lib to Rule Them All

AgendaAgenda

• History

• Namespaces and CGroups

• LibCT

• And Libcontainer

• Current state and future plans

2

Page 3: LibCT: One Lib to Rule Them All

History of Linux ContainersHistory of Linux Containers

• 2002 Virtuozzo

• 2005 OpenVZ

• Linux-VServer

• 2006 Namespaces and Cgroups

• 2008 LXC (Linux Containers)

• 2010 Application Containers ...

3

Page 4: LibCT: One Lib to Rule Them All

History of Application ContainersHistory of Application Containers

• Systemd-nspawn– Spawn a namespace container for debugging,

testing and building

• Docker– LXC– Libcontainer

• Rocket

– systemd-nspawn

4

Page 5: LibCT: One Lib to Rule Them All

NamespacesNamespaces● Mount (2.4.19 2002)

– Mount points

● Network– Network devices, stacks, ports, etc.

● PID– processes

● IPC– System V IPC, POSIX message queues

● UTS– Hostname and NIS domain name

● User (3.8 - 2013)– security-related identifiers and attributes

Page 6: LibCT: One Lib to Rule Them All

Other features of namespacesOther features of namespaces● User namespaces allow to use

namespace for unprivileged users● Namespaces can be created once and

used many times● Fast entering into existing namespaces● Ability to isolate tasks in context of one

user

6

Page 7: LibCT: One Lib to Rule Them All

Usage scenariosUsage scenarios

● Mount namespace– to construct a new root which contains only accessible paths

(security)

– Multitenancy

● Network namespace– to grant full access to network devices (Network Function

Virtualization, Virtual Private Networks, etc)

– to build complex network topology

– to use iptables, traffic shaping, etc

● PID namespaces– to isolate independent group of processes (security)

Page 8: LibCT: One Lib to Rule Them All

Control GroupsControl Groups● Cpu,cpuset,cpuacct● Memory, hugetlb● Blkio● Devices● net_cls, net_prio● Freezer● perf_event

Page 9: LibCT: One Lib to Rule Them All

The LibCT libraryThe LibCT library

● Allows to build containerized applications– configure namespaces and cgroups

– unprivileged containers

● In C and binding for other languages● Cross-platform

Page 10: LibCT: One Lib to Rule Them All

Reasons for creating LibCTReasons for creating LibCT● Complexity of low-level API● Support of all kinds of containers

– Linux Containers

– OpenVZ

– Solaris Zones

– BSD jails

● Hide low-level API changes

10

Page 11: LibCT: One Lib to Rule Them All

Libcontainer and LibCTLibcontainer and LibCT

● In Go / In C● Both support back-ends● Only Go / binding for other languages● Easy for developing / works faster● No fork() / …

Libcontainer → runc

Page 12: LibCT: One Lib to Rule Them All

LibCT APILibCT API

12

Session- create()- load()

Container- namespaces- cgroups

Process- kill(), wait()

ProcessDesc- Uid, Git, Groups

Page 13: LibCT: One Lib to Rule Them All

ExampleExamples = libct_session_open_local();

/* configure container */ct = libct_container_create(s, "test");libct_container_set_nsmask(ct,

CLONE_NEWPID | CLONE_NEWUSER | CLONE_NEWNS));libct_userns_add_uid_map(ct, 0, getuid(), 1);libct_userns_add_gid_map(ct, 0, getgid(), 1);libct_fs_add_mount(ct, "tmpfs", "/tmp", 0, "tmpfs", NULL))

/* configure process descriptor */p = libct_process_desc_create(s);libct_process_desc_set_caps(p, 0, CAPS_ALL);

/* Executing process*/pr = libct_container_spawn_cb(ct, p, set_ct_alive, ct_alive);libct_process_wait(pr, &status);libct_container_destroy(ct);libct_session_close(s);

13

Page 14: LibCT: One Lib to Rule Them All

Future plansFuture plans

● Integration with applications● Notifications● Task-less containers● Checkpoint/Restore (CRIU)

Page 15: LibCT: One Lib to Rule Them All

Thank You!

Andrey Vagin <[email protected]>https://github.com/avagin/libct

Andrey Vagin <[email protected]>https://github.com/avagin/libct