Skip to content

Commit c8fb418

Browse files
rushk014xingzhang-suse
authored andcommitted
fix(rbac): Remove services API call from critical path for namespace resolution
Since `nvVariables.ns` defaults to `cattle-neuvector-system` (NV_POD_NAMESPACE), which is the required namespace for NV+Rancher SSO to work, we can safely drop the services fetch on every page load Fixes RBAC issues with the services API — the fetch was gating loadData() and causing pages to fail to render for restricted users
1 parent fa719eb commit c8fb418

6 files changed

Lines changed: 5 additions & 48 deletions

File tree

pkg/neuvector-ui-ext/components/Compliance/Compliance.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import ComplianceItemsDetail from './contents/ComplianceItemsDetail.vue';
1111
import ComplianceItemsChart from './contents/ComplianceItemsChart.vue';
1212
import { getDomains, getContainerBrief, getAvailableFilters, getCompliance } from '../../plugins/compliance-class';
13-
import { SERVICE } from '@shell/config/types';
13+
1414
import { nvVariables, NV_CONST } from '../../types';
1515
import { arrayToCsv, setRisks } from '../../utils/common';
1616
import { refreshAuth } from '../../plugins/neuvector-class';
@@ -34,12 +34,6 @@
3434
Error
3535
},
3636
async fetch() {
37-
if ( this.$store.getters['cluster/canList'](SERVICE) ) {
38-
this.allServices = await this.$store.dispatch('cluster/findAll', { type: SERVICE }, { root: true });
39-
if ( Array.isArray(this.allServices) && this.allServices.length ) {
40-
nvVariables.ns = this.allServices.find(svc => svc?.id?.includes(NV_CONST.NV_SERVICE)).metadata.namespace
41-
}
42-
}
4337
this.currentCluster = this.$store.getters['currentCluster'];
4438
nvVariables.currentCluster = this.currentCluster.id;
4539
await this.loadData();

pkg/neuvector-ui-ext/components/NetworkRules/NetworkRules.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
import Loading from '@shell/components/Loading';
3-
import { SERVICE } from '@shell/config/types';
3+
44
import { nvVariables, NV_CONST, NV_MAP } from '../../types/neuvector';
55
import { refreshAuth } from '../../plugins/neuvector-class';
66
import { getAutoCompleteData } from '../../plugins/network-rule-class';
@@ -45,12 +45,6 @@ export default {
4545
},
4646
4747
async fetch() {
48-
if ( this.$store.getters['cluster/canList'](SERVICE) ) {
49-
this.allServices = await this.$store.dispatch('cluster/findAll', { type: SERVICE }, { root: true });
50-
if ( Array.isArray(this.allServices) && this.allServices.length ) {
51-
nvVariables.ns = this.allServices.find(svc => svc?.id?.includes(NV_CONST.NV_SERVICE)).metadata.namespace
52-
}
53-
}
5448
this.currentCluster = this.$store.getters['currentCluster'];
5549
nvVariables.currentCluster = this.currentCluster.id;
5650
await this.loadData();

pkg/neuvector-ui-ext/components/ResponseRules/ResponseRules.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
import Loading from '@shell/components/Loading';
3-
import { SERVICE } from '@shell/config/types';
3+
44
import { nvVariables, NV_CONST } from '../../types/neuvector';
55
import { refreshAuth } from '../../plugins/neuvector-class';
66
import { destructConditions } from '../../utils/response-rules';
@@ -39,12 +39,6 @@
3939
this.$store.dispatch('neuvector/cacheResponseRules', null);
4040
},
4141
async fetch() {
42-
if ( this.$store.getters['cluster/canList'](SERVICE) ) {
43-
this.allServices = await this.$store.dispatch('cluster/findAll', { type: SERVICE }, { root: true });
44-
if ( Array.isArray(this.allServices) && this.allServices.length ) {
45-
nvVariables.ns = this.allServices.find(svc => svc?.id?.includes(NV_CONST.NV_SERVICE)).metadata.namespace
46-
}
47-
}
4842
this.currentCluster = this.$store.getters['currentCluster'];
4943
nvVariables.currentCluster = this.currentCluster.id;
5044
await this.loadData();

pkg/neuvector-ui-ext/components/SecurityEvents/SecurityEventsView.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { SERVICE } from '@shell/config/types';
2+
33
import { vTooltip } from 'floating-vue';
44
import { refreshAuth } from '../../plugins/neuvector-class';
55
import { getSecEvents } from '../../plugins/security-events-class';
@@ -47,12 +47,6 @@ import Packet from './dialogs/Packet';
4747
Error,
4848
},
4949
async fetch() {
50-
if ( this.$store.getters['cluster/canList'](SERVICE) ) {
51-
this.allServices = await this.$store.dispatch('cluster/findAll', { type: SERVICE }, { root: true });
52-
if ( Array.isArray(this.allServices) && this.allServices.length ) {
53-
nvVariables.ns = this.allServices.find(svc => svc?.id?.includes(NV_CONST.NV_SERVICE)).metadata.namespace
54-
}
55-
}
5650
this.currentCluster = this.$store.getters['currentCluster'];
5751
nvVariables.currentCluster = this.currentCluster.id;
5852
await this.loadData();

pkg/neuvector-ui-ext/components/Vulnerabilities/Vulnerabilities.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import VulnerabilityItemsDetail from './contents/VulnerabilityItemsDetail.vue';
1212
import AdvancedFilterModal from './dialogs/AdvancedFilterModal.vue';
1313
import { getDomains, postVulnerabilityQuery } from '../../plugins/vulnerabilities-class';
14-
import { SERVICE } from '@shell/config/types';
14+
1515
import { nvVariables, NV_CONST } from '../../types';
1616
import { refreshAuth } from '../../plugins/neuvector-class';
1717
import { initVulQuery } from '../../utils/vulnerabilities';
@@ -35,12 +35,6 @@
3535
Error,
3636
},
3737
async fetch() {
38-
if ( this.$store.getters['cluster/canList'](SERVICE) ) {
39-
this.allServices = await this.$store.dispatch('cluster/findAll', { type: SERVICE }, { root: true });
40-
if ( Array.isArray(this.allServices) && this.allServices.length ) {
41-
nvVariables.ns = this.allServices.find(svc => svc?.id?.includes(NV_CONST.NV_SERVICE)).metadata.namespace
42-
}
43-
}
4438
this.currentCluster = this.$store.getters['currentCluster'];
4539
nvVariables.currentCluster = this.currentCluster.id;
4640
try {

pkg/neuvector-ui-ext/utils/common.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { NV_CONST, nvVariables } from "../types/neuvector";
22
import dayjs from "dayjs";
3-
import { SERVICE } from "@shell/config/types";
43
import { Store } from "vuex";
54
import axios from '../interceptor/http-interceptor'
65

@@ -276,18 +275,6 @@ export function setRisks(risks: any, workloadMap: any) {
276275
export async function cacheNvNamespace(store: Store<any>) {
277276
let currentCluster = store.getters["currentCluster"];
278277
nvVariables.currentCluster = currentCluster.id;
279-
if (store.getters["cluster/canList"](SERVICE)) {
280-
let allServices = await store.dispatch(
281-
"cluster/findAll",
282-
{ type: SERVICE },
283-
{ root: true }
284-
);
285-
if (Array.isArray(allServices) && allServices.length) {
286-
nvVariables.ns = allServices.find((svc) =>
287-
svc?.id?.includes(NV_CONST.NV_SERVICE)
288-
).metadata.namespace;
289-
}
290-
}
291278
}
292279

293280
export function loadPagedData(

0 commit comments

Comments
 (0)