-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
use the upstream namespaced roles #16512
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
package bootstrappolicy | ||
|
||
import ( | ||
"k8s.io/kubernetes/pkg/apis/rbac" | ||
rbacrest "k8s.io/kubernetes/pkg/registry/rbac/rest" | ||
) | ||
|
||
func Policy() *rbacrest.PolicyData { | ||
return &rbacrest.PolicyData{ | ||
ClusterRoles: GetBootstrapClusterRoles(), | ||
ClusterRoleBindings: GetBootstrapClusterRoleBindings(), | ||
Roles: map[string][]rbac.Role{ | ||
DefaultOpenShiftSharedResourcesNamespace: GetBootstrapOpenshiftRoles(DefaultOpenShiftSharedResourcesNamespace), | ||
}, | ||
RoleBindings: map[string][]rbac.RoleBinding{ | ||
DefaultOpenShiftSharedResourcesNamespace: GetBootstrapOpenshiftRoleBindings(DefaultOpenShiftSharedResourcesNamespace), | ||
}, | ||
Roles: NamespaceRoles(), | ||
RoleBindings: NamespaceRoleBindings(), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package bootstrappolicy | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/kubernetes/pkg/apis/rbac" | ||
"k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac/bootstrappolicy" | ||
) | ||
|
||
var ( | ||
// namespaceRoles is a map of namespace to slice of roles to create | ||
namespaceRoles = map[string][]rbac.Role{} | ||
|
||
// namespaceRoleBindings is a map of namespace to slice of roleBindings to create | ||
namespaceRoleBindings = map[string][]rbac.RoleBinding{} | ||
) | ||
|
||
func init() { | ||
namespaceRoles[DefaultOpenShiftSharedResourcesNamespace] = GetBootstrapOpenshiftRoles(DefaultOpenShiftSharedResourcesNamespace) | ||
namespaceRoleBindings[DefaultOpenShiftSharedResourcesNamespace] = GetBootstrapOpenshiftRoleBindings(DefaultOpenShiftSharedResourcesNamespace) | ||
} | ||
|
||
func GetBootstrapOpenshiftRoles(openshiftNamespace string) []rbac.Role { | ||
return []rbac.Role{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: OpenshiftSharedResourceViewRoleName, | ||
Namespace: openshiftNamespace, | ||
}, | ||
Rules: []rbac.PolicyRule{ | ||
rbac.NewRule(read...). | ||
Groups(templateGroup, legacyTemplateGroup). | ||
Resources("templates"). | ||
RuleOrDie(), | ||
rbac.NewRule(read...). | ||
Groups(imageGroup, legacyImageGroup). | ||
Resources("imagestreams", "imagestreamtags", "imagestreamimages"). | ||
RuleOrDie(), | ||
// so anyone can pull from openshift/* image streams | ||
rbac.NewRule("get"). | ||
Groups(imageGroup, legacyImageGroup). | ||
Resources("imagestreams/layers"). | ||
RuleOrDie(), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// NamespaceRoles returns a map of namespace to slice of roles to create | ||
func NamespaceRoles() map[string][]rbac.Role { | ||
ret := map[string][]rbac.Role{} | ||
for k, v := range namespaceRoles { | ||
ret[k] = v | ||
} | ||
for k, v := range bootstrappolicy.NamespaceRoles() { | ||
ret[k] = v | ||
} | ||
return ret | ||
} | ||
|
||
// NamespaceRoleBindings returns a map of namespace to slice of roles to create | ||
func NamespaceRoleBindings() map[string][]rbac.RoleBinding { | ||
ret := map[string][]rbac.RoleBinding{} | ||
for k, v := range namespaceRoleBindings { | ||
ret[k] = v | ||
} | ||
for k, v := range bootstrappolicy.NamespaceRoleBindings() { | ||
ret[k] = v | ||
} | ||
return ret | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package bootstrappolicy | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac/bootstrappolicy" | ||
) | ||
|
||
func TestOpenshiftNamespacePolicyNamespaces(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made this fatal in #16517 just like upstream. Do you still want the tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
don't care |
||
for ns := range namespaceRoles { | ||
if ns == DefaultOpenShiftSharedResourcesNamespace { | ||
continue | ||
} | ||
if strings.HasPrefix(ns, "openshift-") { | ||
continue | ||
} | ||
t.Errorf("bootstrap role in %q,but must be under %q", ns, "openshift-") | ||
} | ||
|
||
for ns := range namespaceRoleBindings { | ||
if ns == DefaultOpenShiftSharedResourcesNamespace { | ||
continue | ||
} | ||
if strings.HasPrefix(ns, "openshift-") { | ||
continue | ||
} | ||
t.Errorf("bootstrap rolebinding in %q,but must be under %q", ns, "openshift-") | ||
} | ||
} | ||
|
||
func TestKubeNamespacePolicyNamespaces(t *testing.T) { | ||
for ns := range bootstrappolicy.NamespaceRoles() { | ||
if strings.HasPrefix(ns, "kube-") { | ||
continue | ||
} | ||
t.Errorf("bootstrap role in %q,but must be under %q", ns, "kube-") | ||
} | ||
|
||
for ns := range bootstrappolicy.NamespaceRoles() { | ||
if strings.HasPrefix(ns, "kube-") { | ||
continue | ||
} | ||
t.Errorf("bootstrap rolebinding in %q,but must be under %q", ns, "kube-") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deads2k do you want these changes in #16517?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't care