Skip to content

Commit

Permalink
adding tarian-detection event to dgraph store
Browse files Browse the repository at this point in the history
  • Loading branch information
kumari-anupam committed Mar 18, 2024
1 parent 304d1f8 commit b60acd4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

6 changes: 6 additions & 0 deletions cmd/tarianctl/cmd/get/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func eventsTableOutput(events []*tarianpb.Event, logger *logrus.Logger) {
evt.WriteString("pod deleted")
}

if e.GetType() == tarianpb.EventTypeDetection {
detectionEventStr := fmt.Sprintf("detection: %s: %s", t.DetectionDataType, t.DetectionData)
evt.WriteString("tarian detection event\n")
evt.WriteString(detectionEventStr)
}

Check warning on line 168 in cmd/tarianctl/cmd/get/events.go

View check run for this annotation

Codecov / codecov/patch

cmd/tarianctl/cmd/get/events.go#L165-L168

Added lines #L165 - L168 were not covered by tests

evt.WriteString("\n")

table.Append(
Expand Down
2 changes: 1 addition & 1 deletion pkg/nodeagent/nodeagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (n *NodeAgent) loopTarianDetectorReadEvents(ctx context.Context) error {
}

n.SendDetectionEventToClusterAgent(detectionDataType, string(byteData))
n.logger.Info("tarian-detector: ", detectionDataType, "binary_file_path", event["directory"], "hostProcessId", event["hostProcessId"],
n.logger.Info("tarian-detector: ", detectionDataType, "binary_file_path", event["directory"].(string)+"/"+event["processName"].(string), "hostProcessId", event["hostProcessId"],
"processId", event["processId"], "comm", event["processName"])

Check warning on line 470 in pkg/nodeagent/nodeagent.go

View check run for this annotation

Codecov / codecov/patch

pkg/nodeagent/nodeagent.go#L468-L470

Added lines #L468 - L470 were not covered by tests
}
}()
Expand Down
18 changes: 14 additions & 4 deletions pkg/server/dgraphstore/dgraph_event_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func newDgraphEventStore(dgraphClient *dgo.Dgraph) store.EventStore {
return &dgraphEventStore{dgraphClient: dgraphClient}
}

// GetAll retrieves all events from the Dgraph store.
// GetAll retrieves all events from the Dgraph store, ignoring events
// with target_detection_data_type and target_detection_data.
//
// Parameters:
// - limit: The maximum number of events to retrieve.
Expand All @@ -33,12 +34,13 @@ func newDgraphEventStore(dgraphClient *dgo.Dgraph) store.EventStore {
// - An array of protobuf Event messages representing the retrieved events.
// - An error if there was an issue with the database query.
func (d *dgraphEventStore) GetAll(limit uint) ([]*tarianpb.Event, error) {
// Dgraph query to retrieve all events.
// Dgraph query to retrieve all events, ignoring events with
// target_detection_data_type and target_detection_data.

Check warning on line 38 in pkg/server/dgraphstore/dgraph_event_store.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/dgraphstore/dgraph_event_store.go#L37-L38

Added lines #L37 - L38 were not covered by tests
q := fmt.Sprintf(`
{
events(func: type(Event)) {
events(func: type(Event)) @filter(not has(target_detection_data_type) and not has(target_detection_data)) {

Check warning on line 41 in pkg/server/dgraphstore/dgraph_event_store.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/dgraphstore/dgraph_event_store.go#L41

Added line #L41 was not covered by tests
%s
}
}

Check warning on line 43 in pkg/server/dgraphstore/dgraph_event_store.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/dgraphstore/dgraph_event_store.go#L43

Added line #L43 was not covered by tests
}
`, eventFields)

Expand Down Expand Up @@ -127,6 +129,9 @@ func (d *dgraphEventList) toPbEvents() []*tarianpb.Event {
}
}

t.DetectionDataType = evtTarget.DetectionDataType
t.DetectionData = evtTarget.DetectionData

Check warning on line 134 in pkg/server/dgraphstore/dgraph_event_store.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/dgraphstore/dgraph_event_store.go#L132-L134

Added lines #L132 - L134 were not covered by tests
event.Targets = append(event.Targets, t)
}

Expand Down Expand Up @@ -159,6 +164,8 @@ const eventFields = `
pod_name
pod_labels
}
target_detection_data_type
target_detection_data
}
`

Expand Down Expand Up @@ -290,6 +297,9 @@ func dgraphEventFromPb(pbEvent *tarianpb.Event) (*Event, error) {
}
}

t.DetectionDataType = pbTarget.GetDetectionDataType()
t.DetectionData = pbTarget.GetDetectionData()

Check warning on line 302 in pkg/server/dgraphstore/dgraph_event_store.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/dgraphstore/dgraph_event_store.go#L300-L302

Added lines #L300 - L302 were not covered by tests
dgraphEvent.Targets = append(dgraphEvent.Targets, t)
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/server/dgraphstore/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ var schema = `
target_violated_processes: string . # JSON
target_violated_files: string . # JSON
target_falco_alert: string .
target_detection_data_type: string .
target_detection_data: string .
type Target {
pod: Pod
target_violated_processes
target_violated_files
target_falco_alert
tarian_detection_data_type
tarian_detection_data
}
`

Expand Down
14 changes: 8 additions & 6 deletions pkg/server/dgraphstore/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ type Event struct {

// Target represents a target in the Dgraph database.
type Target struct {
UID string `json:"uid,omitempty"` // Unique identifier of the target.
DType []string `json:"dgraph.type,omitempty"` // Type information for Dgraph.
ViolatedProcesses string `json:"target_violated_processes,omitempty"` // Violated processes associated with the target (in JSON format).
ViolatedFiles string `json:"target_violated_files,omitempty"` // Violated files associated with the target (in JSON format).
FalcoAlert string `json:"target_falco_alert,omitempty"` // Falco alert associated with the target (in JSON format).
Pod *Pod `json:"pod,omitempty"` // Pod associated with the target.
UID string `json:"uid,omitempty"` // Unique identifier of the target.
DType []string `json:"dgraph.type,omitempty"` // Type information for Dgraph.
ViolatedProcesses string `json:"target_violated_processes,omitempty"` // Violated processes associated with the target (in JSON format).
ViolatedFiles string `json:"target_violated_files,omitempty"` // Violated files associated with the target (in JSON format).
FalcoAlert string `json:"target_falco_alert,omitempty"` // Falco alert associated with the target (in JSON format).
Pod *Pod `json:"pod,omitempty"` // Pod associated with the target.
DetectionDataType string `json:"tarian_detection_data_type,omitempty"` // Type of the tarian detection data.
DetectionData string `json:"tarian_detection_data,omitempty"` // The tarian detection data in JSON format.
}

// Client is an interface for creating Dgraph clients.
Expand Down

0 comments on commit b60acd4

Please sign in to comment.