forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacl_manager.go
190 lines (142 loc) · 3.94 KB
/
acl_manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package services
import (
"www.velocidex.com/golang/velociraptor/acls"
acl_proto "www.velocidex.com/golang/velociraptor/acls/proto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
)
type ACLManager interface {
GetPolicy(
config_obj *config_proto.Config,
principal string) (*acl_proto.ApiClientACL, error)
GetEffectivePolicy(
config_obj *config_proto.Config,
principal string) (*acl_proto.ApiClientACL, error)
SetPolicy(
config_obj *config_proto.Config,
principal string, acl_obj *acl_proto.ApiClientACL) error
CheckAccess(
config_obj *config_proto.Config,
principal string,
permissions ...acls.ACL_PERMISSION) (bool, error)
GrantRoles(
config_obj *config_proto.Config,
principal string,
roles []string) error
}
func GetACLManager(config_obj *config_proto.Config) (ACLManager, error) {
org_manager, err := GetOrgManager()
if err != nil {
return nil, err
}
return org_manager.Services(config_obj.OrgId).ACLManager()
}
// Some helpers for quick access to ACL manager
func GetPolicy(
config_obj *config_proto.Config,
principal string) (*acl_proto.ApiClientACL, error) {
acl_manager, err := GetACLManager(config_obj)
if err != nil {
return nil, err
}
return acl_manager.GetPolicy(config_obj, principal)
}
func GetEffectivePolicy(
config_obj *config_proto.Config,
principal string) (*acl_proto.ApiClientACL, error) {
acl_manager, err := GetACLManager(config_obj)
if err != nil {
return nil, err
}
return acl_manager.GetEffectivePolicy(config_obj, principal)
}
func SetPolicy(
config_obj *config_proto.Config,
principal string, acl_obj *acl_proto.ApiClientACL) error {
acl_manager, err := GetACLManager(config_obj)
if err != nil {
return err
}
return acl_manager.SetPolicy(config_obj, principal, acl_obj)
}
func CheckAccess(
config_obj *config_proto.Config,
principal string,
permissions ...acls.ACL_PERMISSION) (bool, error) {
acl_manager, err := GetACLManager(config_obj)
if err != nil {
return false, err
}
return acl_manager.CheckAccess(config_obj, principal, permissions...)
}
func CheckAccessWithToken(
token *acl_proto.ApiClientACL,
permission acls.ACL_PERMISSION, args ...string) (bool, error) {
// The super user can do everything.
if token.SuperUser {
return true, nil
}
// Requested permission
switch permission {
case acls.ALL_QUERY:
return token.AllQuery, nil
case acls.ANY_QUERY:
return token.AnyQuery, nil
case acls.PUBLISH:
if len(args) == 1 {
for _, allowed_queue := range token.PublishQueues {
if allowed_queue == args[0] {
return true, nil
}
}
}
case acls.READ_RESULTS:
return token.ReadResults, nil
case acls.LABEL_CLIENT:
return token.LabelClients, nil
case acls.COLLECT_CLIENT:
return token.CollectClient, nil
case acls.COLLECT_BASIC:
return token.CollectBasic, nil
case acls.START_HUNT:
return token.StartHunt, nil
case acls.COLLECT_SERVER:
return token.CollectServer, nil
case acls.ARTIFACT_WRITER:
return token.ArtifactWriter, nil
case acls.SERVER_ARTIFACT_WRITER:
return token.ServerArtifactWriter, nil
case acls.EXECVE:
return token.Execve, nil
case acls.NOTEBOOK_EDITOR:
return token.NotebookEditor, nil
case acls.SERVER_ADMIN:
return token.ServerAdmin, nil
case acls.ORG_ADMIN:
return token.OrgAdmin, nil
case acls.IMPERSONATION:
return token.Impersonation, nil
case acls.FILESYSTEM_READ:
return token.FilesystemRead, nil
case acls.FILESYSTEM_WRITE:
return token.FilesystemWrite, nil
case acls.MACHINE_STATE:
return token.MachineState, nil
case acls.PREPARE_RESULTS:
return token.PrepareResults, nil
case acls.DELETE_RESULTS:
return token.DeleteResults, nil
case acls.DATASTORE_ACCESS:
return token.DatastoreAccess, nil
}
return false, nil
}
func GrantRoles(
config_obj *config_proto.Config,
principal string,
roles []string) error {
acl_manager, err := GetACLManager(config_obj)
if err != nil {
return err
}
return acl_manager.GrantRoles(config_obj, principal, roles)
}