Skip to content

Commit

Permalink
fix hello message fields
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Nov 27, 2024
1 parent 3596d47 commit 9f54f58
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
17 changes: 16 additions & 1 deletion pkg/security/probe/custom_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
package probe

import (
coretags "github.com/DataDog/datadog-agent/comp/core/tagger/tags"
"github.com/DataDog/datadog-agent/pkg/process/procutil"
"github.com/DataDog/datadog-agent/pkg/security/events"
"github.com/DataDog/datadog-agent/pkg/security/proto/ebpfless"
"github.com/DataDog/datadog-agent/pkg/security/resolvers/tags"
"github.com/DataDog/datadog-agent/pkg/security/secl/model"
"github.com/DataDog/datadog-agent/pkg/security/secl/rules"
"github.com/DataDog/datadog-agent/pkg/security/seclog"
"github.com/DataDog/datadog-agent/pkg/security/serializers"
"github.com/DataDog/datadog-agent/pkg/security/utils"
)
Expand Down Expand Up @@ -71,7 +74,7 @@ func (e EBPFLessHelloMsgEvent) ToJSON() ([]byte, error) {
}

// NewEBPFLessHelloMsgEvent returns a eBPFLess hello custom event
func NewEBPFLessHelloMsgEvent(acc *events.AgentContainerContext, msg *ebpfless.HelloMsg, scrubber *procutil.DataScrubber) (*rules.Rule, *events.CustomEvent) {
func NewEBPFLessHelloMsgEvent(acc *events.AgentContainerContext, msg *ebpfless.HelloMsg, scrubber *procutil.DataScrubber, tagger tags.Tagger) (*rules.Rule, *events.CustomEvent) {
args := msg.EntrypointArgs
if scrubber != nil {
args, _ = scrubber.ScrubCommand(msg.EntrypointArgs)
Expand All @@ -81,6 +84,18 @@ func NewEBPFLessHelloMsgEvent(acc *events.AgentContainerContext, msg *ebpfless.H
NSID: msg.NSID,
}
evt.Container.ID = msg.ContainerContext.ID

if tagger != nil {
tags, err := tags.GetTagsOfContainer(tagger, msg.ContainerContext.ID)
if err != nil {
seclog.Errorf("Failed to get tags for container %s: %v", msg.ContainerContext.ID, err)
} else {
evt.Container.Name = utils.GetTagValue(coretags.EcsContainerName, tags)
evt.Container.ImageShortName = utils.GetTagValue(coretags.ShortImage, tags)
evt.Container.ImageTag = utils.GetTagValue(coretags.ImageTag, tags)
}
}

evt.EntrypointArgs = args

evt.FillCustomEventCommonFields(acc)
Expand Down
2 changes: 1 addition & 1 deletion pkg/security/probe/probe_ebpfless.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p *EBPFLessProbe) handleClientMsg(cl *client, msg *ebpfless.Message) {
case ebpfless.MessageTypeHello:
if cl.nsID == 0 {
p.probe.DispatchCustomEvent(
NewEBPFLessHelloMsgEvent(p.GetAgentContainerContext(), msg.Hello, p.probe.scrubber),
NewEBPFLessHelloMsgEvent(p.GetAgentContainerContext(), msg.Hello, p.probe.scrubber, p.probe.Opts.Tagger),
)

cl.nsID = msg.Hello.NSID
Expand Down
12 changes: 9 additions & 3 deletions pkg/security/resolvers/tags/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ func (t *DefaultResolver) Resolve(id string) []string {

// ResolveWithErr returns the tags for the given id
func (t *DefaultResolver) ResolveWithErr(id string) ([]string, error) {
if t.tagger == nil {
return GetTagsOfContainer(t.tagger, id)
}

// GetTagsOfContainer returns the tags for the given container id
// exported to share the code with other non-resolver users of tagger
func GetTagsOfContainer(tagger Tagger, containerID string) ([]string, error) {
if tagger == nil {
return nil, nil
}

entityID := types.NewEntityID(types.ContainerID, id)
return t.tagger.Tag(entityID, types.OrchestratorCardinality)
entityID := types.NewEntityID(types.ContainerID, containerID)
return tagger.Tag(entityID, types.OrchestratorCardinality)
}

// GetValue return the tag value for the given id and tag name
Expand Down

0 comments on commit 9f54f58

Please sign in to comment.