From 93062a15334dd3122002d91f631636b4d4fbdcb1 Mon Sep 17 00:00:00 2001 From: Anurag Rajawat Date: Tue, 5 Mar 2024 10:18:24 +0530 Subject: [PATCH] fix(adapters): Update NP status on SecurityIntent update and deletion Signed-off-by: Anurag Rajawat --- pkg/adapter/nimbus-kubearmor/go.mod | 2 +- pkg/adapter/nimbus-kubearmor/go.sum | 4 ++-- .../nimbus-kubearmor/manager/manager.go | 18 ++++++----------- pkg/adapter/nimbus-netpol/go.mod | 2 +- pkg/adapter/nimbus-netpol/go.sum | 4 ++-- .../nimbus-netpol/manager/netpols_manager.go | 20 ++++++++----------- 6 files changed, 20 insertions(+), 30 deletions(-) diff --git a/pkg/adapter/nimbus-kubearmor/go.mod b/pkg/adapter/nimbus-kubearmor/go.mod index 70a8c0ba..b5cb7fb9 100644 --- a/pkg/adapter/nimbus-kubearmor/go.mod +++ b/pkg/adapter/nimbus-kubearmor/go.mod @@ -3,7 +3,7 @@ module github.com/5GSEC/nimbus/pkg/adapter/nimbus-kubearmor go 1.21 require ( - github.com/5GSEC/nimbus v0.0.0-20240220040009-4cc97b1338ad + github.com/5GSEC/nimbus v0.0.0-20240305043055-359d519c1d9f github.com/go-logr/logr v1.4.1 github.com/kubearmor/KubeArmor/pkg/KubeArmorController v0.0.0-20240125171707-8e6641511fe3 k8s.io/apimachinery v0.29.1 diff --git a/pkg/adapter/nimbus-kubearmor/go.sum b/pkg/adapter/nimbus-kubearmor/go.sum index 0154d514..418fc97b 100644 --- a/pkg/adapter/nimbus-kubearmor/go.sum +++ b/pkg/adapter/nimbus-kubearmor/go.sum @@ -1,5 +1,5 @@ -github.com/5GSEC/nimbus v0.0.0-20240220040009-4cc97b1338ad h1:vr8/EtADzXyAYOsZbG8KhSO7ClELdQMjWEfHde5C3yA= -github.com/5GSEC/nimbus v0.0.0-20240220040009-4cc97b1338ad/go.mod h1:YgeRR5ijLJHHeapCUekTfLJXMVrqOMVT2rCsqHlKLdU= +github.com/5GSEC/nimbus v0.0.0-20240305043055-359d519c1d9f h1:FOwBcqhGFm8RXXjgJTdBhjhb3k5UbaDOJ6TpK+5Zmvk= +github.com/5GSEC/nimbus v0.0.0-20240305043055-359d519c1d9f/go.mod h1:FflBHoOu8LpzZJucobgLdGG4j+22A97JX8cXlNY1fXc= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/pkg/adapter/nimbus-kubearmor/manager/manager.go b/pkg/adapter/nimbus-kubearmor/manager/manager.go index 7effd747..856f3acf 100644 --- a/pkg/adapter/nimbus-kubearmor/manager/manager.go +++ b/pkg/adapter/nimbus-kubearmor/manager/manager.go @@ -146,12 +146,9 @@ func createOrUpdateKsp(ctx context.Context, npName, npNamespace string) { logger.Info("KubeArmorPolicy configured", "KubeArmorPolicy.Name", existingKsp.Name, "KubeArmorPolicy.Namespace", existingKsp.Namespace) } - //TODO: Due to adapters' dependency on nimbus module, the docker image build is - // failing. The relevant code is commented out below (lines 153-155). We shall - // uncomment this code in a subsequent PR. - //if err = adapterutil.UpdateNpStatus(ctx, k8sClient, "KubeArmorPolicy/"+ksp.Name, np.Name, np.Namespace, false); err != nil { - // logger.Error(err, "failed to update KubeArmorPolicies status in NimbusPolicy") - //} + if err = adapterutil.UpdateNpStatus(ctx, k8sClient, "KubeArmorPolicy/"+ksp.Name, np.Name, np.Namespace, false); err != nil { + logger.Error(err, "failed to update KubeArmorPolicies status in NimbusPolicy") + } } } @@ -213,12 +210,9 @@ func deleteDanglingKsps(ctx context.Context, np intentv1.NimbusPolicy, logger lo continue } - //TODO: Due to adapters' dependency on nimbus module, the docker image build is - // failing. The relevant code is commented out below (lines 217-219). We shall - // uncomment this code in a subsequent PR. - //if err := adapterutil.UpdateNpStatus(ctx, k8sClient, "KubeArmorPolicy/"+ksp.Name, np.Name, np.Namespace, true); err != nil { - // logger.Error(err, "failed to update KubeArmorPolicy status in NimbusPolicy") - //} + if err := adapterutil.UpdateNpStatus(ctx, k8sClient, "KubeArmorPolicy/"+ksp.Name, np.Name, np.Namespace, true); err != nil { + logger.Error(err, "failed to update KubeArmorPolicy status in NimbusPolicy") + } logger.Info("Dangling KubeArmorPolicy deleted", "KubeArmorPolicy.Name", ksp.Name, "KubeArmorPolicy.Namespace", ksp.Namespace) } } diff --git a/pkg/adapter/nimbus-netpol/go.mod b/pkg/adapter/nimbus-netpol/go.mod index 8a3f7fab..287d0db6 100644 --- a/pkg/adapter/nimbus-netpol/go.mod +++ b/pkg/adapter/nimbus-netpol/go.mod @@ -3,7 +3,7 @@ module github.com/5GSEC/nimbus/pkg/adapter/nimbus-netpol go 1.21 require ( - github.com/5GSEC/nimbus v0.0.0-20240220040009-4cc97b1338ad + github.com/5GSEC/nimbus v0.0.0-20240305043055-359d519c1d9f github.com/go-logr/logr v1.4.1 k8s.io/api v0.29.1 k8s.io/apimachinery v0.29.1 diff --git a/pkg/adapter/nimbus-netpol/go.sum b/pkg/adapter/nimbus-netpol/go.sum index 160e902b..1b9f36b3 100644 --- a/pkg/adapter/nimbus-netpol/go.sum +++ b/pkg/adapter/nimbus-netpol/go.sum @@ -1,5 +1,5 @@ -github.com/5GSEC/nimbus v0.0.0-20240220040009-4cc97b1338ad h1:vr8/EtADzXyAYOsZbG8KhSO7ClELdQMjWEfHde5C3yA= -github.com/5GSEC/nimbus v0.0.0-20240220040009-4cc97b1338ad/go.mod h1:YgeRR5ijLJHHeapCUekTfLJXMVrqOMVT2rCsqHlKLdU= +github.com/5GSEC/nimbus v0.0.0-20240305043055-359d519c1d9f h1:FOwBcqhGFm8RXXjgJTdBhjhb3k5UbaDOJ6TpK+5Zmvk= +github.com/5GSEC/nimbus v0.0.0-20240305043055-359d519c1d9f/go.mod h1:FflBHoOu8LpzZJucobgLdGG4j+22A97JX8cXlNY1fXc= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/pkg/adapter/nimbus-netpol/manager/netpols_manager.go b/pkg/adapter/nimbus-netpol/manager/netpols_manager.go index aae8a006..9ccf701e 100644 --- a/pkg/adapter/nimbus-netpol/manager/netpols_manager.go +++ b/pkg/adapter/nimbus-netpol/manager/netpols_manager.go @@ -144,12 +144,10 @@ func createOrUpdateNetworkPolicy(ctx context.Context, npName, npNamespace string } logger.Info("NetworkPolicy configured", "NetworkPolicy.Name", netpol.Name, "NetworkPolicy.Namespace", netpol.Namespace) } - //TODO: Due to adapters' dependency on nimbus module, the docker image build is - // failing. The relevant code is commented out below (lines 150-152). We shall - // uncomment this code in a subsequent PR. - //if err = adapterutil.UpdateNpStatus(ctx, k8sClient, "NetworkPolicy/"+netpol.Name, np.Name, np.Namespace, false); err != nil { - // logger.Error(err, "failed to update NetworkPolicies status in NimbusPolicy") - //} + + if err = adapterutil.UpdateNpStatus(ctx, k8sClient, "NetworkPolicy/"+netpol.Name, np.Name, np.Namespace, false); err != nil { + logger.Error(err, "failed to update NetworkPolicies status in NimbusPolicy") + } } } @@ -211,12 +209,10 @@ func deleteDanglingNetpols(ctx context.Context, np intentv1.NimbusPolicy, logger logger.Error(err, "failed to delete dangling NetworkPolicy", "NetworkPolicy.Name", netpol.Namespace, "NetworkPolicy.Namespace", netpol.Namespace) continue } - //TODO: Due to adapters' dependency on nimbus module, the docker image build is - // failing. The relevant code is commented out below (lines 215-217). We shall - // uncomment this code in a subsequent PR. - //if err := adapterutil.UpdateNpStatus(ctx, k8sClient, "NetworkPolicy/"+netpol.Name, np.Name, np.Namespace, true); err != nil { - // logger.Error(err, "failed to update NetworkPolicy status in NimbusPolicy") - //} + + if err := adapterutil.UpdateNpStatus(ctx, k8sClient, "NetworkPolicy/"+netpol.Name, np.Name, np.Namespace, true); err != nil { + logger.Error(err, "failed to update NetworkPolicy status in NimbusPolicy") + } logger.Info("Dangling NetworkPolicy deleted", "NetworkPolicy.Name", netpol.Name, "NetworkPolicy.Namespace", netpol.Namespace) } }