Skip to content

Commit

Permalink
libct: fix Caps inheritance
Browse files Browse the repository at this point in the history
For all other properties that are available in both Config and Process,
the merging is performed by newInitConfig.

Let's do the same for Capabilities for the sake of code uniformity.

Also, thanks to the previous commit, we no longer have to make sure we
do not call capabilities.New(nil).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jan 16, 2025
1 parent e54bd9d commit 5a97a84
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 4 additions & 1 deletion libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
User: process.User,
AdditionalGroups: process.AdditionalGroups,
Cwd: process.Cwd,
Capabilities: process.Capabilities,
Capabilities: c.config.Capabilities,
PassedFilesCount: len(process.ExtraFiles),
ContainerID: c.ID(),
NoNewPrivileges: c.config.NoNewPrivileges,
Expand All @@ -707,6 +707,9 @@ func (c *Container) newInitConfig(process *Process) *initConfig {

// Overwrite config properties with ones from process.

if process.Capabilities != nil {
cfg.Capabilities = process.Capabilities
}
if process.NoNewPrivileges != nil {
cfg.NoNewPrivileges = *process.NoNewPrivileges
}
Expand Down
8 changes: 1 addition & 7 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,7 @@ func finalizeNamespace(config *initConfig, addHome bool) error {
}
}

caps := &configs.Capabilities{}
if config.Capabilities != nil {
caps = config.Capabilities
} else if config.Config.Capabilities != nil {
caps = config.Config.Capabilities
}
w, err := capabilities.New(caps)
w, err := capabilities.New(config.Capabilities)
if err != nil {
return err
}
Expand Down

0 comments on commit 5a97a84

Please sign in to comment.