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

Fixes bug #1787 non-k8s: KubeArmor panics when not-enabled policy type is received #1789

Merged
merged 1 commit into from
Aug 12, 2024
Merged
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
5 changes: 4 additions & 1 deletion KubeArmor/core/kubeArmor.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,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 @@ -14,17 +14,23 @@
)

// 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) {
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 @@

// 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) {

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.

Loading