Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
5 changes: 5 additions & 0 deletions internal/config/nsmgr/nsmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (mgr *NamespaceManager) NewPodNamespaces(cfg *PodNamespacesConfig) ([]Names
for _, ns := range cfg.Namespaces {
ns, err := GetNamespace(ns.Path, ns.Type)
if err != nil {
for _, nsToClose := range returnedNamespaces {
if err2 := nsToClose.Remove(); err2 != nil {
logrus.Errorf("failed to remove namespace after failed to create: %v", err2)
}
}
return nil, err
}

Expand Down
4 changes: 0 additions & 4 deletions internal/config/nsmgr/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ func (n *namespace) Remove() error {
// GetNamespace takes a path and type, checks if it is a namespace, and if so
// returns an instance of the Namespace interface.
func GetNamespace(nsPath string, nsType NSType) (Namespace, error) {
if err := nspkg.IsNSorErr(nsPath); err != nil {
return nil, err
}

ns, err := nspkg.GetNS(nsPath)
if err != nil {
return nil, err
Expand Down
66 changes: 22 additions & 44 deletions internal/lib/container_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,30 +199,30 @@ func (c *ContainerServer) LoadSandbox(ctx context.Context, id string) (retErr er
sb.SetSeccompProfilePath(spp)
sb.SetNamespaceOptions(&nsOpts)

defer func() {
if retErr != nil {
if err := sb.RemoveManagedNamespaces(); err != nil {
log.Warnf(ctx, "failed to remove namespaces: %v", err)
}
}
}()
// We add an NS only if we can load a permanent one.
// Otherwise, the sandbox will live in the host namespace.
netNsPath, err := configNsPath(&m, rspec.NetworkNamespace)
if err == nil {
if nsErr := sb.NetNsJoin(netNsPath); nsErr != nil {
return nsErr
}
}
ipcNsPath, err := configNsPath(&m, rspec.IPCNamespace)
if err == nil {
if nsErr := sb.IpcNsJoin(ipcNsPath); nsErr != nil {
return nsErr
}
}
utsNsPath, err := configNsPath(&m, rspec.UTSNamespace)
if err == nil {
if nsErr := sb.UtsNsJoin(utsNsPath); nsErr != nil {
return nsErr
}
}
userNsPath, err := configNsPath(&m, rspec.UserNamespace)
if err == nil {
if nsErr := sb.UserNsJoin(userNsPath); nsErr != nil {
return nsErr
namespacesToJoin := []struct {
rspecNS rspec.LinuxNamespaceType
joinFunc func(string) error
}{
{rspecNS: rspec.NetworkNamespace, joinFunc: sb.NetNsJoin},
{rspecNS: rspec.IPCNamespace, joinFunc: sb.IpcNsJoin},
{rspecNS: rspec.UTSNamespace, joinFunc: sb.UtsNsJoin},
{rspecNS: rspec.UserNamespace, joinFunc: sb.UserNsJoin},
}
for _, namespaceToJoin := range namespacesToJoin {
path, err := configNsPath(&m, namespaceToJoin.rspecNS)
if err == nil {
if nsErr := namespaceToJoin.joinFunc(path); err != nil {
return nsErr
}
}
}

Expand Down Expand Up @@ -304,28 +304,6 @@ func (c *ContainerServer) LoadSandbox(ctx context.Context, id string) (retErr er
return err
}

// We add an NS only if we can load a permanent one.
// Otherwise, the sandbox will live in the host namespace.
if wasSpoofed {
namespacesToJoin := []struct {
rspecNS rspec.LinuxNamespaceType
joinFunc func(string) error
}{
{rspecNS: rspec.NetworkNamespace, joinFunc: sb.NetNsJoin},
{rspecNS: rspec.IPCNamespace, joinFunc: sb.IpcNsJoin},
{rspecNS: rspec.UTSNamespace, joinFunc: sb.UtsNsJoin},
{rspecNS: rspec.UserNamespace, joinFunc: sb.UserNsJoin},
}
for _, namespaceToJoin := range namespacesToJoin {
path, err := configNsPath(&m, namespaceToJoin.rspecNS)
if err == nil {
if nsErr := namespaceToJoin.joinFunc(path); err != nil {
return nsErr
}
}
}
}

sb.SetCreated()
if err := label.ReserveLabel(processLabel); err != nil {
return err
Expand Down