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

Cannot set blockOwnerDeletion #389

Open
cyberox opened this issue Mar 10, 2022 · 9 comments
Open

Cannot set blockOwnerDeletion #389

cyberox opened this issue Mar 10, 2022 · 9 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@cyberox
Copy link

cyberox commented Mar 10, 2022

Describe the bug
I would like to run moco on our openshift cluster. The operator is installed correctly.
But during the creation of a MySQLCluster resource, I receive the following error:

LAST SEEN   TYPE      REASON         OBJECT                         MESSAGE
4s          Normal    NoPods         poddisruptionbudget/moco-ngw   No matching pods found
2s          Warning   FailedCreate   statefulset/moco-ngw           create Claim mysql-data-moco-ngw-0 for Pod moco-ngw-0 in StatefulSet moco-ngw failed error: persistentvolumeclaims "mysql-data-moco-ngw-0" is forbidden: cannot set blockOwnerDeletion if an ownerReference refers to a resource you can't set finalizers on: , <nil>
2s          Warning   FailedCreate   statefulset/moco-ngw           create Pod moco-ngw-0 in StatefulSet moco-ngw failed error: failed to create PVC mysql-data-moco-ngw-0: persistentvolumeclaims "mysql-data-moco-ngw-0" is forbidden: cannot set blockOwnerDeletion if an ownerReference refers to a resource you can't set finalizers on: , <nil>

Environments

  • Version: OpenShift 4.9
  • OS: CoreOS

To Reproduce
Deploy the minimal cluster resource on the openshift cluster.

Expected behavior
PVC are created correctly

Additional context
This is a security enhancement in OpenShift, and is discussed in this BugZilla.
This could be resolved by extending the ClusterRole resources with additional /finalizers, but I need some help with this.

@cyberox cyberox added the bug Something isn't working label Mar 10, 2022
@ymmt2005
Copy link
Member

Thank you for the report. We also do not have experience with OpenShift, so need help.

@ymmt2005 ymmt2005 added the help wanted Extra attention is needed label Mar 10, 2022
@zoetrope
Copy link
Member

@cyberox
We do not have an OpenShift environment.
So could you try the following configuration in your environment?

kubectl edit clusterrole moco-manager-role

Please add the following rule in moco-manager-role:

- apiGroups:
  - ""
  resources:
  - persistentvolumeclaims/finalizers
  verbs:
  - update

If it works, we will add this configuration to our helm chart.

@cyberox
Copy link
Author

cyberox commented Mar 11, 2022

Thank you for the suggestion. I applied it to the clusterrole, and redeployed the MySQLCluster resource.
I'm receiving the same error when creating the statefulset.

@zoetrope
Copy link
Member

Please add the following rule as well.

- apiGroups:
  - apps
  resources:
  - statefulsets/finalizer
  verbs:
  - update

@cyberox
Copy link
Author

cyberox commented Mar 11, 2022

I also added that to the clusterrole, but unfortunately it is not working.

@zoetrope
Copy link
Member

I will try OpenShift free trial or Minishift.
Please wait a while.

@cyberox cyberox closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2022
@rassie
Copy link

rassie commented Feb 20, 2025

So I've stumbled over this problem on my OKD 4.18 cluster. The reason this is happening is that OwnerReferencesPermissionEnforcement admission plugin is enabled by default in OpenShift/OKD, so this could happen in a pure Kubernetes cluster too depending on security pre-requisites.

After a long debugging session I've managed to come by with the following RBAC:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
    name: mysqlclusters-finalizer
rules:
    - apiGroups: ["moco.cybozu.com"]
      resources: ["mysqlclusters/finalizers"]
      verbs: ["update"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
    name: mysqlclusters-finalizer-role-binding
subjects:
    - kind: ServiceAccount
      name: statefulset-controller
      namespace: kube-system
roleRef:
    kind: ClusterRole
    name: mysqlclusters-finalizer
    apiGroup: rbac.authorization.k8s.io

However, I want to stress that I don't think this is the proper way, giving out roles to system processes just feels wrong. I'd like to research how other operators handle this before proposing a change in Moco, but I'm not too optimistic I'd find much, because OpenShift support is too often an afterthought.

A connected issue is #777 -- OpenShift does not like hard-coded UIDs and GIDs and currently requires adding anyuid SCC to the service account to run Moco. Would be nice if that wasn't necessary.

@zoetrope @ymmt2005 could you re-open this one please? I think we might find a proper solution soon.

@ymmt2005 ymmt2005 reopened this Feb 20, 2025
@ymmt2005
Copy link
Member

Thank you for your report, @rassie !

@rassie
Copy link

rassie commented Feb 20, 2025

I think I have identified the problem, at least in comparison with other operators. I think the owner reference on the PVC is wrong:

pvc.WithOwnerReferences(metav1ac.OwnerReference().
WithAPIVersion(apiVersion).
WithKind(gvk.Kind).
WithName(cluster.Name).
WithUID(cluster.GetUID()).
WithBlockOwnerDeletion(true).
WithController(true))

From what I've seen from other operators, if a PVC has an owner reference, it's most commonly owned by the StatefulSet, not the custom resource which created the StatefulSet. Moco however sets MySQLCluster as PVC's ownerRef, so that when the statefulset-controller tries to create a PVC and set the blockOwnerDeletion option, it requires a permission to update finalizers on PVC's owner, which is MySQLCluster and not StatefulSet. statefulset-controller however, only has the permission for the latter, which is why everything fails.

I'm not quite sure why the owner reference is set like that, but I suspect it has something to do with PVC resizing support which needs a certain decoupling of StatefulSets and PVCs. I'm also not sure what best practices should be applied here, but I think the root cause is correct, but I can offer no full solution apart from not setting the ownerRef on the PVCs. YMMV as always.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants