summaryrefslogtreecommitdiff
path: root/cmd/podman/create_cli.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/create_cli.go')
-rw-r--r--cmd/podman/create_cli.go43
1 files changed, 37 insertions, 6 deletions
diff --git a/cmd/podman/create_cli.go b/cmd/podman/create_cli.go
index 0cc265e92..24856feb8 100644
--- a/cmd/podman/create_cli.go
+++ b/cmd/podman/create_cli.go
@@ -24,14 +24,45 @@ func getAllLabels(labelFile, inputLabels []string) (map[string]string, error) {
return labels, nil
}
-func convertStringSliceToMap(strSlice []string, delimiter string) (map[string]string, error) {
+// validateSysctl validates a sysctl and returns it.
+func validateSysctl(strSlice []string) (map[string]string, error) {
sysctl := make(map[string]string)
- for _, inputSysctl := range strSlice {
- values := strings.Split(inputSysctl, delimiter)
- if len(values) < 2 {
- return sysctl, errors.Errorf("%s in an invalid sysctl value", inputSysctl)
+ validSysctlMap := map[string]bool{
+ "kernel.msgmax": true,
+ "kernel.msgmnb": true,
+ "kernel.msgmni": true,
+ "kernel.sem": true,
+ "kernel.shmall": true,
+ "kernel.shmmax": true,
+ "kernel.shmmni": true,
+ "kernel.shm_rmid_forced": true,
+ }
+ validSysctlPrefixes := []string{
+ "net.",
+ "fs.mqueue.",
+ }
+
+ for _, val := range strSlice {
+ foundMatch := false
+ arr := strings.Split(val, "=")
+ if len(arr) < 2 {
+ return nil, errors.Errorf("%s is invalid, sysctl values must be in the form of KEY=VALUE", val)
+ }
+ if validSysctlMap[arr[0]] {
+ sysctl[arr[0]] = arr[1]
+ continue
+ }
+
+ for _, prefix := range validSysctlPrefixes {
+ if strings.HasPrefix(arr[0], prefix) {
+ sysctl[arr[0]] = arr[1]
+ foundMatch = true
+ break
+ }
+ }
+ if !foundMatch {
+ return nil, errors.Errorf("sysctl '%s' is not whitelisted", arr[0])
}
- sysctl[values[0]] = values[1]
}
return sysctl, nil
}