Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/server/instance/drivers/driver_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1726,3 +1726,21 @@ func (d *common) setOOMPriority(pid int) error {

return nil
}

// selinuxCategory returns the SELinux category suffix.
func (d *common) selinuxCategory() string {
idStr := strconv.Itoa(d.id)
remaining := len(idStr)

seContext := ""
current := 0
for current != len(idStr) {
length := min(remaining, 3)
seContext += ":c" + idStr[current:current+length]

current += length
remaining -= length
}

return seContext
}
2 changes: 1 addition & 1 deletion internal/server/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ func (d *lxc) initLXC(config bool) (*liblxc.Container, error) {

// Setup SELinux.
if d.state.OS.SELinuxAvailable && d.state.OS.SELinuxContextInstanceLXC != "" {
err := lxcSetConfigItem(cc, "lxc.selinux.context", fmt.Sprintf("%s:c%d", d.state.OS.SELinuxContextInstanceLXC, d.id))
err := lxcSetConfigItem(cc, "lxc.selinux.context", fmt.Sprintf("%s%s", d.state.OS.SELinuxContextInstanceLXC, d.selinuxCategory()))
if err != nil {
return nil, err
}
Expand Down
Loading