Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(probe): send policy data along with policy name in Probe Service #1825

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions KubeArmor/core/karmorprobedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ package core

import (
"context"
"encoding/json"
"fmt"

"github.com/golang/protobuf/ptypes/empty"
kl "github.com/kubearmor/KubeArmor/KubeArmor/common"
cfg "github.com/kubearmor/KubeArmor/KubeArmor/config"
tp "github.com/kubearmor/KubeArmor/KubeArmor/types"
"github.com/kubearmor/KubeArmor/protobuf"
pb "github.com/kubearmor/KubeArmor/protobuf"
)

Expand Down Expand Up @@ -89,15 +92,21 @@ func (dm *KubeArmorDaemon) SetProbeContainerData() ([]string, map[string]*pb.Con
for _, ep := range dm.EndPoints {

var policyNames []string
var policyData []*protobuf.Policy

for _, policy := range ep.SecurityPolicies {

policyNames = append(policyNames, policy.Metadata["policyName"])
policyEventData, err := json.Marshal(policy)
if err == nil {
policyData = append(policyData, &protobuf.Policy{Policy: policyEventData})
}

}
containerMap[ep.EndPointName] = &pb.ContainerData{
PolicyList: policyNames,
PolicyEnabled: int32(ep.PolicyEnabled),
PolicyList: policyNames,
PolicyEnabled: int32(ep.PolicyEnabled),
PolicyListData: policyData,
}
}
dm.EndPointsLock.Unlock()
Expand All @@ -113,12 +122,23 @@ func (dm *KubeArmorDaemon) SetProbeContainerData() ([]string, map[string]*pb.Con
if val, ok := hostMap[hostName]; ok {

val.PolicyList = append(val.PolicyList, hp.Metadata["policyName"])
policyEventData, err := json.Marshal(hp)
if err == nil {
val.PolicyListData = append(val.PolicyListData, &protobuf.Policy{Policy: policyEventData})
} else {
dm.Logger.Errf(err.Error())
}

hostMap[hostName] = val

} else {

policyEventData, err := json.Marshal(hp)
if err != nil {
dm.Logger.Errf(err.Error())
}
hostMap[hostName] = &pb.HostSecurityPolicies{
PolicyList: []string{hp.Metadata["policyName"]},
PolicyList: []string{hp.Metadata["policyName"]},
PolicyListData: []*protobuf.Policy{{Policy: policyEventData}},
}

}
Expand All @@ -133,6 +153,7 @@ func (dm *KubeArmorDaemon) SetProbeContainerData() ([]string, map[string]*pb.Con
func (p *Probe) GetProbeData(c context.Context, in *empty.Empty) (*pb.ProbeResponse, error) {

containerList, containerMap, hostMap := p.GetContainerData()
fmt.Printf("\n\nProbe called : Host Data %v\n\n", hostMap["pop-os"].PolicyListData)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hope this is a debug statement

Suggested change
fmt.Printf("\n\nProbe called : Host Data %v\n\n", hostMap["pop-os"].PolicyListData)

res := &pb.ProbeResponse{
ContainerList: containerList,
ContainerMap: containerMap,
Expand Down
2 changes: 1 addition & 1 deletion KubeArmor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ require (
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions KubeArmor/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuB
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ=
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw=
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f h1:RARaIm8pxYuxyNPbBQf5igT7XdOyCNtat1qAT2ZxjU4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf h1:liao9UHurZLtiEwBgT9LMOnKYsHze6eA6w1KQCMVN2Q=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
Expand Down
173 changes: 99 additions & 74 deletions protobuf/policy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading