Skip to content

Commit 28aa960

Browse files
Merge pull request #20638 from deads2k/server-17-rbac-enable
use the upstream RBAC roles for reconciliation
2 parents 70c96cb + fa149e8 commit 28aa960

File tree

9 files changed

+841
-4555
lines changed

9 files changed

+841
-4555
lines changed

pkg/cmd/server/bootstrappolicy/constants.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ const (
3333

3434
// groups
3535
const (
36-
UnauthenticatedUsername = "system:anonymous"
37-
3836
AuthenticatedGroup = "system:authenticated"
3937
AuthenticatedOAuthGroup = "system:authenticated:oauth"
4038
UnauthenticatedGroup = "system:unauthenticated"
@@ -43,7 +41,6 @@ const (
4341
MastersGroup = "system:masters"
4442
NodesGroup = "system:nodes"
4543
NodeAdminsGroup = "system:node-admins"
46-
NodeReadersGroup = "system:node-readers"
4744
)
4845

4946
// Service Account Names that are not controller related
@@ -96,7 +93,7 @@ const (
9693
SDNManagerRoleName = "system:sdn-manager"
9794
OAuthTokenDeleterRoleName = "system:oauth-token-deleter"
9895
WebHooksRoleName = "system:webhook"
99-
DiscoveryRoleName = "system:discovery"
96+
DiscoveryRoleName = "system:openshift:discovery"
10097

10198
// NodeAdmin has full access to the API provided by the kubelet
10299
NodeAdminRoleName = "system:node-admin"
@@ -127,7 +124,6 @@ const (
127124
NodeAdminRoleBindingName = NodeAdminRoleName + "s"
128125
SDNReaderRoleBindingName = SDNReaderRoleName + "s"
129126
WebHooksRoleBindingName = WebHooksRoleName + "s"
130-
DiscoveryRoleBindingName = DiscoveryRoleName + "-binding"
131127

132128
OpenshiftSharedResourceViewRoleBindingName = OpenshiftSharedResourceViewRoleName + "s"
133129

pkg/cmd/server/bootstrappolicy/dead.go

+3
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,7 @@ func init() {
7676

7777
// this was replaced by the node authorizer
7878
addDeadClusterRoleBinding("system:nodes", "system:node")
79+
80+
// this was replaced by an openshift specific role and binding
81+
addDeadClusterRoleBinding("system:discovery-binding", "system:discovery")
7982
}

pkg/cmd/server/bootstrappolicy/policy.go

+6-59
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,6 @@ func GetOpenshiftBootstrapClusterRoles() []rbacv1.ClusterRole {
102102
// four resource can be a single line
103103
// up to ten-ish resources per line otherwise
104104
clusterRoles := []rbacv1.ClusterRole{
105-
{
106-
ObjectMeta: metav1.ObjectMeta{
107-
Name: ClusterAdminRoleName,
108-
Annotations: map[string]string{
109-
oapi.OpenShiftDescription: "A super-user that can perform any action in the cluster. When granted to a user within a project, they have full control over quota and membership and can perform every action on every resource in the project.",
110-
},
111-
},
112-
Rules: []rbacv1.PolicyRule{
113-
rbacv1helpers.NewRule(rbacv1.VerbAll).Groups(rbacv1.APIGroupAll).Resources(rbacv1.ResourceAll).RuleOrDie(),
114-
rbacv1helpers.NewRule(rbacv1.VerbAll).URLs(rbacv1.NonResourceAll).RuleOrDie(),
115-
},
116-
},
117105
{
118106
ObjectMeta: metav1.ObjectMeta{
119107
Name: SudoerRoleName,
@@ -741,7 +729,6 @@ func GetBootstrapClusterRoles() []rbacv1.ClusterRole {
741729
// so add them to this list.
742730
openshiftClusterRoles = append(openshiftClusterRoles, GetDeadClusterRoles()...)
743731
kubeClusterRoles := bootstrappolicy.ClusterRoles()
744-
kubeSAClusterRoles := bootstrappolicy.ControllerRoles()
745732
openshiftControllerRoles := ControllerRoles()
746733

747734
// Eventually openshift controllers and kube controllers have different prefixes
@@ -757,26 +744,14 @@ func GetBootstrapClusterRoles() []rbacv1.ClusterRole {
757744
}
758745

759746
conflictingNames := kubeClusterRoleNames.Intersection(openshiftClusterRoleNames)
760-
extraRBACConflicts := conflictingNames.Difference(clusterRoleConflicts)
761-
extraWhitelistEntries := clusterRoleConflicts.Difference(conflictingNames)
762-
switch {
763-
case len(extraRBACConflicts) > 0 && len(extraWhitelistEntries) > 0:
764-
panic(fmt.Sprintf("kube ClusterRoles conflict with openshift ClusterRoles: %v and ClusterRole whitelist contains a extraneous entries: %v ", extraRBACConflicts.List(), extraWhitelistEntries.List()))
765-
case len(extraRBACConflicts) > 0:
766-
panic(fmt.Sprintf("kube ClusterRoles conflict with openshift ClusterRoles: %v", extraRBACConflicts.List()))
767-
case len(extraWhitelistEntries) > 0:
768-
panic(fmt.Sprintf("ClusterRole whitelist contains a extraneous entries: %v", extraWhitelistEntries.List()))
747+
if len(conflictingNames) > 0 {
748+
panic(fmt.Sprintf("kube ClusterRoles conflict with openshift ClusterRoles: %v", conflictingNames.List()))
769749
}
770750

771751
finalClusterRoles := []rbacv1.ClusterRole{}
772752
finalClusterRoles = append(finalClusterRoles, openshiftClusterRoles...)
773753
finalClusterRoles = append(finalClusterRoles, openshiftControllerRoles...)
774-
finalClusterRoles = append(finalClusterRoles, kubeSAClusterRoles...)
775-
for i := range kubeClusterRoles {
776-
if !clusterRoleConflicts.Has(kubeClusterRoles[i].Name) {
777-
finalClusterRoles = append(finalClusterRoles, kubeClusterRoles[i])
778-
}
779-
}
754+
finalClusterRoles = append(finalClusterRoles, kubeClusterRoles...)
780755

781756
// TODO we should not do this for kube cluster roles since we cannot control them once we run on top of kube
782757
// conditionally add the web console annotations
@@ -876,7 +851,7 @@ func GetOpenshiftBootstrapClusterRoleBindings() []rbacv1.ClusterRoleBinding {
876851
newOriginClusterBinding(WebHooksRoleBindingName, WebHooksRoleName).
877852
Groups(AuthenticatedGroup, UnauthenticatedGroup).
878853
BindingOrDie(),
879-
newOriginClusterBinding(DiscoveryRoleBindingName, DiscoveryRoleName).
854+
rbacv1helpers.NewClusterBinding(DiscoveryRoleName).
880855
Groups(AuthenticatedGroup, UnauthenticatedGroup).
881856
BindingOrDie(),
882857
// Allow all build strategies by default.
@@ -915,7 +890,6 @@ func GetBootstrapClusterRoleBindings() []rbacv1.ClusterRoleBinding {
915890
openshiftClusterRoleBindings = append(openshiftClusterRoleBindings, GetDeadClusterRoleBindings()...)
916891

917892
kubeClusterRoleBindings := bootstrappolicy.ClusterRoleBindings()
918-
kubeControllerClusterRoleBindings := bootstrappolicy.ControllerRoleBindings()
919893
openshiftControllerClusterRoleBindings := ControllerRoleBindings()
920894

921895
// openshift controllers and kube controllers have different prefixes
@@ -930,44 +904,17 @@ func GetBootstrapClusterRoleBindings() []rbacv1.ClusterRoleBinding {
930904
}
931905

932906
conflictingNames := kubeClusterRoleBindingNames.Intersection(openshiftClusterRoleBindingNames)
933-
extraRBACConflicts := conflictingNames.Difference(clusterRoleBindingConflicts)
934-
extraWhitelistEntries := clusterRoleBindingConflicts.Difference(conflictingNames)
935-
switch {
936-
case len(extraRBACConflicts) > 0 && len(extraWhitelistEntries) > 0:
937-
panic(fmt.Sprintf("kube ClusterRoleBindings conflict with openshift ClusterRoleBindings: %v and ClusterRoleBinding whitelist contains a extraneous entries: %v ", extraRBACConflicts.List(), extraWhitelistEntries.List()))
938-
case len(extraRBACConflicts) > 0:
939-
panic(fmt.Sprintf("kube ClusterRoleBindings conflict with openshift ClusterRoleBindings: %v", extraRBACConflicts.List()))
940-
case len(extraWhitelistEntries) > 0:
941-
panic(fmt.Sprintf("ClusterRoleBinding whitelist contains a extraneous entries: %v", extraWhitelistEntries.List()))
907+
if len(conflictingNames) > 0 {
908+
panic(fmt.Sprintf("kube ClusterRoleBindings conflict with openshift ClusterRoleBindings: %v", conflictingNames.List()))
942909
}
943910

944911
finalClusterRoleBindings := []rbacv1.ClusterRoleBinding{}
945912
finalClusterRoleBindings = append(finalClusterRoleBindings, openshiftClusterRoleBindings...)
946-
finalClusterRoleBindings = append(finalClusterRoleBindings, kubeControllerClusterRoleBindings...)
947913
finalClusterRoleBindings = append(finalClusterRoleBindings, openshiftControllerClusterRoleBindings...)
948-
for i := range kubeClusterRoleBindings {
949-
if !clusterRoleBindingConflicts.Has(kubeClusterRoleBindings[i].Name) {
950-
finalClusterRoleBindings = append(finalClusterRoleBindings, kubeClusterRoleBindings[i])
951-
}
952-
}
953914

954915
return finalClusterRoleBindings
955916
}
956917

957-
// clusterRoleConflicts lists the roles which are known to conflict with upstream and which we have manually
958-
// deconflicted with our own.
959-
var clusterRoleConflicts = sets.NewString(
960-
// TODO this should probably be re-swizzled to be the delta on top of the kube role
961-
"system:discovery",
962-
963-
// TODO these should be reconsidered
964-
"cluster-admin",
965-
)
966-
967-
// clusterRoleBindingConflicts lists the roles which are known to conflict with upstream and which we have manually
968-
// deconflicted with our own.
969-
var clusterRoleBindingConflicts = sets.NewString()
970-
971918
// The current list of roles considered useful for normal users (non-admin)
972919
var rolesToShow = sets.NewString(
973920
"admin",

pkg/cmd/server/bootstrappolicy/web_console_role_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var rolesToHide = sets.NewString(
6666
"system:openshift:aggregate-to-edit",
6767
"system:openshift:aggregate-to-view",
6868
"system:openshift:aggregate-to-cluster-reader",
69+
"system:openshift:discovery",
6970
"system:kubelet-api-admin",
7071
"system:volume-scheduler",
7172
)

pkg/cmd/server/kubernetes/master/master_config.go

-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import (
5151
"k8s.io/kubernetes/pkg/registry/cachesize"
5252
"k8s.io/kubernetes/pkg/registry/core/endpoint"
5353
endpointsstorage "k8s.io/kubernetes/pkg/registry/core/endpoint/storage"
54-
rbacrest "k8s.io/kubernetes/pkg/registry/rbac/rest"
5554
kversion "k8s.io/kubernetes/pkg/version"
5655

5756
"github.com/openshift/library-go/pkg/crypto"
@@ -412,9 +411,6 @@ func (rc *incompleteKubeMasterConfig) Complete(
412411
genericConfig.PublicAddress = publicAddress
413412
genericConfig.Authentication.Authenticator = originAuthenticator // this is used to fulfill the tokenreviews endpoint which is used by node authentication
414413
genericConfig.Authorization.Authorizer = kubeAuthorizer // this is used to fulfill the kube SAR endpoints
415-
genericConfig.DisabledPostStartHooks.Insert(rbacrest.PostStartHookName)
416-
// This disables the ThirdPartyController which removes handlers from our go-restful containers. The remove functionality is broken and destroys the serve mux.
417-
genericConfig.DisabledPostStartHooks.Insert("extensions/third-party-resources")
418414
genericConfig.AdmissionControl = admissionControl
419415
genericConfig.RequestInfoResolver = configprocessing.OpenshiftRequestInfoResolver()
420416
genericConfig.OpenAPIConfig = configprocessing.DefaultOpenAPIConfig(masterConfig)

test/integration/master_routes_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ var expectedIndex = []string{
125125
"/healthz/poststarthook/project.openshift.io-projectauthorizationcache",
126126
"/healthz/poststarthook/project.openshift.io-projectcache",
127127
"/healthz/poststarthook/quota.openshift.io-clusterquotamapping",
128+
"/healthz/poststarthook/rbac/bootstrap-roles",
128129
"/healthz/poststarthook/scheduling/bootstrap-system-priority-classes",
129130
"/healthz/poststarthook/security.openshift.io-bootstrapscc",
130131
"/healthz/poststarthook/start-apiextensions-controllers",

0 commit comments

Comments
 (0)