Commit 08a030f4 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #45088 from xilabao/add-validate-in-create-rolebinding

Automatic merge from submit-queue add validate in create rolebinding
parents 446d8959 0c0a32d8
...@@ -132,7 +132,7 @@ func (s ClusterRoleBindingGeneratorV1) StructuredGenerate() (runtime.Object, err ...@@ -132,7 +132,7 @@ func (s ClusterRoleBindingGeneratorV1) StructuredGenerate() (runtime.Object, err
} }
for _, sa := range sets.NewString(s.ServiceAccounts...).List() { for _, sa := range sets.NewString(s.ServiceAccounts...).List() {
tokens := strings.Split(sa, ":") tokens := strings.Split(sa, ":")
if len(tokens) != 2 { if len(tokens) != 2 || tokens[0] == "" || tokens[1] == "" {
return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>") return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>")
} }
clusterRoleBinding.Subjects = append(clusterRoleBinding.Subjects, rbac.Subject{ clusterRoleBinding.Subjects = append(clusterRoleBinding.Subjects, rbac.Subject{
......
...@@ -147,7 +147,7 @@ func (s RoleBindingGeneratorV1) StructuredGenerate() (runtime.Object, error) { ...@@ -147,7 +147,7 @@ func (s RoleBindingGeneratorV1) StructuredGenerate() (runtime.Object, error) {
} }
for _, sa := range sets.NewString(s.ServiceAccounts...).List() { for _, sa := range sets.NewString(s.ServiceAccounts...).List() {
tokens := strings.Split(sa, ":") tokens := strings.Split(sa, ":")
if len(tokens) != 2 { if len(tokens) != 2 || tokens[1] == "" {
return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>") return nil, fmt.Errorf("serviceaccount must be <namespace>:<name>")
} }
roleBinding.Subjects = append(roleBinding.Subjects, rbac.Subject{ roleBinding.Subjects = append(roleBinding.Subjects, rbac.Subject{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment