Skip to content

Commit 1230bd6

Browse files
authored
Merge pull request #4952 from crosbymichael/label-etc-files
[cri] label etc files for selinux containers
2 parents 9c3f171 + a731039 commit 1230bd6

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

pkg/cri/opts/spec_linux.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,30 @@ func WithMounts(osi osinterface.OS, config *runtime.ContainerConfig, extra []*ru
242242
}
243243
}
244244

245+
const (
246+
etcHosts = "/etc/hosts"
247+
etcHostname = "/etc/hostname"
248+
resolvConfPath = "/etc/resolv.conf"
249+
)
250+
251+
// WithRelabeledContainerMounts relabels the default container mounts for files in /etc
252+
func WithRelabeledContainerMounts(mountLabel string) oci.SpecOpts {
253+
return func(ctx context.Context, client oci.Client, _ *containers.Container, s *runtimespec.Spec) (err error) {
254+
if mountLabel == "" {
255+
return nil
256+
}
257+
for _, m := range s.Mounts {
258+
switch m.Destination {
259+
case etcHosts, etcHostname, resolvConfPath:
260+
if err := label.Relabel(m.Source, mountLabel, false); err != nil {
261+
return err
262+
}
263+
}
264+
}
265+
return nil
266+
}
267+
}
268+
245269
// Ensure mount point on which path is mounted, is shared.
246270
func ensureShared(path string, lookupMount func(string) (mount.Info, error)) error {
247271
mountInfo, err := lookupMount(path)

pkg/cri/server/container_create_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (c *criService) containerSpec(id string, sandboxID string, sandboxPid uint3
183183
}
184184
}()
185185

186-
specOpts = append(specOpts, customopts.WithMounts(c.os, config, extraMounts, mountLabel))
186+
specOpts = append(specOpts, customopts.WithMounts(c.os, config, extraMounts, mountLabel), customopts.WithRelabeledContainerMounts(mountLabel))
187187

188188
if !c.config.DisableProcMount {
189189
// Apply masked paths if specified.

0 commit comments

Comments
 (0)