Skip to content

Commit

Permalink
Merge pull request #4836 from nalind/debug-capabilities
Browse files Browse the repository at this point in the history
At startup, log the effective capabilities for debugging
  • Loading branch information
rhatdan authored Jun 5, 2023
2 parents 8543176 + 9b65b12 commit df1fb74
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/buildah/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func before(cmd *cobra.Command) error {
case "", "help", "version", "mount":
return nil
}
debugCapabilities()
unshare.MaybeReexecUsingUserNamespace(false)
if globalFlagResults.CPUProfile != "" {
globalFlagResults.cpuProfileFile, err = os.Create(globalFlagResults.CPUProfile)
Expand Down
22 changes: 22 additions & 0 deletions cmd/buildah/unshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"fmt"
"os"
"os/exec"
"sort"
"strings"

"github.com/containers/storage"
"github.com/containers/storage/pkg/unshare"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/syndtr/gocapability/capability"
)

var (
Expand Down Expand Up @@ -126,3 +128,23 @@ func unshareCmd(c *cobra.Command, args []string) error {
os.Exit(1)
return nil
}

func debugCapabilities() {
pid, err := capability.NewPid2(0)
if err != nil {
logrus.Errorf("error checking our capabilities: %v", err)
return
}
if err := pid.Load(); err != nil {
logrus.Errorf("error loading our current capabilities: %v", err)
return
}
knownCaps := capability.List()
effective := make([]string, 0, len(knownCaps))
for i := range knownCaps {
have := pid.Get(capability.EFFECTIVE, knownCaps[i])
effective = append(effective, fmt.Sprintf("%s=%v", knownCaps[i].String(), have))
}
sort.Strings(effective)
logrus.Debugf("effective capabilities: %v", effective)
}
4 changes: 4 additions & 0 deletions cmd/buildah/unshare_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux

package main
Expand All @@ -16,3 +17,6 @@ func init() {
}
rootCmd.AddCommand(&unshareCommand)
}

func debugCapabilities() {
}

0 comments on commit df1fb74

Please sign in to comment.