-
Notifications
You must be signed in to change notification settings - Fork 459
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
Allow empty securityContext #1452
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be only for an openshift
kustomization overlay
Out of the box Openshift install will need to have the It is also a possibility if we check the namespace annotations for the apiVersion: apps/v1
kind: Deployment
metadata:
name: tenant
...
spec:
...
template:
spec:
securityContext:
runAsUser: {uid}
runAsGroup: {gid}
fsGroup: {gid} If no Any Other SecurityContextConstrains that the final setup have we could ask them to set it manually in the According to this Redhat doc https://cloud.redhat.com/blog/a-guide-to-openshift-and-uids, that metadata will allways be there, Openshift Assigns its values based in the SCC that the project have. |
the |
I beg to differ, Overlay is good, we should do it, but it only solves operator pods securityContext, not for tenants because the tenant deployment is created on the fly by Operator based on the assignations @cniackz is looking at now. |
Our Operator is currently wrong for OpenShift, we can't clear securityContext and the only way in OpenShift to get this working is by changing the scc which is totally wrong, we should let OpenShift pick those values if not set. So from this PR at least we need to change this function below: // 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 scc don't allow hardcoded values
// from our yamls and 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
// Values from pool.SecurityContext ONLY if provided
if pool.SecurityContext != nil {
if pool.SecurityContext.RunAsNonRoot != nil {
runAsNonRoot = *pool.SecurityContext.RunAsNonRoot
}
if pool.SecurityContext.RunAsUser != nil {
runAsUser = *pool.SecurityContext.RunAsUser
}
if pool.SecurityContext.RunAsGroup != nil {
runAsGroup = *pool.SecurityContext.RunAsGroup
}
if pool.SecurityContext.RunAsNonRoot != nil || pool.SecurityContext.RunAsUser != nil || pool.SecurityContext.RunAsGroup != nil {
// Only set values if one is set otherwise let it empty
containerSecurityContext = corev1.SecurityContext{
RunAsNonRoot: &runAsNonRoot,
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
}
}
}
// Values from pool.ContainerSecurityContext if provided
if pool != nil && pool.ContainerSecurityContext != nil {
containerSecurityContext = *pool.ContainerSecurityContext
}
return &containerSecurityContext
} |
For now if we don't change our code, below lines will be always needed: oc apply -k ~/operator/examples/kustomization/tenant-lite
oc create serviceaccount minio-operator -n tenant-lite
oc adm policy add-scc-to-user privileged -n tenant-lite -z minio-operator
oc adm policy add-scc-to-user privileged -n tenant-lite -z builder
oc adm policy add-scc-to-user privileged -n tenant-lite -z deployer
oc adm policy add-scc-to-user privileged -n tenant-lite -z default
oc adm policy add-scc-to-user privileged -n tenant-lite -z storage-lite-sa |
@cniackz just be aware that if we remove the default It is not feasible ask users to chown all existing files in the mounts. |
Ok, thank you Pedro, I will test for an existing setup |
@pjuarezd this change is not affecting existing setups, already tested. If tenant has been deployed with previous code and is using previous hardcoded values, and then we update operator with this code, it will remain to use those same values as they were already set and hence this will only affect new deployments or if specifically we set securityContext as empty values.
|
VulnCheck issue in unrelated to this change. |
Im looking for your branch under https://github.com/cniackz/operator/branches. I cant see it. Did you delete it? @cniackz |
@allanrogerr New PR is: #1462 |
Objective:
Avoid hardcoding values that are not part of any security context constraint and allow Tenant to be deployed without changing scc in OpenShift as Operator logic is currently not allowing empty securityContext for Tenant and this is totally wrong!.