-
Notifications
You must be signed in to change notification settings - Fork 51
/
uid.go
43 lines (34 loc) · 1.1 KB
/
uid.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
package extractors
import (
"fmt"
"strconv"
"strings"
"go.aporeto.io/trireme-lib/v11/common"
"go.aporeto.io/trireme-lib/v11/policy"
"go.aporeto.io/trireme-lib/v11/utils/cgnetcls"
)
// UIDMetadataExtractor is a metadata extractor for uid/gid.
func UIDMetadataExtractor(event *common.EventInfo) (*policy.PURuntime, error) {
runtimeTags := policy.NewTagStore()
for _, tag := range event.Tags {
parts := strings.SplitN(tag, "=", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("invalid tag: %s", tag)
}
// TODO: Remove OLDTAGS
runtimeTags.AppendKeyValue("@sys:"+parts[0], parts[1])
runtimeTags.AppendKeyValue("@app:linux:"+parts[0], parts[1])
}
if event.Name == "" {
event.Name = event.PUID
}
// TODO: improve with additional information here.
options := &policy.OptionsType{
CgroupName: event.PUID,
CgroupMark: strconv.FormatUint(cgnetcls.MarkVal(), 10),
UserID: event.PUID,
Services: event.Services,
}
runtimeIps := policy.ExtendedMap{"bridge": "0.0.0.0/0"}
return policy.NewPURuntime(event.Name, int(event.PID), "", runtimeTags, runtimeIps, common.UIDLoginPU, options), nil
}