Skip to content

Commit

Permalink
libct: straighten 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.

While at it, allow nil capabilities to be passed (this is covered by the
test case

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jan 8, 2025
1 parent fc7190c commit 181bd4b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 3 additions & 0 deletions libcontainer/capabilities/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func KnownCapabilities() []string {
// printing a warning instead.
func New(capConfig *configs.Capabilities) (*Caps, error) {
var c Caps
if capConfig == nil {
return &c, nil
}

_, err := capMap()
if err != nil {
Expand Down
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 @@ -351,13 +351,7 @@ func finalizeNamespace(config *initConfig) 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 181bd4b

Please sign in to comment.