Skip to content

Commit

Permalink
Allow empty securityContext (#1462)
Browse files Browse the repository at this point in the history
Let OpenShift pick its own users, don't hardcode them

Co-authored-by: MinIO Bot <minio.bot@minio.io>
  • Loading branch information
cniackz and MinIO Bot committed Mar 14, 2023
1 parent 85dcede commit 11e20b4
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions pkg/resources/statefulsets/minio-statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,28 +424,41 @@ func poolSecurityContext(pool *miniov2.Pool, status *miniov2.PoolStatus) *v1.Pod

// Builds the security context for containers in a Pool
func poolContainerSecurityContext(pool *miniov2.Pool) *v1.SecurityContext {
// Default values:
// By default, values should be totally empty if not provided
// This is specially needed in OpenShift where Security Context Constraints restrict them
// if let empty then OCP can pick the values from the constraints defined.
containerSecurityContext := corev1.SecurityContext{}
runAsNonRoot := true
var runAsUser int64 = 1000
var runAsGroup int64 = 1000
// Default to Pod values
poolSCSet := false

// Values from pool.SecurityContext ONLY if provided
if pool.SecurityContext != nil {
if pool.SecurityContext.RunAsNonRoot != nil {
runAsNonRoot = *pool.SecurityContext.RunAsNonRoot
poolSCSet = true
}
if pool.SecurityContext.RunAsUser != nil {
runAsUser = *pool.SecurityContext.RunAsUser
poolSCSet = true
}
if pool.SecurityContext.RunAsGroup != nil {
runAsGroup = *pool.SecurityContext.RunAsGroup
poolSCSet = true
}
if poolSCSet {
// Only set values if one of above is set otherwise let it empty
containerSecurityContext = corev1.SecurityContext{
RunAsNonRoot: &runAsNonRoot,
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
}
}
}

containerSecurityContext := corev1.SecurityContext{
RunAsNonRoot: &runAsNonRoot,
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
}

// Values from pool.ContainerSecurityContext if provided
if pool != nil && pool.ContainerSecurityContext != nil {
containerSecurityContext = *pool.ContainerSecurityContext
}
Expand Down

0 comments on commit 11e20b4

Please sign in to comment.