|
|
@ -9,13 +9,14 @@ import (
|
|
|
|
"path"
|
|
|
|
"path"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
"syscall"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/subgraph/oz"
|
|
|
|
"github.com/subgraph/oz"
|
|
|
|
"github.com/subgraph/oz/fs"
|
|
|
|
"github.com/subgraph/oz/fs"
|
|
|
|
"github.com/subgraph/oz/xpra"
|
|
|
|
|
|
|
|
"github.com/subgraph/oz/network"
|
|
|
|
"github.com/subgraph/oz/network"
|
|
|
|
|
|
|
|
"github.com/subgraph/oz/xpra"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/op/go-logging"
|
|
|
|
"github.com/op/go-logging"
|
|
|
|
|
|
|
|
"github.com/subgraph/oz/oz-init"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const initPath = "/usr/local/bin/oz-init"
|
|
|
|
const initPath = "/usr/local/bin/oz-init"
|
|
|
@ -46,7 +47,7 @@ func findSandbox(id int) *Sandbox {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
func createInitCommand(name, chroot string, uid uint32, display int, stn *network.SandboxNetwork, nettype string) *exec.Cmd {
|
|
|
|
func createInitCommand(name, chroot string, env []string, uid uint32, display int, stn *network.SandboxNetwork, nettype string) *exec.Cmd {
|
|
|
|
cmd := exec.Command(initPath)
|
|
|
|
cmd := exec.Command(initPath)
|
|
|
|
cmd.Dir = "/"
|
|
|
|
cmd.Dir = "/"
|
|
|
|
|
|
|
|
|
|
|
@ -54,11 +55,11 @@ func createInitCommand(name, chroot string, uid uint32, display int, stn *networ
|
|
|
|
cloneFlags |= syscall.CLONE_NEWIPC
|
|
|
|
cloneFlags |= syscall.CLONE_NEWIPC
|
|
|
|
cloneFlags |= syscall.CLONE_NEWPID
|
|
|
|
cloneFlags |= syscall.CLONE_NEWPID
|
|
|
|
cloneFlags |= syscall.CLONE_NEWUTS
|
|
|
|
cloneFlags |= syscall.CLONE_NEWUTS
|
|
|
|
|
|
|
|
|
|
|
|
if nettype != "host" {
|
|
|
|
if nettype != "host" {
|
|
|
|
cloneFlags |= syscall.CLONE_NEWNET
|
|
|
|
cloneFlags |= syscall.CLONE_NEWNET
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
Chroot: chroot,
|
|
|
|
Chroot: chroot,
|
|
|
|
Cloneflags: cloneFlags,
|
|
|
|
Cloneflags: cloneFlags,
|
|
|
@ -67,20 +68,24 @@ func createInitCommand(name, chroot string, uid uint32, display int, stn *networ
|
|
|
|
"INIT_PROFILE=" + name,
|
|
|
|
"INIT_PROFILE=" + name,
|
|
|
|
fmt.Sprintf("INIT_UID=%d", uid),
|
|
|
|
fmt.Sprintf("INIT_UID=%d", uid),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if stn.Ip != "" {
|
|
|
|
if stn.Ip != "" {
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_ADDR=" + stn.Ip)
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_ADDR="+stn.Ip)
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_VHOST=" + stn.VethHost)
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_VHOST="+stn.VethHost)
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_VGUEST=" + stn.VethGuest)
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_VGUEST="+stn.VethGuest)
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_GATEWAY=" + stn.Gateway.String() + "/" + stn.Class)
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_GATEWAY="+stn.Gateway.String()+"/"+stn.Class)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmd.Env = append(cmd.Env, fmt.Sprintf("INIT_DISPLAY=%d", display))
|
|
|
|
cmd.Env = append(cmd.Env, fmt.Sprintf("INIT_DISPLAY=%d", display))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, e := range env {
|
|
|
|
|
|
|
|
cmd.Env = append(cmd.Env, ozinit.EnvPrefix+e)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger) (*Sandbox, error) {
|
|
|
|
func (d *daemonState) launch(p *oz.Profile, env []string, uid, gid uint32, log *logging.Logger) (*Sandbox, error) {
|
|
|
|
u, err := user.LookupId(fmt.Sprintf("%d", uid))
|
|
|
|
u, err := user.LookupId(fmt.Sprintf("%d", uid))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to lookup user for uid=%d: %v", uid, err)
|
|
|
|
return nil, fmt.Errorf("failed to lookup user for uid=%d: %v", uid, err)
|
|
|
@ -90,11 +95,11 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
display := 0
|
|
|
|
display := 0
|
|
|
|
if p.XServer.Enabled && p.Networking.Nettype == "host" {
|
|
|
|
if p.XServer.Enabled && p.Networking.Nettype == "host" {
|
|
|
|
display = d.nextDisplay
|
|
|
|
display = d.nextDisplay
|
|
|
|
d.nextDisplay += 1
|
|
|
|
d.nextDisplay += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stn := new(network.SandboxNetwork)
|
|
|
|
stn := new(network.SandboxNetwork)
|
|
|
|
if p.Networking.Nettype == "bridge" {
|
|
|
|
if p.Networking.Nettype == "bridge" {
|
|
|
|
stn, err = network.PrepareSandboxNetwork(d.network, log)
|
|
|
|
stn, err = network.PrepareSandboxNetwork(d.network, log)
|
|
|
@ -102,8 +107,8 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
return nil, fmt.Errorf("Unable to prepare veth network: %+v", err)
|
|
|
|
return nil, fmt.Errorf("Unable to prepare veth network: %+v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cmd := createInitCommand(p.Name, fs.Root(), uid, display, stn, p.Networking.Nettype)
|
|
|
|
cmd := createInitCommand(p.Name, fs.Root(), env, uid, display, stn, p.Networking.Nettype)
|
|
|
|
log.Debug("Command environment: %+v", cmd.Env)
|
|
|
|
log.Debug("Command environment: %+v", cmd.Env)
|
|
|
|
pp, err := cmd.StderrPipe()
|
|
|
|
pp, err := cmd.StderrPipe()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -111,13 +116,12 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
return nil, fmt.Errorf("error creating stderr pipe for init process: %v", err)
|
|
|
|
return nil, fmt.Errorf("error creating stderr pipe for init process: %v", err)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
fs.Cleanup()
|
|
|
|
fs.Cleanup()
|
|
|
|
return nil, fmt.Errorf("Unable to start process: %+v", err)
|
|
|
|
return nil, fmt.Errorf("Unable to start process: %+v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sbox := &Sandbox{
|
|
|
|
sbox := &Sandbox{
|
|
|
|
daemon: d,
|
|
|
|
daemon: d,
|
|
|
|
id: d.nextSboxId,
|
|
|
|
id: d.nextSboxId,
|
|
|
@ -130,7 +134,7 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
stderr: pp,
|
|
|
|
stderr: pp,
|
|
|
|
network: stn,
|
|
|
|
network: stn,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if p.Networking.Nettype == "bridge" {
|
|
|
|
if p.Networking.Nettype == "bridge" {
|
|
|
|
if err := network.NetInit(stn, d.network, cmd.Process.Pid, log); err != nil {
|
|
|
|
if err := network.NetInit(stn, d.network, cmd.Process.Pid, log); err != nil {
|
|
|
|
cmd.Process.Kill()
|
|
|
|
cmd.Process.Kill()
|
|
|
@ -138,7 +142,7 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
return nil, fmt.Errorf("Unable to create veth networking: %+v", err)
|
|
|
|
return nil, fmt.Errorf("Unable to create veth networking: %+v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sbox.ready.Add(1)
|
|
|
|
sbox.ready.Add(1)
|
|
|
|
go sbox.logMessages()
|
|
|
|
go sbox.logMessages()
|
|
|
|
if sbox.profile.XServer.Enabled {
|
|
|
|
if sbox.profile.XServer.Enabled {
|
|
|
|