Error 404 when editing non-Cilium network policies in Threat Monitoring
Summary
In Threat Monitoring > Policies, it is impossible to edit custom network policies that don't have the Cilium kind.
Steps to reproduce
- Open https://staging.gitlab.com/defend-team-test/cnp-alert-demo/-/threat_monitoring.
- Select the Policies tab.
- Select
New policy. - Give the policy a name.
- Switch to the
.yaml modeeditor. - Replace the kind line (
kind: CiliumNetworkPolicy) tokind: NetworkPolicy. - Save the policy.
- Back in the policy list, select the policy you've just created.
- In the drawer, click on
Edit policy.
Example Project
https://staging.gitlab.com/defend-team-test/cnp-alert-demo/-/threat_monitoring
What is the current bug behavior?
Error 404.
What is the expected correct behavior?
No error 404.
Implementation plan
-
backend update NetworkPolicyTypewith new field:kind, -
frontend read value of kindfield and use it when creatingeditPolicyPath:
diff --git a/ee/app/assets/javascripts/threat_monitoring/components/policy_list.vue b/ee/app/assets/javascripts/threat_monitoring/components/policy_list.vue
index f3a3900fdc2..4737547f660 100644
--- a/ee/app/assets/javascripts/threat_monitoring/components/policy_list.vue
+++ b/ee/app/assets/javascripts/threat_monitoring/components/policy_list.vue
@@ -99,6 +99,7 @@ export default {
data() {
return {
selectedPolicyName: null,
+ selectedPolicyKind: null,
initialManifest: null,
initialEnforcementStatus: null,
networkPolicies: [],
@@ -141,7 +142,7 @@ export default {
editPolicyPath() {
return this.hasSelectedPolicy
? mergeUrlParams(
- { environment_id: this.currentEnvironmentId },
+ { environment_id: this.currentEnvironmentId, kind: this.selectedPolicyKind },
this.newPolicyPath.replace('new', `${this.selectedPolicyName}/edit`),
)
: '';
@@ -192,11 +193,13 @@ export default {
const [selectedPolicy] = rows;
this.selectedPolicyName = selectedPolicy?.name;
+ this.selectedPolicyKind = selectedPolicy?.kind;
this.initialManifest = selectedPolicy?.yaml;
this.initialEnforcementStatus = selectedPolicy?.enabled;
},
deselectPolicy() {
this.selectedPolicyName = null;
+ this.selectedPolicyKind = null;
const bTable = this.$refs.policiesTable.$children[0];
bTable.clearSelected();
-
backend update https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/controllers/projects/threat_monitoring_controller.rb#L27 to accept :kindfrom params (kind[:params]):CiliumNetworkPolicy/NetworkPolicy: we need to parse it and provide proper constant to https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/services/network_policies/find_resource_service.rb#L7
Edited by Alan (Maciej) Paruszewski