master
xSmurf 9 years ago
parent 046bc48d51
commit 6df101331f

@ -0,0 +1,9 @@
package main
import (
ozseccomp "github.com/subgraph/oz/oz-seccomp"
)
func main() {
ozseccomp.Main()
}

@ -209,11 +209,6 @@ func (st *initState) runInit() {
st.launchEnv = append(st.launchEnv, "HOME="+st.user.HomeDir) st.launchEnv = append(st.launchEnv, "HOME="+st.user.HomeDir)
} }
pname := os.Getenv("INIT_PROFILE")
if (pname != "") {
st.launchEnv = append(st.launchEnv, "INIT_PROFILE="+pname)
}
if st.profile.Networking.Nettype != network.TYPE_HOST { if st.profile.Networking.Nettype != network.TYPE_HOST {
err := network.NetSetup(st.network) err := network.NetSetup(st.network)
if err != nil { if err != nil {
@ -307,23 +302,17 @@ func (st *initState) readXpraOutput(r io.ReadCloser) {
} }
func (st *initState) launchApplication(cpath, pwd string, cmdArgs []string) (*exec.Cmd, error) { func (st *initState) launchApplication(cpath, pwd string, cmdArgs []string) (*exec.Cmd, error) {
suffix := ""
if st.config.DivertSuffix != "" {
suffix = "." + st.config.DivertSuffix
}
if cpath == "" { if cpath == "" {
cpath = st.profile.Path cpath = st.profile.Path
} }
if st.config.DivertSuffix != "" {
cpath += "." + st.config.DivertSuffix
}
cpath = cpath + suffix if st.profile.Seccomp.Mode == oz.PROFILE_SECCOMP_WHITELIST {
st.log.Notice("Enabling seccomp whitelist for: %s", cpath)
if st.profile.Seccomp.Mode == "whitelist" { cmdArgs = append([]string{"-w",cpath}, cmdArgs...)
st.log.Warning("cmdArgs %v", cmdArgs) cpath = path.Join(st.config.PrefixPath, "bin", "oz-seccomp")
args := []string{"-w",cpath}
cmdArgs = append(args, cmdArgs...)
cpath = "/usr/bin/seccomp-wrapper"
} }
cmd := exec.Command(cpath) cmd := exec.Command(cpath)
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()
@ -343,6 +332,10 @@ func (st *initState) launchApplication(cpath, pwd string, cmdArgs []string) (*ex
} }
cmd.Env = append(cmd.Env, st.launchEnv...) cmd.Env = append(cmd.Env, st.launchEnv...)
if st.profile.Seccomp.Mode == oz.PROFILE_SECCOMP_WHITELIST {
cmd.Env = append(cmd.Env, "_OZ_PROFILE="+st.profile.Name)
}
cmd.Args = append(cmd.Args, cmdArgs...) cmd.Args = append(cmd.Args, cmdArgs...)
if _, err := os.Stat(pwd); err == nil { if _, err := os.Stat(pwd); err == nil {

@ -1,4 +1,4 @@
package main package seccomp
import ( import (
"fmt" "fmt"
@ -19,7 +19,7 @@ func createLogger() *logging.Logger {
return l return l
} }
func main() { func Main() {
log := createLogger() log := createLogger()
if len(os.Args) < 3 { if len(os.Args) < 3 {
@ -33,13 +33,14 @@ func main() {
log.Error("Error: missing required '%s' argument", name) log.Error("Error: missing required '%s' argument", name)
os.Exit(1) os.Exit(1)
} }
os.Setenv(name, "")
return val return val
} }
cmd := os.Args[2] cmd := os.Args[2]
cmdArgs := os.Args[2:] cmdArgs := os.Args[2:]
env := os.Environ() env := os.Environ()
pname := getvar("INIT_PROFILE") pname := getvar("_OZ_PROFILE")
config, err := oz.LoadConfig(oz.DefaultConfigPath) config, err := oz.LoadConfig(oz.DefaultConfigPath)
if err != nil { if err != nil {

@ -66,8 +66,16 @@ type XServerConf struct {
AudioMode AudioMode `json:"audio_mode"` AudioMode AudioMode `json:"audio_mode"`
} }
type SeccompMode string
const (
PROFILE_SECCOMP_WHITELIST SeccompMode = "whitelist"
PROFILE_SECCOMP_BLACKLIST SeccompMode = "blacklist"
PROFILE_SECCOMP_DISABLED SeccompMode = "disabled"
)
type SeccompConf struct { type SeccompConf struct {
Mode string Mode SeccompMode
Enforce bool Enforce bool
Seccomp_Whitelist string Seccomp_Whitelist string
Seccomp_Blacklist string Seccomp_Blacklist string
@ -168,8 +176,7 @@ func LoadProfiles(dir string) (Profiles, error) {
for _, f := range fs { for _, f := range fs {
if !f.IsDir() { if !f.IsDir() {
name := path.Join(dir, f.Name()) name := path.Join(dir, f.Name())
if strings.Contains(f.Name(), ".json") { if strings.HasSuffix(f.Name(), ".json") {
p, err := loadProfileFile(name) p, err := loadProfileFile(name)
if err != nil { if err != nil {
return nil, fmt.Errorf("error loading '%s': %v", f.Name(), err) return nil, fmt.Errorf("error loading '%s': %v", f.Name(), err)

Loading…
Cancel
Save