From 4c98e4637f695db4f5526cc01c0b013eee4aa4f9 Mon Sep 17 00:00:00 2001 From: pjuarezd Date: Mon, 21 Aug 2023 20:56:07 -0600 Subject: [PATCH] bugfix: empty securityContext breaks console process with nil 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) }