mimir icon indicating copy to clipboard operation
mimir copied to clipboard

Add `global.openshift.enabled` config option

Open radudd opened this issue 2 years ago • 8 comments

Signed-off-by: Radu Domnu [email protected]

What this PR does

Introduces global.openshift.enabled config option. When set, the securityContexts will not be set for Mimir components.

Which issue(s) this PR fixes or relates to

Checklist

  • [ ] Tests updated
  • [ ] Documentation added
  • [ ] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

radudd avatar Nov 16 '22 09:11 radudd

Thanks for contributing @radudd! I'm not super familiar with OpenShift, can you help me understand why this is needed?

As far as I know, OpenShift does support and recommend using security contexts, it just requires using SecurityContextConstraints instead of PodSecurityPolicies to define what is allowed.

Logiraptor avatar Nov 18 '22 22:11 Logiraptor

The CHANGELOG has just been cut to prepare for the next Mimir release. Please rebase main and eventually move the CHANGELOG entry added / updated in this PR to the top of the CHANGELOG document. Thanks!

replay avatar Nov 29 '22 14:11 replay

Thanks for contributing @radudd! I'm not super familiar with OpenShift, can you help me understand why this is needed?

As far as I know, OpenShift does support and recommend using security contexts, it just requires using SecurityContextConstraints instead of PodSecurityPolicies to define what is allowed.

Yes, that's correct. However, there are some specific considerations in OpenShift: (to simplify, let's focus for example on runAsUser parameter of SCC/PSP)

  1. SCCs are enforced in OpenShift and the default (and the recommended one if there are no special requirements) is the so called, "restricted" SCC. In this SCC, the runAsUser is set to MustRunAsRange.
  2. When an OpenShift namespace is created, a random UID range is generated uniquely for it. This is defined in the following annotation for the namespace: openshift.io/sa.scc.uid-range
  3. If no securityContext is specified for a pod, OpenShift assigns an UID depending on SCC that emits the pod. If the pods runs under the restricted SCC, the runAsUser parameter of securityContext defaults to the first value of the UID range of the namespace. If desired, a pod can run of course with a different UID, but this will require a different SCC which sets runAsUser as MustRunAs (predefined UID) or RunAsAny(any UID). This, of course will have security implications.

Same applies for other security context parameters. Bottom line: In OpenShift, under the restricted SCC, if there are no particular requirements, securityContext shall be left unset, as the values which are populated are already secure.

Reference: https://docs.openshift.com/container-platform/4.10/authentication/managing-security-context-constraints.html#security-context-constraints-pre-allocated-values_configuring-internal-oauth

radudd avatar Dec 21 '22 11:12 radudd

Is there anything in the SCC that mimir-distributed bundles that makes it incompatible with OpenShift's "restricted" SCC? There were some changes recently that made sure that the majority of pods can run under a restricted policy.

dimitarvdimitrov avatar Dec 22 '22 18:12 dimitarvdimitrov

Is there anything in the SCC that mimir-distributed bundles that makes it incompatible with OpenShift's "restricted" SCC? There were some changes recently that made sure that the majority of pods can run under a restricted policy.

The PR https://github.com/grafana/mimir/pull/3007 sets default securityContext options in values.yaml file. For example, runAsUser is set to 1001. This will not work in OpenShift, unless a more privileged SCC is assigned (to run the pod as a specific user). Overriding these values will also not work as the UIDs to run the pods are assigned dynamically and are not known in advance. In order for the restricted SCC to work properly in OpenShift, it's recommended to have the securityContext unset.

radudd avatar Jan 03 '23 09:01 radudd

From IRL discussion it seems the existing rbac.type==scc can be used to disable rendering the securityContext fields. Depending on that instead of introducing a new configuration option would be our preferred solution.

krajorama avatar Feb 15 '23 14:02 krajorama

I've made an alternate version in #4272 , would you be able to verify?

krajorama avatar Feb 22 '23 14:02 krajorama

#4272

Thanks. Unfortunately I can't test anymore, but it looks good to me.

radudd avatar Feb 22 '23 14:02 radudd

Managed to get testing done in #4272 , which is ready to merge soon.

krajorama avatar Mar 10 '23 11:03 krajorama