2015-02-07 04:48:57 +08:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package libcontainer
|
|
|
|
|
|
|
|
import (
|
2016-02-23 04:36:12 +08:00
|
|
|
"fmt"
|
2015-03-06 06:33:13 +08:00
|
|
|
"os"
|
|
|
|
|
2015-06-22 10:29:59 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer/apparmor"
|
2016-01-21 07:12:25 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer/keys"
|
2015-06-22 10:29:59 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer/label"
|
2015-06-30 02:12:54 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer/seccomp"
|
2015-06-22 10:29:59 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer/system"
|
2015-02-07 04:48:57 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// linuxSetnsInit performs the container's initialization for running a new process
|
|
|
|
// inside an existing container.
|
|
|
|
type linuxSetnsInit struct {
|
2015-02-10 05:11:57 +08:00
|
|
|
config *initConfig
|
2015-02-07 04:48:57 +08:00
|
|
|
}
|
|
|
|
|
2016-02-23 04:36:12 +08:00
|
|
|
func (l *linuxSetnsInit) getSessionRingName() string {
|
|
|
|
return fmt.Sprintf("_ses.%s", l.config.ContainerId)
|
|
|
|
}
|
|
|
|
|
2016-06-07 04:15:18 +08:00
|
|
|
func (l *linuxSetnsInit) Init() error {
|
2016-06-04 02:53:07 +08:00
|
|
|
if !l.config.Config.NoNewKeyring {
|
|
|
|
// do not inherit the parent's session keyring
|
2016-07-25 06:41:57 +08:00
|
|
|
if _, err := keys.JoinSessionKeyring(l.getSessionRingName()); err != nil {
|
2016-06-04 02:53:07 +08:00
|
|
|
return err
|
|
|
|
}
|
2016-01-21 07:12:25 +08:00
|
|
|
}
|
2016-03-04 02:44:33 +08:00
|
|
|
if l.config.NoNewPrivileges {
|
2016-02-16 19:55:26 +08:00
|
|
|
if err := system.Prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2015-06-30 02:12:54 +08:00
|
|
|
if l.config.Config.Seccomp != nil {
|
|
|
|
if err := seccomp.InitSeccomp(l.config.Config.Seccomp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2015-02-07 04:48:57 +08:00
|
|
|
if err := finalizeNamespace(l.config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-03-04 02:44:33 +08:00
|
|
|
if err := apparmor.ApplyProfile(l.config.AppArmorProfile); err != nil {
|
2015-02-07 04:48:57 +08:00
|
|
|
return err
|
|
|
|
}
|
2016-06-01 22:59:44 +08:00
|
|
|
if err := label.SetProcessLabel(l.config.ProcessLabel); err != nil {
|
|
|
|
return err
|
2015-02-07 04:48:57 +08:00
|
|
|
}
|
2015-03-06 06:33:13 +08:00
|
|
|
return system.Execv(l.config.Args[0], l.config.Args[0:], os.Environ())
|
2015-02-07 04:48:57 +08:00
|
|
|
}
|