-
Notifications
You must be signed in to change notification settings - Fork 51
/
ssh.go
42 lines (32 loc) · 1.05 KB
/
ssh.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
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"
)
// SSHMetadataExtractor is a metadata extractor for ssh.
func SSHMetadataExtractor(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)
}
// This means we send something that is for internal purposes only
// We add it as it is.
if strings.HasPrefix(tag, "$") {
runtimeTags.AppendKeyValue(parts[0], parts[1])
continue
}
runtimeTags.AppendKeyValue("@user:ssh:"+parts[0], parts[1])
}
options := &policy.OptionsType{
CgroupName: event.PUID,
CgroupMark: strconv.FormatUint(cgnetcls.MarkVal(), 10),
}
runtimeIps := policy.ExtendedMap{"bridge": "0.0.0.0/0"}
return policy.NewPURuntime(event.Name, int(event.PID), "", runtimeTags, runtimeIps, event.PUType, options), nil
}