mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 18:28:13 +00:00 
			
		
		
		
	add roles and bindings for bootstrap controllers
This commit is contained in:
		| @@ -78,6 +78,38 @@ func init() { | ||||
| 			rbac.NewRule("get").Groups(legacyGroup).Resources("configmaps").Names("extension-apiserver-authentication").RuleOrDie(), | ||||
| 		}, | ||||
| 	}) | ||||
| 	addNamespaceRole(metav1.NamespaceSystem, rbac.Role{ | ||||
| 		// role for the bootstrap signer to be able to inspect kube-system secrets | ||||
| 		ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + "bootstrap-signer"}, | ||||
| 		Rules: []rbac.PolicyRule{ | ||||
| 			rbac.NewRule("get", "list", "watch").Groups(legacyGroup).Resources("secrets").RuleOrDie(), | ||||
| 		}, | ||||
| 	}) | ||||
| 	addNamespaceRole(metav1.NamespaceSystem, rbac.Role{ | ||||
| 		// role for the token-cleaner to be able to remove secrets, but only in kube-system | ||||
| 		ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + "token-cleaner"}, | ||||
| 		Rules: []rbac.PolicyRule{ | ||||
| 			rbac.NewRule("get", "list", "watch", "delete").Groups(legacyGroup).Resources("secrets").RuleOrDie(), | ||||
| 			eventsRule(), | ||||
| 		}, | ||||
| 	}) | ||||
| 	addNamespaceRoleBinding(metav1.NamespaceSystem, | ||||
| 		rbac.NewRoleBinding(saRolePrefix+"bootstrap-signer", metav1.NamespaceSystem).SAs(metav1.NamespaceSystem, "bootstrap-signer").BindingOrDie()) | ||||
| 	addNamespaceRoleBinding(metav1.NamespaceSystem, | ||||
| 		rbac.NewRoleBinding(saRolePrefix+"token-cleaner", metav1.NamespaceSystem).SAs(metav1.NamespaceSystem, "token-cleaner").BindingOrDie()) | ||||
|  | ||||
| 	addNamespaceRole(metav1.NamespacePublic, rbac.Role{ | ||||
| 		// role for the bootstrap signer to be able to write its configmap | ||||
| 		ObjectMeta: metav1.ObjectMeta{Name: saRolePrefix + "bootstrap-signer"}, | ||||
| 		Rules: []rbac.PolicyRule{ | ||||
| 			rbac.NewRule("get", "list", "watch").Groups(legacyGroup).Resources("configmaps").RuleOrDie(), | ||||
| 			rbac.NewRule("update").Groups(legacyGroup).Resources("configmaps").Names("cluster-info").RuleOrDie(), | ||||
| 			eventsRule(), | ||||
| 		}, | ||||
| 	}) | ||||
| 	addNamespaceRoleBinding(metav1.NamespacePublic, | ||||
| 		rbac.NewRoleBinding(saRolePrefix+"bootstrap-signer", metav1.NamespacePublic).SAs(metav1.NamespaceSystem, "bootstrap-signer").BindingOrDie()) | ||||
|  | ||||
| } | ||||
|  | ||||
| // NamespaceRoles returns a map of namespace to slice of roles to create | ||||
|   | ||||
| @@ -1,4 +1,58 @@ | ||||
| apiVersion: v1 | ||||
| items: null | ||||
| items: | ||||
| - apiVersion: rbac.authorization.k8s.io/v1beta1 | ||||
|   kind: RoleBinding | ||||
|   metadata: | ||||
|     annotations: | ||||
|       rbac.authorization.kubernetes.io/autoupdate: "true" | ||||
|     creationTimestamp: null | ||||
|     labels: | ||||
|       kubernetes.io/bootstrapping: rbac-defaults | ||||
|     name: system:controller:bootstrap-signer | ||||
|     namespace: kube-public | ||||
|   roleRef: | ||||
|     apiGroup: rbac.authorization.k8s.io | ||||
|     kind: Role | ||||
|     name: system:controller:bootstrap-signer | ||||
|   subjects: | ||||
|   - kind: ServiceAccount | ||||
|     name: bootstrap-signer | ||||
|     namespace: kube-system | ||||
| - apiVersion: rbac.authorization.k8s.io/v1beta1 | ||||
|   kind: RoleBinding | ||||
|   metadata: | ||||
|     annotations: | ||||
|       rbac.authorization.kubernetes.io/autoupdate: "true" | ||||
|     creationTimestamp: null | ||||
|     labels: | ||||
|       kubernetes.io/bootstrapping: rbac-defaults | ||||
|     name: system:controller:bootstrap-signer | ||||
|     namespace: kube-system | ||||
|   roleRef: | ||||
|     apiGroup: rbac.authorization.k8s.io | ||||
|     kind: Role | ||||
|     name: system:controller:bootstrap-signer | ||||
|   subjects: | ||||
|   - kind: ServiceAccount | ||||
|     name: bootstrap-signer | ||||
|     namespace: kube-system | ||||
| - apiVersion: rbac.authorization.k8s.io/v1beta1 | ||||
|   kind: RoleBinding | ||||
|   metadata: | ||||
|     annotations: | ||||
|       rbac.authorization.kubernetes.io/autoupdate: "true" | ||||
|     creationTimestamp: null | ||||
|     labels: | ||||
|       kubernetes.io/bootstrapping: rbac-defaults | ||||
|     name: system:controller:token-cleaner | ||||
|     namespace: kube-system | ||||
|   roleRef: | ||||
|     apiGroup: rbac.authorization.k8s.io | ||||
|     kind: Role | ||||
|     name: system:controller:token-cleaner | ||||
|   subjects: | ||||
|   - kind: ServiceAccount | ||||
|     name: token-cleaner | ||||
|     namespace: kube-system | ||||
| kind: List | ||||
| metadata: {} | ||||
|   | ||||
| @@ -1,5 +1,40 @@ | ||||
| apiVersion: v1 | ||||
| items: | ||||
| - apiVersion: rbac.authorization.k8s.io/v1beta1 | ||||
|   kind: Role | ||||
|   metadata: | ||||
|     annotations: | ||||
|       rbac.authorization.kubernetes.io/autoupdate: "true" | ||||
|     creationTimestamp: null | ||||
|     labels: | ||||
|       kubernetes.io/bootstrapping: rbac-defaults | ||||
|     name: system:controller:bootstrap-signer | ||||
|     namespace: kube-public | ||||
|   rules: | ||||
|   - apiGroups: | ||||
|     - "" | ||||
|     resources: | ||||
|     - configmaps | ||||
|     verbs: | ||||
|     - get | ||||
|     - list | ||||
|     - watch | ||||
|   - apiGroups: | ||||
|     - "" | ||||
|     resourceNames: | ||||
|     - cluster-info | ||||
|     resources: | ||||
|     - configmaps | ||||
|     verbs: | ||||
|     - update | ||||
|   - apiGroups: | ||||
|     - "" | ||||
|     resources: | ||||
|     - events | ||||
|     verbs: | ||||
|     - create | ||||
|     - patch | ||||
|     - update | ||||
| - apiVersion: rbac.authorization.k8s.io/v1beta1 | ||||
|   kind: Role | ||||
|   metadata: | ||||
| @@ -19,5 +54,52 @@ items: | ||||
|     - configmaps | ||||
|     verbs: | ||||
|     - get | ||||
| - apiVersion: rbac.authorization.k8s.io/v1beta1 | ||||
|   kind: Role | ||||
|   metadata: | ||||
|     annotations: | ||||
|       rbac.authorization.kubernetes.io/autoupdate: "true" | ||||
|     creationTimestamp: null | ||||
|     labels: | ||||
|       kubernetes.io/bootstrapping: rbac-defaults | ||||
|     name: system:controller:bootstrap-signer | ||||
|     namespace: kube-system | ||||
|   rules: | ||||
|   - apiGroups: | ||||
|     - "" | ||||
|     resources: | ||||
|     - secrets | ||||
|     verbs: | ||||
|     - get | ||||
|     - list | ||||
|     - watch | ||||
| - apiVersion: rbac.authorization.k8s.io/v1beta1 | ||||
|   kind: Role | ||||
|   metadata: | ||||
|     annotations: | ||||
|       rbac.authorization.kubernetes.io/autoupdate: "true" | ||||
|     creationTimestamp: null | ||||
|     labels: | ||||
|       kubernetes.io/bootstrapping: rbac-defaults | ||||
|     name: system:controller:token-cleaner | ||||
|     namespace: kube-system | ||||
|   rules: | ||||
|   - apiGroups: | ||||
|     - "" | ||||
|     resources: | ||||
|     - secrets | ||||
|     verbs: | ||||
|     - delete | ||||
|     - get | ||||
|     - list | ||||
|     - watch | ||||
|   - apiGroups: | ||||
|     - "" | ||||
|     resources: | ||||
|     - events | ||||
|     verbs: | ||||
|     - create | ||||
|     - patch | ||||
|     - update | ||||
| kind: List | ||||
| metadata: {} | ||||
|   | ||||
| @@ -279,6 +279,22 @@ func NewRoleBinding(roleName, namespace string) *RoleBindingBuilder { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func NewRoleBindingForClusterRole(roleName, namespace string) *RoleBindingBuilder { | ||||
| 	return &RoleBindingBuilder{ | ||||
| 		RoleBinding: RoleBinding{ | ||||
| 			ObjectMeta: metav1.ObjectMeta{ | ||||
| 				Name:      roleName, | ||||
| 				Namespace: namespace, | ||||
| 			}, | ||||
| 			RoleRef: RoleRef{ | ||||
| 				APIGroup: GroupName, | ||||
| 				Kind:     "ClusterRole", | ||||
| 				Name:     roleName, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Groups adds the specified groups as the subjects of the RoleBinding. | ||||
| func (r *RoleBindingBuilder) Groups(groups ...string) *RoleBindingBuilder { | ||||
| 	for _, group := range groups { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 deads2k
					deads2k