mirror of
https://github.com/containers/podman.git
synced 2025-10-17 19:24:04 +08:00
podman: handle namespaces specified on the CLI
and handle differently the user namespace as it supports additional options. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -33,6 +33,11 @@ const (
|
||||
// Slirp indicates that a slirp4netns network stack should
|
||||
// be used
|
||||
Slirp NamespaceMode = "slirp4netns"
|
||||
// KeepId indicates a user namespace to keep the owner uid inside
|
||||
// of the namespace itself
|
||||
KeepID NamespaceMode = "keep-id"
|
||||
// KeepId indicates to automatically create a user namespace
|
||||
Auto NamespaceMode = "auto"
|
||||
)
|
||||
|
||||
// Namespace describes the namespace
|
||||
@ -71,6 +76,16 @@ func (n *Namespace) IsPod() bool {
|
||||
func (n *Namespace) IsPrivate() bool {
|
||||
return n.NSMode == Private
|
||||
}
|
||||
func validateUserNS(n *Namespace) error {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
switch n.NSMode {
|
||||
case Auto, KeepID:
|
||||
return nil
|
||||
}
|
||||
return n.validate()
|
||||
}
|
||||
|
||||
func validateNetNS(n *Namespace) error {
|
||||
if n == nil {
|
||||
@ -158,6 +173,30 @@ func ParseNamespace(ns string) (Namespace, error) {
|
||||
return toReturn, nil
|
||||
}
|
||||
|
||||
// ParseUserNamespace parses a user namespace specification in string
|
||||
// form.
|
||||
func ParseUserNamespace(ns string) (Namespace, error) {
|
||||
toReturn := Namespace{}
|
||||
switch {
|
||||
case ns == "auto":
|
||||
toReturn.NSMode = Auto
|
||||
return toReturn, nil
|
||||
case strings.HasPrefix(ns, "auto:"):
|
||||
split := strings.SplitN(ns, ":", 2)
|
||||
if len(split) != 2 {
|
||||
return toReturn, errors.Errorf("invalid setting for auto: mode")
|
||||
}
|
||||
toReturn.NSMode = KeepID
|
||||
toReturn.Value = split[1]
|
||||
return toReturn, nil
|
||||
case ns == "keep-id":
|
||||
toReturn.NSMode = KeepID
|
||||
toReturn.NSMode = FromContainer
|
||||
return toReturn, nil
|
||||
}
|
||||
return ParseNamespace(ns)
|
||||
}
|
||||
|
||||
// ParseNetworkNamespace parses a network namespace specification in string
|
||||
// form.
|
||||
// Returns a namespace and (optionally) a list of CNI networks to join.
|
||||
|
Reference in New Issue
Block a user