Skip to content

Commit 5736579

Browse files
Merge pull request #38 from Roblox/seccomp
Add support for custom seccomp profiles.
2 parents fa7c293 + 1fd49f9 commit 5736579

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ More detailed instructions are in the [`example README.md`](https://github.com/R
8686
| **args** | []string | no | Arguments to the command. |
8787
| **privileged** | bool | no | Run container in privileged mode. Your container will have all linux capabilities when running in privileged mode. |
8888
| **seccomp** | bool | no | Enable default seccomp profile. List of [`allowed syscalls`](https://github.com/containerd/containerd/blob/master/contrib/seccomp/seccomp_default.go#L51-L390). |
89+
| **seccomp_profile** | string | no | Path to custom seccomp profile. `seccomp` must be set to `true` in order to use `seccomp_profile`. The default `docker` seccomp profile found [`here`](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json) can be used as a reference, and modified to create a custom seccomp profile. |
8990
| **readonly_rootfs** | bool | no | Container root filesystem will be read-only. |
9091
| **host_network** | bool | no | Enable host network. This is equivalent to `--net=host` in docker. |
9192
| **cap_add** | []string | no | Add individual capabilities. |
@@ -112,6 +113,19 @@ mounts = [
112113
}
113114
]
114115
```
116+
**Custom seccomp profile example**
117+
118+
The default `docker` seccomp profile found [`here`](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json)
119+
can be downloaded, and modified (by removing/adding syscalls) to create a custom seccomp profile.<br/>
120+
The custom seccomp profile can then be saved under `/opt/seccomp/seccomp.json` on the Nomad client nodes.
121+
122+
A nomad job can be launched using this custom seccomp profile.
123+
```
124+
config {
125+
seccomp = true
126+
seccomp_profile = "/opt/seccomp/seccomp.json"
127+
}
128+
```
115129

116130
## Networking
117131

@@ -120,7 +134,7 @@ mounts = [
120134
**NOTE:** `host` and `bridge` are mutually exclusive options, and only one of them should be used at a time.
121135

122136
1. **Host** network can be enabled by setting `host_network` to `true` in task config
123-
of the job spec [Check under [`Supported options`](https://github.com/Roblox/nomad-driver-containerd#supported-options)].
137+
of the job spec (see under [`Supported options`](https://github.com/Roblox/nomad-driver-containerd#supported-options)).
124138

125139
2. **Bridge** network can be enabled by setting the `network` stanza in the task group section of the job spec.
126140

@@ -129,12 +143,14 @@ network {
129143
mode = "bridge"
130144
}
131145
```
132-
You need to install CNI plugins on nomad client nodes under `/opt/cni/bin` before you can use `bridge` networks.
146+
You need to install CNI plugins on Nomad client nodes under `/opt/cni/bin` before you can use `bridge` networks.
133147

134-
**Instructions for installing CNI plugins.**<br/>
135-
- $ curl -L -o cni-plugins.tgz https://github.com/containernetworking/plugins/releases/download/v0.8.1/cni-plugins-linux-amd64-v0.8.1.tgz<br/>
136-
- sudo mkdir -p /opt/cni/bin<br/>
137-
- sudo tar -C /opt/cni/bin -xzf cni-plugins.tgz
148+
**Instructions for installing CNI plugins.**<br/>
149+
```
150+
$ curl -L -o cni-plugins.tgz https://github.com/containernetworking/plugins/releases/download/v0.8.6/cni-plugins-linux-amd64-v0.8.6.tgz
151+
$ sudo mkdir -p /opt/cni/bin
152+
$ sudo tar -C /opt/cni/bin -xzf cni-plugins.tgz
153+
```
138154

139155
## Tests
140156
```

containerd/containerd.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,18 @@ func (d *Driver) createContainer(image containerd.Image, containerName, containe
6666
opts = append(opts, oci.WithPrivileged)
6767
}
6868

69-
// Enable default seccomp profile.
69+
if !config.Seccomp && config.SeccompProfile != "" {
70+
return nil, fmt.Errorf("seccomp must be set to true, if using a custom seccomp_profile.")
71+
}
72+
73+
// Enable default (or custom) seccomp profile.
7074
// Allowed syscalls for the default seccomp profile: https://github.com/containerd/containerd/blob/master/contrib/seccomp/seccomp_default.go#L51-L390
7175
if config.Seccomp {
72-
opts = append(opts, seccomp.WithDefaultProfile())
76+
if config.SeccompProfile != "" {
77+
opts = append(opts, seccomp.WithProfile(config.SeccompProfile))
78+
} else {
79+
opts = append(opts, seccomp.WithDefaultProfile())
80+
}
7381
}
7482

7583
// Launch container in read-only mode.

containerd/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ var (
9393
"devices": hclspec.NewAttr("devices", "list(string)", false),
9494
"privileged": hclspec.NewAttr("privileged", "bool", false),
9595
"seccomp": hclspec.NewAttr("seccomp", "bool", false),
96+
"seccomp_profile": hclspec.NewAttr("seccomp_profile", "string", false),
9697
"readonly_rootfs": hclspec.NewAttr("readonly_rootfs", "bool", false),
9798
"host_network": hclspec.NewAttr("host_network", "bool", false),
9899
"mounts": hclspec.NewBlockList("mounts", hclspec.NewObject(map[string]*hclspec.Spec{
@@ -143,6 +144,7 @@ type TaskConfig struct {
143144
CapDrop []string `codec:"cap_drop"`
144145
Devices []string `codec:"devices"`
145146
Seccomp bool `codec:"seccomp"`
147+
SeccompProfile string `codec:"seccomp_profile"`
146148
Privileged bool `codec:"privileged"`
147149
ReadOnlyRootfs bool `codec:"readonly_rootfs"`
148150
HostNetwork bool `codec:"host_network"`

0 commit comments

Comments
 (0)