Skip to content

Commit

Permalink
incusd/isntance/lxc: Respect restrict.idmap.size on un-isolated conta…
Browse files Browse the repository at this point in the history
…iners

Closes #1305

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Oct 21, 2024
1 parent 320b8dc commit 0ca8dd5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/server/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,27 @@ func findIdmap(s *state.State, cName string, isolated bool, configBase string, c
}

if !isolated {
// Create a new set based from the global one.
newIdmapset := idmap.Set{Entries: make([]idmap.Entry, len(s.OS.IdmapSet.Entries))}
copy(newIdmapset.Entries, s.OS.IdmapSet.Entries)

// Restrict the range sizes if specified.
if configSize != "" {
size, err := idmapSize(s, isolated, configSize)
if err != nil {
return nil, 0, err
}

for k, ent := range newIdmapset.Entries {
if ent.MapRange < size {
continue
}

newIdmapset.Entries[k].MapRange = size
}
}

// Apply the raw idmap entries.
for _, ent := range rawMaps.Entries {
err := newIdmapset.AddSafe(ent)
if err != nil && err == idmap.ErrHostIDIsSubID {
Expand Down

0 comments on commit 0ca8dd5

Please sign in to comment.