Skip to content

Commit

Permalink
capabilities: be more graceful in resetting ambient
Browse files Browse the repository at this point in the history
Similar to when SetAmbient() can fail, runc should be graceful about
ResetAmbient failing.

This functionality previously worked under gvisor, which doesn't
implement ambient capabilities atm. The hard error on reset broke gvisor
usage.

Signed-off-by: Evan Phoenix <[email protected]>
  • Loading branch information
evanphx committed Jan 24, 2025
1 parent a7d7645 commit 17087f7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libcontainer/capabilities/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
package capabilities

import (
"errors"
"fmt"
"sort"
"strings"
"sync"
"syscall"

"github.com/moby/sys/capability"
"github.com/opencontainers/runc/libcontainer/configs"
Expand Down Expand Up @@ -129,9 +131,13 @@ func (c *Caps) ApplyCaps() error {
// don't return any errors, only warn.
ambs := c.caps[capability.AMBIENT]
err := capability.ResetAmbient()
if err != nil {
return fmt.Errorf("can't reset ambient capabilities: %w", err)

// EINVAL is returned when the kernel doesn't support ambient capabilities.
// We ignore this because runc supports running on older kernels.
if err != nil && !errors.Is(err, syscall.EINVAL) {
return err
}

for _, a := range ambs {
err := capability.SetAmbient(true, a)
if err != nil {
Expand Down

0 comments on commit 17087f7

Please sign in to comment.