Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ContainerSecurityContext to Pools #1372

Merged
merged 17 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/kustomization/base/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ spec:
runAsGroup: 1000
runAsNonRoot: true
fsGroup: 1000
## Configure container security context
containerSecurityContext:
runAsUser: 1000
runAsGroup: 1000
runAsNonRoot: true
## Enable automatic Kubernetes based certificate generation and signing as explained in
## https://kubernetes.io/docs/tasks/tls/managing-tls-in-a-cluster
requestAutoCert: true
Expand Down
4 changes: 4 additions & 0 deletions examples/kustomization/tenant-lite/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ spec:
resources:
requests:
storage: 2Gi
containerSecurityContext:
runAsUser: 1000
runAsGroup: 1000
runAsNonRoot: true
4 changes: 4 additions & 0 deletions helm/tenant/templates/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ spec:
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with (dig "containerSecurityContext" (dict) .) }}
containerSecurityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with (dig "topologySpreadConstraints" (list) .) }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
Expand Down
9 changes: 9 additions & 0 deletions helm/tenant/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ tenant:
topologySpreadConstraints: [ ]
## Configure Runtime Class
# runtimeClassName: ""
securityContext:
cniackz marked this conversation as resolved.
Show resolved Hide resolved
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
runAsNonRoot: true
containerSecurityContext:
runAsUser: 1000
runAsGroup: 1000
runAsNonRoot: true
## Mount path where PV will be mounted inside container(s).
mountPath: /export
## Sub path inside Mount path where MinIO stores data.
Expand Down
12 changes: 10 additions & 2 deletions pkg/apis/minio.min.io/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,18 @@ type Pool struct {
//
// * `runAsUser` +
//
// * `seLinuxOptions` +
//
// +optional
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
// Specify the https://kubernetes.io/docs/tasks/configure-pod-container/security-context/[Security Context] of containers in the pool. The Operator supports only the following container security fields: +
//
// * `runAsGroup` +
//
// * `runAsNonRoot` +
//
// * `runAsUser` +
//
// +optional
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
// *Optional* +
//
// Specify custom labels and annotations to append to the Pool.
Expand Down
19 changes: 19 additions & 0 deletions pkg/resources/statefulsets/minio-statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func poolMinioServerContainer(t *miniov2.Tenant, wsSecret *v1.Secret, skipEnvVar
LivenessProbe: t.Spec.Liveness,
ReadinessProbe: t.Spec.Readiness,
StartupProbe: t.Spec.Startup,
SecurityContext: poolContainerSecurityContext(pool),
}
}

Expand Down Expand Up @@ -403,6 +404,24 @@ func poolSecurityContext(pool *miniov2.Pool, status *miniov2.PoolStatus) *v1.Pod
return &securityContext
}

// Builds the security context for containers in a Pool
func poolContainerSecurityContext(pool *miniov2.Pool) *v1.SecurityContext {
runAsNonRoot := true
var runAsUser int64 = 1000
var runAsGroup int64 = 1000

securityContext := corev1.SecurityContext{
harshavardhana marked this conversation as resolved.
Show resolved Hide resolved
RunAsNonRoot: &runAsNonRoot,
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
}

if pool != nil && pool.ContainerSecurityContext != nil {
securityContext = *pool.ContainerSecurityContext
}
return &securityContext
}

// NewPool creates a new StatefulSet for the given Cluster.
func NewPool(t *miniov2.Tenant, wsSecret *v1.Secret, skipEnvVars map[string][]byte, pool *miniov2.Pool, poolStatus *miniov2.PoolStatus, serviceName, hostsTemplate, operatorVersion string, operatorTLS bool, operatorCATLS bool) *appsv1.StatefulSet {
var podVolumes []corev1.Volume
Expand Down
61 changes: 61 additions & 0 deletions resources/base/crds/minio.min.io_tenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7647,6 +7647,67 @@ spec:
additionalProperties:
type: string
type: object
containerSecurityContext:
properties:
allowPrivilegeEscalation:
type: boolean
capabilities:
properties:
add:
items:
type: string
type: array
drop:
items:
type: string
type: array
type: object
privileged:
type: boolean
procMount:
type: string
readOnlyRootFilesystem:
type: boolean
runAsGroup:
format: int64
type: integer
runAsNonRoot:
type: boolean
runAsUser:
format: int64
type: integer
seLinuxOptions:
properties:
level:
type: string
role:
type: string
type:
type: string
user:
type: string
type: object
seccompProfile:
properties:
localhostProfile:
type: string
type:
type: string
required:
- type
type: object
windowsOptions:
properties:
gmsaCredentialSpec:
type: string
gmsaCredentialSpecName:
type: string
hostProcess:
type: boolean
runAsUserName:
type: string
type: object
type: object
labels:
additionalProperties:
type: string
Expand Down
20 changes: 14 additions & 6 deletions testing/deploy-tenant-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,21 @@ function main() {

setup_kind

if [ -n "$lower_version" ]
error=$( {
if [ -n "$lower_version" ]
then
# Test specific version of operator
install_operator_version $lower_version
else
# Test latest release
install_operator_version
fi
} 2>&1 )

echo "$error"
if [ -n "$error" ]
then
# Test specific version of operator
install_operator_version $lower_version
else
# Test latest release
install_operator_version
install_operator
fi

install_tenant
Expand Down