|
| 1 | +// Package sanitize removes dangerous and questionably-portable properties from container configurations. |
| 2 | +package sanitize |
| 3 | + |
| 4 | +import ( |
| 5 | + rspec "github.com/opencontainers/runtime-spec/specs-go" |
| 6 | +) |
| 7 | + |
| 8 | +// Santize removes dangerous and questionably-portable properties from container configurations. |
| 9 | +func Sanitize(config *rspec.Spec) (err error) { |
| 10 | + config.Process.Terminal = false |
| 11 | + //config.Process.ConsoleSize = nil // needs runtime-spec#581 |
| 12 | + config.Process.User.AdditionalGids = []uint32{} |
| 13 | + config.Process.Capabilities = []string{} |
| 14 | + config.Process.Rlimits = []rspec.Rlimit{} |
| 15 | + config.Process.NoNewPrivileges = false |
| 16 | + config.Process.ApparmorProfile = "" |
| 17 | + config.Process.SelinuxLabel = "" |
| 18 | + config.Root = rspec.Root{ |
| 19 | + Path: "rootfs", |
| 20 | + } |
| 21 | + config.Hostname = "" |
| 22 | + //config.Hooks = nil // needs runtime-spec#427 |
| 23 | + |
| 24 | + for i, _ := range config.Mounts { |
| 25 | + config.Mounts[i].Source = "" |
| 26 | + } |
| 27 | + |
| 28 | + if config.Linux != nil { |
| 29 | + config.Linux.UIDMappings = []rspec.IDMapping{} |
| 30 | + config.Linux.GIDMappings = []rspec.IDMapping{} |
| 31 | + config.Linux.Sysctl = map[string]string{} |
| 32 | + config.Linux.CgroupsPath = nil |
| 33 | + config.Linux.Namespaces = []rspec.Namespace{} |
| 34 | + config.Linux.Devices = []rspec.Device{} |
| 35 | + config.Linux.Seccomp = nil |
| 36 | + config.Linux.RootfsPropagation = "" |
| 37 | + config.Linux.MaskedPaths = []string{} |
| 38 | + config.Linux.MaskedPaths = []string{} |
| 39 | + config.Linux.MountLabel = "" |
| 40 | + |
| 41 | + if config.Linux.Resources != nil { |
| 42 | + config.Linux.Resources.Devices = []rspec.DeviceCgroup{} |
| 43 | + config.Linux.Resources.DisableOOMKiller = nil |
| 44 | + config.Linux.Resources.OOMScoreAdj= nil |
| 45 | + config.Linux.Resources.Pids = nil |
| 46 | + config.Linux.Resources.BlockIO = nil |
| 47 | + config.Linux.Resources.HugepageLimits = []rspec.HugepageLimit{} |
| 48 | + config.Linux.Resources.Network = nil |
| 49 | + |
| 50 | + if config.Linux.Resources.Memory != nil { |
| 51 | + config.Linux.Resources.Memory.Kernel = nil |
| 52 | + config.Linux.Resources.Memory.KernelTCP = nil |
| 53 | + config.Linux.Resources.Memory.Swappiness = nil |
| 54 | + } |
| 55 | + |
| 56 | + if config.Linux.Resources.CPU != nil { |
| 57 | + config.Linux.Resources.CPU.Quota = nil |
| 58 | + config.Linux.Resources.CPU.Period = nil |
| 59 | + config.Linux.Resources.CPU.RealtimeRuntime = nil |
| 60 | + config.Linux.Resources.CPU.Period = nil |
| 61 | + config.Linux.Resources.CPU.Cpus = nil |
| 62 | + config.Linux.Resources.CPU.Mems = nil |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + if config.Solaris != nil { |
| 68 | + config.Solaris.Milestone = "" |
| 69 | + config.Solaris.LimitPriv = "" |
| 70 | + config.Solaris.MaxShmMemory = "" |
| 71 | + config.Solaris.Anet = []rspec.Anet{} |
| 72 | + config.Solaris.CappedCPU = nil |
| 73 | + } |
| 74 | + |
| 75 | + return nil |
| 76 | +} |
0 commit comments