Skip to content

Commit 181bd4b

Browse files
committed
libct: straighten Caps inheritance
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 <[email protected]>
1 parent fc7190c commit 181bd4b

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

libcontainer/capabilities/capabilities.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ func KnownCapabilities() []string {
4545
// printing a warning instead.
4646
func New(capConfig *configs.Capabilities) (*Caps, error) {
4747
var c Caps
48+
if capConfig == nil {
49+
return &c, nil
50+
}
4851

4952
_, err := capMap()
5053
if err != nil {

libcontainer/container_linux.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
691691
User: process.User,
692692
AdditionalGroups: process.AdditionalGroups,
693693
Cwd: process.Cwd,
694-
Capabilities: process.Capabilities,
694+
Capabilities: c.config.Capabilities,
695695
PassedFilesCount: len(process.ExtraFiles),
696696
ContainerID: c.ID(),
697697
NoNewPrivileges: c.config.NoNewPrivileges,
@@ -707,6 +707,9 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
707707

708708
// Overwrite config properties with ones from process.
709709

710+
if process.Capabilities != nil {
711+
cfg.Capabilities = process.Capabilities
712+
}
710713
if process.NoNewPrivileges != nil {
711714
cfg.NoNewPrivileges = *process.NoNewPrivileges
712715
}

libcontainer/init_linux.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,7 @@ func finalizeNamespace(config *initConfig) error {
351351
}
352352
}
353353

354-
caps := &configs.Capabilities{}
355-
if config.Capabilities != nil {
356-
caps = config.Capabilities
357-
} else if config.Config.Capabilities != nil {
358-
caps = config.Config.Capabilities
359-
}
360-
w, err := capabilities.New(caps)
354+
w, err := capabilities.New(config.Capabilities)
361355
if err != nil {
362356
return err
363357
}

0 commit comments

Comments
 (0)