Skip to content

Commit cce054b

Browse files
authored
Create security context component and add to edit Prometheus Monitoring (#2115)
1 parent cf0e326 commit cce054b

File tree

9 files changed

+200
-7
lines changed

9 files changed

+200
-7
lines changed

models/tenant_monitoring_info.go

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operatorapi/embedded_spec.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operatorapi/tenants.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,11 +2137,10 @@ func getTenantMonitoringResponse(session *models.Principal, params operator_api.
21372137
client: opClientClientSet,
21382138
}
21392139

2140-
minInst, err := opClient.TenantGet(ctx, params.Namespace, params.Tenant, metav1.GetOptions{})
2140+
minInst, err := getTenant(ctx, opClient, params.Namespace, params.Tenant)
21412141
if err != nil {
21422142
return nil, restapi.ErrorWithContext(ctx, err)
21432143
}
2144-
21452144
monitoringInfo := &models.TenantMonitoringInfo{}
21462145

21472146
if minInst.Spec.Prometheus != nil {
@@ -2212,7 +2211,9 @@ func getTenantMonitoringResponse(session *models.Principal, params operator_api.
22122211
if len(minInst.Spec.Prometheus.SideCarImage) != 0 {
22132212
monitoringInfo.SidecarImage = minInst.Spec.Prometheus.SideCarImage
22142213
}
2215-
2214+
if minInst.Spec.Prometheus.SecurityContext != nil {
2215+
monitoringInfo.SecurityContext = convertK8sSCToModelSC(minInst.Spec.Prometheus.SecurityContext)
2216+
}
22162217
return monitoringInfo, nil
22172218
}
22182219

@@ -2306,12 +2307,16 @@ func setTenantMonitoringResponse(session *models.Principal, params operator_api.
23062307
if err == nil {
23072308
*minTenant.Spec.Prometheus.DiskCapacityDB = diskCapacityGB
23082309
}
2310+
23092311
minTenant.Spec.Prometheus.ServiceAccountName = params.Data.ServiceAccountName
2312+
minTenant.Spec.Prometheus.SecurityContext, err = convertModelSCToK8sSC(params.Data.SecurityContext)
2313+
if err != nil {
2314+
return false, restapi.ErrorWithContext(ctx, err)
2315+
}
23102316
_, err = opClient.TenantUpdate(ctx, minTenant, metav1.UpdateOptions{})
23112317
if err != nil {
23122318
return false, restapi.ErrorWithContext(ctx, err)
23132319
}
2314-
23152320
return true, nil
23162321
}
23172322

portal-ui/src/screens/Console/Tenants/ListTenants/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export interface ITenantMonitoringStruct {
199199
prometheusEnabled: boolean;
200200
monitoringCPURequest: string;
201201
monitoringMemRequest: string;
202+
securityContext: ISecurityContext;
202203
}
203204

204205
export interface IKeyValue {

portal-ui/src/screens/Console/Tenants/TenantDetails/EditTenantMonitoringScreen.tsx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//import { ISecurityContext} from "../types";
1817
import { Theme } from "@mui/material/styles";
1918
import createStyles from "@mui/styles/createStyles";
2019
import withStyles from "@mui/styles/withStyles";
@@ -56,9 +55,13 @@ import {
5655
setServiceAccountName,
5756
setCPURequest,
5857
setMemRequest,
58+
setRunAsGroup,
59+
setFSGroup,
60+
setRunAsUser,
61+
setRunAsNonRoot,
5962
} from "../TenantDetails/tenantMonitoringSlice";
60-
6163
import { clearValidationError } from "../utils";
64+
import SecurityContextSelector from "../securityContextSelector";
6265

6366
interface ITenantMonitoring {
6467
classes: any;
@@ -135,6 +138,18 @@ const TenantMonitoring = ({ classes }: ITenantMonitoring) => {
135138
const [annotationsError, setAnnotationsError] = useState<any>({});
136139
const [nodeSelectorError, setNodeSelectorError] = useState<any>({});
137140

141+
const runAsGroup = useSelector(
142+
(state: AppState) => state.editTenantMonitoring.runAsGroup
143+
);
144+
const runAsUser = useSelector(
145+
(state: AppState) => state.editTenantMonitoring.runAsUser
146+
);
147+
const fsGroup = useSelector(
148+
(state: AppState) => state.editTenantMonitoring.fsGroup
149+
);
150+
const runAsNonRoot = useSelector(
151+
(state: AppState) => state.editTenantMonitoring.runAsNonRoot
152+
);
138153
const cleanValidation = (fieldName: string) => {
139154
setValidationErrors(clearValidationError(validationErrors, fieldName));
140155
};
@@ -167,6 +182,10 @@ const TenantMonitoring = ({ classes }: ITenantMonitoring) => {
167182
res.nodeSelector != null
168183
? setNodeSelector(res.nodeSelector)
169184
: setNodeSelector([{ key: "", value: "" }]);
185+
dispatch(setRunAsGroup(res.securityContext.runAsGroup));
186+
dispatch(setRunAsUser(res.securityContext.runAsUser));
187+
dispatch(setRunAsNonRoot(res.securityContext.runAsNonRoot));
188+
dispatch(setFSGroup(res.securityContext.fsGroup));
170189
};
171190

172191
const trim = (x: IKeyValue[]): IKeyValue[] => {
@@ -221,6 +240,12 @@ const TenantMonitoring = ({ classes }: ITenantMonitoring) => {
221240

222241
const submitMonitoringInfo = () => {
223242
if (checkValid()) {
243+
const securityContext = {
244+
runAsGroup: runAsGroup != null ? runAsGroup : "0",
245+
runAsUser: runAsUser != null ? runAsUser : "0",
246+
fsGroup: fsGroup != null ? fsGroup : "0",
247+
runAsNonRoot: runAsNonRoot != null ? runAsNonRoot : true,
248+
};
224249
api
225250
.invoke(
226251
"PUT",
@@ -237,6 +262,7 @@ const TenantMonitoring = ({ classes }: ITenantMonitoring) => {
237262
storageClassName: storageClassName,
238263
monitoringCPURequest: cpuRequest,
239264
monitoringMemRequest: memRequest + "Gi",
265+
securityContext: securityContext,
240266
}
241267
)
242268
.then(() => {
@@ -312,7 +338,7 @@ const TenantMonitoring = ({ classes }: ITenantMonitoring) => {
312338
description=""
313339
/>
314340
</Grid>
315-
<Grid xs={12}>
341+
<Grid item xs={12}>
316342
<hr className={classes.hrClass} />
317343
</Grid>
318344
</Grid>
@@ -518,6 +544,21 @@ const TenantMonitoring = ({ classes }: ITenantMonitoring) => {
518544
/>
519545
</Grid>
520546
)}
547+
<Grid item xs={12} className={classes.formFieldRow}>
548+
<SecurityContextSelector
549+
classes={classes}
550+
runAsGroup={runAsGroup}
551+
runAsUser={runAsUser}
552+
fsGroup={fsGroup}
553+
runAsNonRoot={runAsNonRoot}
554+
setFSGroup={(value: string) => dispatch(setFSGroup(value))}
555+
setRunAsUser={(value: string) => dispatch(setRunAsUser(value))}
556+
setRunAsGroup={(value: string) => dispatch(setRunAsGroup(value))}
557+
setRunAsNonRoot={(value: boolean) =>
558+
dispatch(setRunAsNonRoot(value))
559+
}
560+
/>
561+
</Grid>
521562
<Grid item xs={12} textAlign={"right"}>
522563
<Button
523564
type="submit"

portal-ui/src/screens/Console/Tenants/TenantDetails/tenantMonitoringSlice.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export interface IEditTenantMonitoring {
2929
serviceAccountName: string;
3030
monitoringCPURequest: string;
3131
monitoringMemRequest: string;
32+
runAsUser: string;
33+
runAsGroup: string;
34+
fsGroup: string;
35+
runAsNonRoot: boolean;
3236
}
3337

3438
const initialState: IEditTenantMonitoring = {
@@ -44,6 +48,10 @@ const initialState: IEditTenantMonitoring = {
4448
serviceAccountName: "",
4549
monitoringCPURequest: "",
4650
monitoringMemRequest: "",
51+
runAsUser: "1000",
52+
runAsGroup: "1000",
53+
fsGroup: "1000",
54+
runAsNonRoot: true,
4755
};
4856

4957
export const editTenantMonitoringSlice = createSlice({
@@ -86,6 +94,18 @@ export const editTenantMonitoringSlice = createSlice({
8694
setMemRequest: (state, action: PayloadAction<string>) => {
8795
state.monitoringMemRequest = action.payload;
8896
},
97+
setRunAsUser: (state, action: PayloadAction<string>) => {
98+
state.runAsUser = action.payload;
99+
},
100+
setRunAsGroup: (state, action: PayloadAction<string>) => {
101+
state.runAsGroup = action.payload;
102+
},
103+
setFSGroup: (state, action: PayloadAction<string>) => {
104+
state.fsGroup = action.payload;
105+
},
106+
setRunAsNonRoot: (state, action: PayloadAction<boolean>) => {
107+
state.runAsNonRoot = action.payload;
108+
},
89109
},
90110
});
91111

@@ -102,6 +122,10 @@ export const {
102122
setServiceAccountName,
103123
setCPURequest,
104124
setMemRequest,
125+
setRunAsUser,
126+
setRunAsGroup,
127+
setFSGroup,
128+
setRunAsNonRoot,
105129
} = editTenantMonitoringSlice.actions;
106130

107131
export default editTenantMonitoringSlice.reducer;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2022 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
17+
import { IEditMonitoringSecurityContext } from "./types";
18+
19+
const initialState: IEditMonitoringSecurityContext = {
20+
securityContextEnabled: false,
21+
runAsUser: "1000",
22+
runAsGroup: "1000",
23+
fsGroup: "1000",
24+
runAsNonRoot: true,
25+
};
26+
27+
export const editMonitoringSecurityContextSlice = createSlice({
28+
name: "editMonitoringSecurityContext",
29+
initialState,
30+
reducers: {
31+
setSecurityContextEnabled: (state, action: PayloadAction<boolean>) => {
32+
state.securityContextEnabled = action.payload;
33+
},
34+
setRunAsUser: (state, action: PayloadAction<string>) => {
35+
state.runAsUser = action.payload;
36+
},
37+
setRunAsGroup: (state, action: PayloadAction<string>) => {
38+
state.runAsGroup = action.payload;
39+
},
40+
setFSGroup: (state, action: PayloadAction<string>) => {
41+
state.fsGroup = action.payload;
42+
},
43+
setRunAsNonRoot: (state, action: PayloadAction<boolean>) => {
44+
state.runAsNonRoot = action.payload;
45+
},
46+
},
47+
});
48+
49+
export const {
50+
setSecurityContextEnabled,
51+
setRunAsUser,
52+
setRunAsGroup,
53+
setFSGroup,
54+
setRunAsNonRoot,
55+
} = editMonitoringSecurityContextSlice.actions;
56+
57+
export default editMonitoringSecurityContextSlice.reducer;

portal-ui/src/screens/Console/Tenants/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,11 @@ export interface ITenantIdentityProviderResponse {
338338
user_dn_search_filter: string;
339339
};
340340
}
341+
342+
export interface IEditMonitoringSecurityContext {
343+
securityContextEnabled: boolean;
344+
runAsUser: string;
345+
runAsGroup: string;
346+
fsGroup: string;
347+
runAsNonRoot: boolean;
348+
}

swagger-operator.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,6 +3272,9 @@ definitions:
32723272
type: string
32733273
monitoringMemRequest:
32743274
type: string
3275+
securityContext:
3276+
type: object
3277+
$ref: "#/definitions/securityContext"
32753278

32763279
label:
32773280
type: object

0 commit comments

Comments
 (0)