Skip to content

Commit ad4ec39

Browse files
committed
ContainerService: Add minimum memory amount validation
Today it's possible to pass a memory amount that very easily will cause the container's VM to not be able to boot. We should protect against this to avoid weird hangs/error messages. I could be convinced that a limit should be in Containerization as well, but I think having one in the daemon is a decent idea regardless.
1 parent f7d00aa commit ad4ec39

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Sources/Services/ContainerAPIService/Server/Containers/ContainersService.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,21 @@ public actor ContainersService {
254254
)
255255
}
256256

257+
// Protect against a user providing a memory amount that will cause us to not be able
258+
// to boot. We can go lower, but this is a somewhat safe threshold. Containerization
259+
// also gives a little bit extra than the user asked for to account for guest agent overhead.
260+
//
261+
// NOTE: We could potentially leave this validation to the sandbox service(s), as
262+
// it's possible there could be an implementation that can get away with a lower
263+
// amount and be perfectly safe.
264+
let minimumMemory: UInt64 = 200.mib()
265+
guard configuration.resources.memoryInBytes >= minimumMemory else {
266+
throw ContainerizationError(
267+
.invalidArgument,
268+
message: "minimum memory amount allowed is 200 MiB (got \(configuration.resources.memoryInBytes) bytes)"
269+
)
270+
}
271+
257272
let path = self.containerRoot.appendingPathComponent(configuration.id)
258273
let systemPlatform = kernel.platform
259274

0 commit comments

Comments
 (0)