Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/unshare/unshare_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ var (
hasCapSysAdminOnce sync.Once
hasCapSysAdminRet bool
hasCapSysAdminErr error
hasCapNetAdminOnce sync.Once
hasCapNetAdminRet bool
hasCapNetAdminErr error
)

// IsRootless tells us if we are running in rootless mode
Expand Down Expand Up @@ -753,3 +756,20 @@ func HasCapSysAdmin() (bool, error) {
})
return hasCapSysAdminRet, hasCapSysAdminErr
}

// HasCapNetAdmin returns whether the current process has CAP_NET_ADMIN.
func HasCapNetAdmin() (bool, error) {
hasCapNetAdminOnce.Do(func() {
currentCaps, err := capability.NewPid2(0)
if err != nil {
hasCapNetAdminErr = err
return
}
if err = currentCaps.Load(); err != nil {
hasCapNetAdminErr = err
return
}
hasCapNetAdminRet = currentCaps.Get(capability.EFFECTIVE, capability.CAP_NET_ADMIN)
})
return hasCapNetAdminRet, hasCapNetAdminErr
}
5 changes: 5 additions & 0 deletions pkg/unshare/unshare_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ func ParseIDMappings(uidmap, gidmap []string) ([]idtools.IDMap, []idtools.IDMap,
func HasCapSysAdmin() (bool, error) {
return os.Geteuid() == 0, nil
}

// HasCapNetAdmin returns whether the current process has CAP_NET_ADMIN.
func HasCapNetAdmin() (bool, error) {
return os.Geteuid() == 0, nil
}
Loading