@@ -21,6 +21,10 @@ const (
2121 CSIDriverRegistrarClusterBindingName = "storageos:driver-registrar"
2222 CSIK8SDriverRegistrarClusterBindingName = "storageos:k8s-driver-registrar"
2323
24+ // OpenShift Security Context Constraints role and role binding names.
25+ OpenShiftSCCClusterRoleName = "storageos:openshift-scc"
26+ OpenShiftSCCClusterBindingName = "storageos:openshift-scc"
27+
2428 KeyManagementRoleName = "storageos:key-management"
2529 KeyManagementBindingName = "storageos:key-management"
2630
@@ -393,3 +397,46 @@ func (s *Deployment) createClusterRoleBindingForAttacher() error {
393397 }
394398 return s .createClusterRoleBinding (CSIAttacherClusterBindingName , subjects , roleRef )
395399}
400+
401+ // createClusterRoleForSCC creates cluster role with api group and resource
402+ // specific to openshift. This permission is required for by daemonsets and
403+ // statefulsets.
404+ func (s * Deployment ) createClusterRoleForSCC () error {
405+ rules := []rbacv1.PolicyRule {
406+ {
407+ APIGroups : []string {"security.openshift.io" },
408+ Resources : []string {"securitycontextconstraints" },
409+ Verbs : []string {"use" },
410+ ResourceNames : []string {"privileged" },
411+ },
412+ }
413+ return s .createClusterRole (OpenShiftSCCClusterRoleName , rules )
414+ }
415+
416+ // createClusterRoleBindingForSCC creates a cluster role binding of the
417+ // openshift SCC role with daemonset and statefulset service account.
418+ func (s * Deployment ) createClusterRoleBindingForSCC () error {
419+ subjects := []rbacv1.Subject {
420+ {
421+ Kind : rbacv1 .ServiceAccountKind ,
422+ Name : DaemonsetSA ,
423+ Namespace : s .stos .Spec .GetResourceNS (),
424+ },
425+ }
426+
427+ // Add Statefulset service account if CSI is enabled.
428+ if s .stos .Spec .CSI .Enable {
429+ subjects = append (subjects , rbacv1.Subject {
430+ Kind : rbacv1 .ServiceAccountKind ,
431+ Name : StatefulsetSA ,
432+ Namespace : s .stos .Spec .GetResourceNS (),
433+ })
434+ }
435+
436+ roleRef := rbacv1.RoleRef {
437+ Kind : "ClusterRole" ,
438+ Name : OpenShiftSCCClusterRoleName ,
439+ APIGroup : "rbac.authorization.k8s.io" ,
440+ }
441+ return s .createClusterRoleBinding (OpenShiftSCCClusterBindingName , subjects , roleRef )
442+ }
0 commit comments