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

use the upstream namespaced roles #16512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions pkg/cmd/server/bootstrappolicy/all.go
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(),
}
}
12 changes: 0 additions & 12 deletions pkg/cmd/server/bootstrappolicy/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const (

// groups
const (
UnauthenticatedUsername = "system:anonymous"
Copy link
Contributor

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?

Copy link
Contributor Author

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?

don't care


AuthenticatedGroup = "system:authenticated"
AuthenticatedOAuthGroup = "system:authenticated:oauth"
UnauthenticatedGroup = "system:unauthenticated"
Expand All @@ -42,7 +40,6 @@ const (
MastersGroup = "system:masters"
NodesGroup = "system:nodes"
NodeAdminsGroup = "system:node-admins"
NodeReadersGroup = "system:node-readers"
)

// Roles
Expand Down Expand Up @@ -113,23 +110,14 @@ const (
StatusCheckerRoleBindingName = StatusCheckerRoleName + "-binding"
ImagePullerRoleBindingName = ImagePullerRoleName + "s"
ImageBuilderRoleBindingName = ImageBuilderRoleName + "s"
RouterRoleBindingName = RouterRoleName + "s"
RegistryRoleBindingName = RegistryRoleName + "s"
MasterRoleBindingName = MasterRoleName + "s"
NodeRoleBindingName = NodeRoleName + "s"
NodeProxierRoleBindingName = NodeProxierRoleName + "s"
NodeAdminRoleBindingName = NodeAdminRoleName + "s"
NodeReaderRoleBindingName = NodeReaderRoleName + "s"
SDNReaderRoleBindingName = SDNReaderRoleName + "s"
SDNManagerRoleBindingName = SDNManagerRoleName + "s"
WebHooksRoleBindingName = WebHooksRoleName + "s"
DiscoveryRoleBindingName = DiscoveryRoleName + "-binding"
RegistryAdminRoleBindingName = RegistryAdminRoleName + "s"
RegistryViewerRoleBindingName = RegistryViewerRoleName + "s"
RegistryEditorRoleBindingName = RegistryEditorRoleName + "s"

BuildStrategyDockerRoleBindingName = BuildStrategyDockerRoleName + "-binding"
BuildStrategyCustomRoleBindingName = BuildStrategyCustomRoleName + "-binding"
BuildStrategySourceRoleBindingName = BuildStrategySourceRoleName + "-binding"
BuildStrategyJenkinsPipelineRoleBindingName = BuildStrategyJenkinsPipelineRoleName + "-binding"

Expand Down
70 changes: 70 additions & 0 deletions pkg/cmd/server/bootstrappolicy/namespace_policy.go
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
}
46 changes: 46 additions & 0 deletions pkg/cmd/server/bootstrappolicy/namespace_policy_test.go
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

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-")
}
}
26 changes: 0 additions & 26 deletions pkg/cmd/server/bootstrappolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,6 @@ var (
legacyNetworkGroup = networkapi.LegacyGroupName
)

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(),
},
},
}
}

func GetOpenshiftBootstrapClusterRoles() []rbac.ClusterRole {
// four resource can be a single line
// up to ten-ish resources per line otherwise
Expand Down