Skip to content

Commit

Permalink
Fixes bug #1787 when not-enabled policy type is received
Browse files Browse the repository at this point in the history
Signed-off-by: Cheithanya <cheithanya2002@gmail.com>
  • Loading branch information
itsCheithanya committed Jul 22, 2024
1 parent 9ce5979 commit b369910
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 46 deletions.
5 changes: 4 additions & 1 deletion KubeArmor/core/kubeArmor.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,10 @@ func KubeArmor() {
}

if !dm.K8sEnabled && (enableContainerPolicy || cfg.GlobalCfg.HostPolicy) {
policyService := &policy.PolicyServer{}
policyService := &policy.PolicyServer{
ContainerPolicyEnabled: enableContainerPolicy,
HostPolicyEnabled: cfg.GlobalCfg.HostPolicy,
}
if enableContainerPolicy {
policyService.UpdateContainerPolicy = dm.ParseAndUpdateContainerSecurityPolicy
dm.Logger.Print("Started to monitor container security policies on gRPC")
Expand Down
22 changes: 16 additions & 6 deletions KubeArmor/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ import (
// PolicyServer provides structure to serve Policy gRPC service
type PolicyServer struct {

Check warning on line 17 in KubeArmor/policy/policy.go

View workflow job for this annotation

GitHub Actions / go-lint

type name will be used as policy.PolicyServer by other packages, and that stutters; consider calling this Server
pb.PolicyServiceServer
UpdateContainerPolicy func(tp.K8sKubeArmorPolicyEvent) pb.PolicyStatus
UpdateHostPolicy func(tp.K8sKubeArmorHostPolicyEvent) pb.PolicyStatus
UpdateContainerPolicy func(tp.K8sKubeArmorPolicyEvent) pb.PolicyStatus
UpdateHostPolicy func(tp.K8sKubeArmorHostPolicyEvent) pb.PolicyStatus
ContainerPolicyEnabled bool
HostPolicyEnabled bool
}

// ContainerPolicy accepts container events on gRPC and update container security policies
func (p *PolicyServer) ContainerPolicy(c context.Context, data *pb.Policy) (*pb.Response, error) {

Check warning on line 26 in KubeArmor/policy/policy.go

View workflow job for this annotation

GitHub Actions / go-lint

parameter 'c' seems to be unused, consider removing or renaming it as _
policyEvent := tp.K8sKubeArmorPolicyEvent{}
res := new(pb.Response)

if !p.ContainerPolicyEnabled {
res.Status = pb.PolicyStatus_NotEnabled
kg.Warn("Container policies are not enabled")
return res, nil
}
policyEvent := tp.K8sKubeArmorPolicyEvent{}
err := json.Unmarshal(data.Policy, &policyEvent)

if err == nil {
Expand All @@ -50,9 +56,13 @@ func (p *PolicyServer) ContainerPolicy(c context.Context, data *pb.Policy) (*pb.

// HostPolicy accepts host policy event on gRPC service and updates host security policies. It responds with 1 if success else 0.
func (p *PolicyServer) HostPolicy(c context.Context, data *pb.Policy) (*pb.Response, error) {

Check warning on line 58 in KubeArmor/policy/policy.go

View workflow job for this annotation

GitHub Actions / go-lint

parameter 'c' seems to be unused, consider removing or renaming it as _

policyEvent := tp.K8sKubeArmorHostPolicyEvent{}
res := new(pb.Response)
if !p.HostPolicyEnabled {
res.Status = pb.PolicyStatus_NotEnabled
kg.Warn("Host policies are not enabled")
return res, nil
}
policyEvent := tp.K8sKubeArmorHostPolicyEvent{}

err := json.Unmarshal(data.Policy, &policyEvent)
if err == nil {
Expand Down
54 changes: 29 additions & 25 deletions protobuf/policy.pb.go

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

1 change: 1 addition & 0 deletions protobuf/policy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum PolicyStatus {
Modified = 3 ;
NotExist = 4;
Invalid = 5;
NotEnabled = 6 ;
}

message response {
Expand Down
31 changes: 17 additions & 14 deletions protobuf/policy_grpc.pb.go

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

0 comments on commit b369910

Please sign in to comment.