Skip to content

Commit 0317a8e

Browse files
committed
Add Seccomp support
This change is rather large, but I think it's simpler to get in as one unit. It: - Adds a new ContainerizationSeccomp target/product that is a cBPF compiler specifically for seccomp. Its main use is to take in an OCI seccomp description and spit out a filter we can apply. - Adds a new friendly SeccompProfile API to Containerization to specify what filters you'd like applied. This will (as is the case for basically everything else) get translated to OCI behind the scenes. - Adds a small bit of logic in vmexec to apply the filters. And unit and integration tests for everything. Unit testing is interesting. I've added a small simulator so we actually have some semblance of testing outside of just integration tests and seeing if the syscall is blocked/returns whatever.
1 parent d09a102 commit 0317a8e

17 files changed

Lines changed: 2514 additions & 18 deletions

File tree

Package.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let package = Package(
3333
.library(name: "ContainerizationOS", targets: ["ContainerizationOS"]),
3434
.library(name: "ContainerizationExtras", targets: ["ContainerizationExtras"]),
3535
.library(name: "ContainerizationArchive", targets: ["ContainerizationArchive"]),
36+
.library(name: "ContainerizationSeccomp", targets: ["ContainerizationSeccomp"]),
3637
.library(name: "VminitdCore", targets: ["VminitdCore", "Cgroup", "LCShim"]),
3738
.executable(name: "cctl", targets: ["cctl"]),
3839
],
@@ -294,6 +295,19 @@ let package = Package(
294295
],
295296
path: "vminitd/Sources/VminitdCore"
296297
),
298+
.target(
299+
name: "ContainerizationSeccomp",
300+
dependencies: [
301+
"ContainerizationOCI"
302+
]
303+
),
304+
.testTarget(
305+
name: "ContainerizationSeccompTests",
306+
dependencies: [
307+
"ContainerizationSeccomp",
308+
"ContainerizationOCI",
309+
]
310+
),
297311
]
298312
)
299313

Sources/Containerization/LinuxContainer.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public final class LinuxContainer: Container, Sendable {
6767
public var sockets: [UnixSocketConfiguration] = []
6868
/// The mounts for the container.
6969
public var mounts: [Mount] = LinuxContainer.defaultMounts()
70+
/// Seccomp profile for system call filtering.
71+
public var seccomp: SeccompProfile?
7072
/// The DNS configuration for the container.
7173
public var dns: DNS?
7274
/// The hosts to add to /etc/hosts for the container.
@@ -100,6 +102,7 @@ public final class LinuxContainer: Container, Sendable {
100102
interfaces: [any Interface] = [],
101103
sockets: [UnixSocketConfiguration] = [],
102104
mounts: [Mount] = LinuxContainer.defaultMounts(),
105+
seccomp: SeccompProfile? = nil,
103106
dns: DNS? = nil,
104107
hosts: Hosts? = nil,
105108
virtualization: Bool = false,
@@ -117,6 +120,7 @@ public final class LinuxContainer: Container, Sendable {
117120
self.interfaces = interfaces
118121
self.sockets = sockets
119122
self.mounts = mounts
123+
self.seccomp = seccomp
120124
self.dns = dns
121125
self.hosts = hosts
122126
self.virtualization = virtualization
@@ -394,6 +398,7 @@ public final class LinuxContainer: Container, Sendable {
394398

395399
// Linux toggles.
396400
spec.linux?.sysctl = config.sysctl
401+
spec.linux?.seccomp = config.seccomp?.toOCI(effectiveCapabilities: config.process.capabilities.effective)
397402

398403
// If the rootfs was requested as read-only, set it in the OCI spec.
399404
// We let the OCI runtime remount as ro, instead of doing it originally.

Sources/Containerization/LinuxPod.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public final class LinuxPod: Sendable {
8383
public var sysctl: [String: String] = [:]
8484
/// The mounts for the container.
8585
public var mounts: [Mount] = LinuxContainer.defaultMounts()
86+
/// Seccomp profile for system call filtering.
87+
public var seccomp: SeccompProfile?
8688
/// The Unix domain socket relays to setup for the container.
8789
public var sockets: [UnixSocketConfiguration] = []
8890
/// The DNS configuration for the container.
@@ -281,6 +283,7 @@ public final class LinuxPod: Sendable {
281283

282284
// Linux toggles
283285
spec.linux?.sysctl = config.sysctl
286+
spec.linux?.seccomp = config.seccomp?.toOCI(effectiveCapabilities: config.process.capabilities.effective)
284287

285288
// If the rootfs was requested as read-only, set it in the OCI spec.
286289
// We let the OCI runtime remount as ro, instead of doing it originally.

0 commit comments

Comments
 (0)