modifyHostConfig applies security context config to dockercontainer.HostConfig.
( sc *runtimeapi.LinuxContainerSecurityContext, hostConfig *dockercontainer.HostConfig, separator rune, )
| 125 | |
| 126 | // modifyHostConfig applies security context config to dockercontainer.HostConfig. |
| 127 | func modifyHostConfig( |
| 128 | sc *runtimeapi.LinuxContainerSecurityContext, |
| 129 | hostConfig *dockercontainer.HostConfig, |
| 130 | separator rune, |
| 131 | ) error { |
| 132 | if sc == nil { |
| 133 | return nil |
| 134 | } |
| 135 | |
| 136 | // Apply supplemental groups. |
| 137 | for _, group := range sc.SupplementalGroups { |
| 138 | hostConfig.GroupAdd = append(hostConfig.GroupAdd, strconv.FormatInt(group, 10)) |
| 139 | } |
| 140 | |
| 141 | // Apply security context for the container. |
| 142 | hostConfig.Privileged = sc.Privileged |
| 143 | hostConfig.ReadonlyRootfs = sc.ReadonlyRootfs |
| 144 | if sc.Capabilities != nil { |
| 145 | hostConfig.CapAdd = sc.GetCapabilities().AddCapabilities |
| 146 | hostConfig.CapDrop = sc.GetCapabilities().DropCapabilities |
| 147 | } |
| 148 | if sc.SelinuxOptions != nil { |
| 149 | hostConfig.SecurityOpt = addSELinuxOptions( |
| 150 | hostConfig.SecurityOpt, |
| 151 | sc.SelinuxOptions, |
| 152 | separator, |
| 153 | ) |
| 154 | } |
| 155 | |
| 156 | // Apply apparmor options. |
| 157 | apparmorSecurityOpts, err := getApparmorSecurityOpts(sc, separator) |
| 158 | if err != nil { |
| 159 | return fmt.Errorf("failed to generate apparmor security options: %v", err) |
| 160 | } |
| 161 | hostConfig.SecurityOpt = append(hostConfig.SecurityOpt, apparmorSecurityOpts...) |
| 162 | |
| 163 | if sc.NoNewPrivs { |
| 164 | hostConfig.SecurityOpt = append(hostConfig.SecurityOpt, "no-new-privileges") |
| 165 | } |
| 166 | |
| 167 | if !hostConfig.Privileged { |
| 168 | hostConfig.MaskedPaths = sc.MaskedPaths |
| 169 | hostConfig.ReadonlyPaths = sc.ReadonlyPaths |
| 170 | } |
| 171 | |
| 172 | return nil |
| 173 | } |
| 174 | |
| 175 | // modifySandboxNamespaceOptions apply namespace options for sandbox |
| 176 | func modifySandboxNamespaceOptions( |
searching dependent graphs…