From 619699e1218bb1b785d47c4fe21bac44ef3ecade Mon Sep 17 00:00:00 2001 From: Pedro Juarez Date: Mon, 21 Aug 2023 21:30:02 -0600 Subject: [PATCH] bugfix: empty securityContext breaks console process with nil (#1736) Signed-off-by: pjuarezd --- api/tenants_helper.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/api/tenants_helper.go b/api/tenants_helper.go index a14eaea472d..495e4c16828 100644 --- a/api/tenants_helper.go +++ b/api/tenants_helper.go @@ -64,11 +64,20 @@ func convertModelSCToK8sSC(sc *models.SecurityContext) (*corev1.PodSecurityConte // convertK8sSCToModelSC validates and converts from corev1.PodSecurityContext to models.SecurityContext func convertK8sSCToModelSC(sc *corev1.PodSecurityContext) *models.SecurityContext { - runAsUser := strconv.FormatInt(*sc.RunAsUser, 10) - runAsGroup := strconv.FormatInt(*sc.RunAsGroup, 10) - fsGroup := strconv.FormatInt(*sc.FSGroup, 10) + var runAsUser string + var runAsGroup string + var fsGroup string fsGroupChangePolicy := "Always" + if sc.RunAsUser != nil && *sc.RunAsUser != 0 { + runAsUser = strconv.FormatInt(*sc.RunAsUser, 10) + } + if sc.RunAsGroup != nil && *sc.RunAsGroup != 0 { + runAsGroup = strconv.FormatInt(*sc.RunAsGroup, 10) + } + if sc.FSGroup != nil && *sc.FSGroup != 0 { + fsGroup = strconv.FormatInt(*sc.FSGroup, 10) + } if sc.FSGroupChangePolicy != nil { fsGroupChangePolicy = string(*sc.FSGroupChangePolicy) }