Skip to content

Commit 1c8627f

Browse files
authored
Merge pull request #249 from xibz/enable_jailer_runc
Adding runc jailing
2 parents f09b86d + fb4d1f6 commit 1c8627f

16 files changed

+1043
-74
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
bin/
3+
runtime/logs
34
*stamp

examples/etc/containerd/firecracker-runtime.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"root_drive": "/var/lib/firecracker-containerd/runtime/default-rootfs.img",
66
"cpu_count": 1,
77
"cpu_template": "T2",
8-
"log_level": "Debug"
8+
"log_level": "Debug",
9+
"jailer": {
10+
"runc_binary_path": "/usr/local/bin/runc"
11+
}
912
}

proto/firecracker.pb.go

Lines changed: 74 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/firecracker.proto

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ message CreateVMRequest {
3232

3333
// Whether the VM should exit after all tasks running in it have been deleted.
3434
bool ExitAfterAllTasksDeleted = 9;
35+
36+
JailerConfig JailerConfig = 10;
3537
}
3638

3739
message StopVMRequest {
@@ -54,4 +56,7 @@ message GetVMInfoResponse {
5456
message SetVMMetadataRequest {
5557
string VMID = 1;
5658
string Metadata = 2;
57-
}
59+
}
60+
61+
message JailerConfig {
62+
}

runtime/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ type Config struct {
4747
LogLevel string `json:"log_level"`
4848
HtEnabled bool `json:"ht_enabled"`
4949
Debug bool `json:"debug"`
50-
5150
// If a CreateVM call specifies no network interfaces and DefaultNetworkInterfaces is non-empty,
5251
// the VM will default to using the network interfaces as specified here. This is especially
5352
// useful when a CNI-based network interface is provided in DefaultNetworkInterfaces.
5453
DefaultNetworkInterfaces []proto.FirecrackerNetworkInterface `json:"default_network_interfaces"`
54+
JailerConfig JailerConfig `json:"jailer"`
55+
}
56+
57+
// JailerConfig houses a set of configurable values for jailing
58+
// TODO: Add netns field
59+
type JailerConfig struct {
60+
RuncBinaryPath string `json:"runc_binary_path"`
5561
}
5662

5763
// LoadConfig loads configuration from JSON file at 'path'
@@ -76,6 +82,7 @@ func LoadConfig(path string) (*Config, error) {
7682
CPUCount: defaultCPUCount,
7783
CPUTemplate: string(defaultCPUTemplate),
7884
}
85+
7986
if err := json.Unmarshal(data, cfg); err != nil {
8087
return nil, errors.Wrapf(err, "failed to unmarshal config from %q", path)
8188
}

runtime/drive_handler.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ type stubDriveHandler struct {
5151
mutex sync.Mutex
5252
}
5353

54-
func newStubDriveHandler(path string, logger *logrus.Entry, count int) (*stubDriveHandler, error) {
54+
// stubDrivesOpt is used to make and modify changes to the stub drives.
55+
type stubDrivesOpt func(stubDrives []models.Drive) error
56+
57+
func newStubDriveHandler(path string, logger *logrus.Entry, count int, opts ...stubDrivesOpt) (*stubDriveHandler, error) {
5558
h := stubDriveHandler{
5659
RootPath: path,
5760
logger: logger,
@@ -60,6 +63,13 @@ func newStubDriveHandler(path string, logger *logrus.Entry, count int) (*stubDri
6063
if err != nil {
6164
return nil, err
6265
}
66+
67+
for _, opt := range opts {
68+
if err := opt(drives); err != nil {
69+
h.logger.WithError(err).Debug("failed to apply option to stub drives")
70+
return nil, err
71+
}
72+
}
6373
h.drives = drives
6474
return &h, nil
6575
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"ociVersion": "1.0.1",
3+
"process": {
4+
"terminal": false,
5+
"user": {
6+
"uid": 0,
7+
"gid": 0
8+
},
9+
"args": [
10+
"/firecracker",
11+
"--api-sock",
12+
"api.socket"
13+
],
14+
"env": [
15+
"PATH=/"
16+
],
17+
"cwd": "/",
18+
"capabilities": {
19+
"effective": [
20+
],
21+
"bounding": [
22+
],
23+
"inheritable": [
24+
],
25+
"permitted": [
26+
],
27+
"ambient": [
28+
]
29+
},
30+
"rlimits": [
31+
{
32+
"type": "RLIMIT_NOFILE",
33+
"hard": 1024,
34+
"soft": 1024
35+
}
36+
],
37+
"noNewPrivileges": true
38+
},
39+
"root": {
40+
"path": "rootfs",
41+
"readonly": false
42+
},
43+
"hostname": "runc",
44+
"mounts": [
45+
{
46+
"destination": "/proc",
47+
"type": "proc",
48+
"source": "proc"
49+
}
50+
],
51+
"linux": {
52+
"devices": [
53+
{
54+
"path": "/dev/kvm",
55+
"type": "c",
56+
"major": 10,
57+
"minor": 232,
58+
"fileMode": 438,
59+
"uid": 0,
60+
"gid": 0
61+
},
62+
{
63+
"path": "/dev/net/tun",
64+
"type": "c",
65+
"major": 10,
66+
"minor": 200,
67+
"fileMode": 438,
68+
"uid": 0,
69+
"gid": 0
70+
}
71+
],
72+
"resources": {
73+
"devices": [
74+
{
75+
"allow": false,
76+
"access": "rwm"
77+
},
78+
{
79+
"allow": true,
80+
"major": 10,
81+
"minor": 232,
82+
"access": "rwm"
83+
},
84+
{
85+
"allow": true,
86+
"major": 10,
87+
"minor": 200,
88+
"access": "rwm"
89+
}
90+
]
91+
},
92+
"namespaces": [
93+
{
94+
"type": "cgroup"
95+
},
96+
{
97+
"type": "pid"
98+
},
99+
{
100+
"type": "network"
101+
},
102+
{
103+
"type": "ipc"
104+
},
105+
{
106+
"type": "uts"
107+
},
108+
{
109+
"type": "mount"
110+
}
111+
],
112+
"maskedPaths": [
113+
"/proc/asound",
114+
"/proc/kcore",
115+
"/proc/latency_stats",
116+
"/proc/timer_list",
117+
"/proc/timer_stats",
118+
"/proc/sched_debug",
119+
"/sys/firmware",
120+
"/proc/scsi"
121+
],
122+
"readonlyPaths": [
123+
"/proc/bus",
124+
"/proc/fs",
125+
"/proc/irq",
126+
"/proc/sys",
127+
"/proc/sysrq-trigger"
128+
]
129+
}
130+
}

0 commit comments

Comments
 (0)