@@ -2,6 +2,8 @@ package policy
2
2
3
3
import (
4
4
"fmt"
5
+
6
+ glob "github.com/gobwas/glob"
5
7
)
6
8
7
9
type SandboxPolicy interface {
@@ -39,15 +41,33 @@ func (o *PathOps) UnmarshalYAML(unmarshal func(interface{}) error) error {
39
41
return nil
40
42
}
41
43
44
+ type PatternMatcher struct {
45
+ glob.Glob
46
+ }
47
+
48
+ func (p * PatternMatcher ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
49
+ var raw string
50
+ var err error
51
+ if err = unmarshal (& raw ); err != nil {
52
+ return err
53
+ }
54
+ var g glob.Glob
55
+ if g , err = glob .Compile (raw ); err != nil {
56
+ return err
57
+ }
58
+ * p = PatternMatcher {g }
59
+ return nil
60
+ }
61
+
42
62
type PolicyConf struct {
43
- WhitelistPaths map [PathOps ][]string `yaml:"whitelist_paths"`
44
- ExecAllowance int `yaml:"exec_allowance"`
45
- ForkAllowance int `yaml:"fork_allowance"`
46
- MaxChildProcs uint `yaml:"max_child_procs"`
47
- ExtraEnvs []string `yaml:"extra_envs"`
48
- PreservedEnvKeys []string `yaml:"preserved_env_keys"`
49
- TracedSyscalls []string `yaml:"traced_syscalls"`
50
- AllowedSyscalls []string `yaml:"allowed_syscalls"`
63
+ WhitelistPaths map [PathOps ][]PatternMatcher `yaml:"whitelist_paths"`
64
+ ExecAllowance int `yaml:"exec_allowance"`
65
+ ForkAllowance int `yaml:"fork_allowance"`
66
+ MaxChildProcs uint `yaml:"max_child_procs"`
67
+ ExtraEnvs []string `yaml:"extra_envs"`
68
+ PreservedEnvKeys []string `yaml:"preserved_env_keys"`
69
+ TracedSyscalls []string `yaml:"traced_syscalls"`
70
+ AllowedSyscalls []string `yaml:"allowed_syscalls"`
51
71
}
52
72
53
73
var defaultConf PolicyConf
@@ -64,12 +84,12 @@ func init() {
64
84
"OP_STAT" : OP_STAT ,
65
85
"OP_CHMOD" : OP_CHMOD ,
66
86
}
67
- defaultConf .WhitelistPaths = map [PathOps ][]string {
68
- OP_OPEN : []string { },
69
- OP_ACCESS : []string { },
70
- OP_EXEC : []string { },
71
- OP_STAT : []string { },
72
- OP_CHMOD : []string { "/home/work/" , "/tmp/" },
87
+ defaultConf .WhitelistPaths = map [PathOps ][]PatternMatcher {
88
+ OP_OPEN : []PatternMatcher { PatternMatcher { glob . MustCompile ( "*" )} },
89
+ OP_ACCESS : []PatternMatcher { PatternMatcher { glob . MustCompile ( "*" )} },
90
+ OP_EXEC : []PatternMatcher { PatternMatcher { glob . MustCompile ( "*" )} },
91
+ OP_STAT : []PatternMatcher { PatternMatcher { glob . MustCompile ( "*" )} },
92
+ OP_CHMOD : []PatternMatcher { PatternMatcher { glob . MustCompile ( "/home/work/*" )}, PatternMatcher { glob . MustCompile ( "/tmp/*" )} },
73
93
}
74
94
defaultConf .ExecAllowance = 0
75
95
defaultConf .ForkAllowance = - 1
0 commit comments