-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
activity_dump_profile_proto_enc_v1.go
55 lines (46 loc) · 1.87 KB
/
activity_dump_profile_proto_enc_v1.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
//go:build linux
// Package dump holds dump related files
package dump
import (
"errors"
"time"
proto "github.com/DataDog/agent-payload/v5/cws/dumpsv1"
cgroupModel "github.com/DataDog/datadog-agent/pkg/security/resolvers/cgroup/model"
timeResolver "github.com/DataDog/datadog-agent/pkg/security/resolvers/time"
activity_tree "github.com/DataDog/datadog-agent/pkg/security/security_profile/activity_tree"
mtdt "github.com/DataDog/datadog-agent/pkg/security/security_profile/activity_tree/metadata"
)
// ActivityDumpToSecurityProfileProto serializes an Activity Dump to a Security Profile protobuf representation
func ActivityDumpToSecurityProfileProto(input *ActivityDump) (*proto.SecurityProfile, error) {
if input == nil {
return nil, errors.New("imput == nil")
}
wSelector := input.GetWorkloadSelector()
if wSelector == nil {
return nil, errors.New("can't get dump selector, tags shouldn't be resolved yet")
}
output := &proto.SecurityProfile{
Metadata: mtdt.ToProto(&input.Metadata),
ProfileContexts: make(map[string]*proto.ProfileContext),
Tree: activity_tree.ToProto(input.ActivityTree),
Selector: cgroupModel.WorkloadSelectorToProto(wSelector),
}
timeResolver, err := timeResolver.NewResolver()
if err != nil {
return nil, errors.New("can't init time resolver")
}
ts := uint64(timeResolver.ComputeMonotonicTimestamp(time.Now()))
ctx := &proto.ProfileContext{
Syscalls: input.ActivityTree.ComputeSyscallsList(),
Tags: make([]string, len(input.Tags)),
FirstSeen: ts,
LastSeen: ts,
}
copy(ctx.Tags, input.Tags)
output.ProfileContexts[wSelector.Tag] = ctx
return output, nil
}