@@ -178,6 +178,10 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator,
178
178
179
179
g .SetRootReadonly (s .ReadOnlyFilesystem )
180
180
181
+ noUseIPC := s .IpcNS .NSMode == specgen .FromContainer || s .IpcNS .NSMode == specgen .FromPod || s .IpcNS .NSMode == specgen .Host
182
+ noUseNet := s .NetNS .NSMode == specgen .FromContainer || s .NetNS .NSMode == specgen .FromPod || s .NetNS .NSMode == specgen .Host
183
+ noUseUTS := s .UtsNS .NSMode == specgen .FromContainer || s .UtsNS .NSMode == specgen .FromPod || s .UtsNS .NSMode == specgen .Host
184
+
181
185
// Add default sysctls
182
186
defaultSysctls , err := util .ValidateSysctls (rtc .Sysctls ())
183
187
if err != nil {
@@ -186,20 +190,20 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator,
186
190
for sysctlKey , sysctlVal := range defaultSysctls {
187
191
188
192
// Ignore mqueue sysctls if --ipc=host
189
- if s . IpcNS . IsHost () && strings .HasPrefix (sysctlKey , "fs.mqueue." ) {
193
+ if noUseIPC && strings .HasPrefix (sysctlKey , "fs.mqueue." ) {
190
194
logrus .Infof ("Sysctl %s=%s ignored in containers.conf, since IPC Namespace set to host" , sysctlKey , sysctlVal )
191
195
192
196
continue
193
197
}
194
198
195
199
// Ignore net sysctls if --net=host
196
- if s . NetNS . IsHost () && strings .HasPrefix (sysctlKey , "net." ) {
200
+ if noUseNet && strings .HasPrefix (sysctlKey , "net." ) {
197
201
logrus .Infof ("Sysctl %s=%s ignored in containers.conf, since Network Namespace set to host" , sysctlKey , sysctlVal )
198
202
continue
199
203
}
200
204
201
205
// Ignore uts sysctls if --uts=host
202
- if s . UtsNS . IsHost () && (strings .HasPrefix (sysctlKey , "kernel.domainname" ) || strings .HasPrefix (sysctlKey , "kernel.hostname" )) {
206
+ if noUseUTS && (strings .HasPrefix (sysctlKey , "kernel.domainname" ) || strings .HasPrefix (sysctlKey , "kernel.hostname" )) {
203
207
logrus .Infof ("Sysctl %s=%s ignored in containers.conf, since UTS Namespace set to host" , sysctlKey , sysctlVal )
204
208
continue
205
209
}
0 commit comments