mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
make sure that the bootstrap rbac rules are getting created in test-cmd
This commit is contained in:
parent
467b7d928f
commit
f73d1ea90a
@ -419,6 +419,10 @@ runTests() {
|
|||||||
|
|
||||||
kubectl get "${kube_flags[@]}" --raw /version
|
kubectl get "${kube_flags[@]}" --raw /version
|
||||||
|
|
||||||
|
# make sure the server was properly bootstrapped with clusterroles and bindings
|
||||||
|
kube::test::get_object_assert clusterroles/cluster-admin "{{.metadata.name}}" 'cluster-admin'
|
||||||
|
kube::test::get_object_assert clusterrolebindings/cluster-admin "{{.metadata.name}}" 'cluster-admin'
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
# POD creation / deletion #
|
# POD creation / deletion #
|
||||||
###########################
|
###########################
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/rest"
|
"k8s.io/kubernetes/pkg/api/rest"
|
||||||
"k8s.io/kubernetes/pkg/apis/rbac"
|
"k8s.io/kubernetes/pkg/apis/rbac"
|
||||||
"k8s.io/kubernetes/pkg/apis/rbac/validation"
|
"k8s.io/kubernetes/pkg/apis/rbac/validation"
|
||||||
"k8s.io/kubernetes/pkg/auth/user"
|
rbacregistry "k8s.io/kubernetes/pkg/registry/rbac"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,18 +43,8 @@ func NewStorage(s rest.StandardStorage, ruleResolver validation.AuthorizationRul
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||||
if u, ok := api.UserFrom(ctx); ok {
|
if rbacregistry.EscalationAllowed(ctx, s.superUser) {
|
||||||
if s.superUser != "" && u.GetName() == s.superUser {
|
return s.StandardStorage.Create(ctx, obj)
|
||||||
return s.StandardStorage.Create(ctx, obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
// system:masters is special because the API server uses it for privileged loopback connections
|
|
||||||
// therefore we know that a member of system:masters can always do anything
|
|
||||||
for _, group := range u.GetGroups() {
|
|
||||||
if group == user.SystemPrivilegedGroup {
|
|
||||||
return s.StandardStorage.Create(ctx, obj)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clusterRole := obj.(*rbac.ClusterRole)
|
clusterRole := obj.(*rbac.ClusterRole)
|
||||||
@ -66,10 +56,8 @@ func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||||
if user, ok := api.UserFrom(ctx); ok {
|
if rbacregistry.EscalationAllowed(ctx, s.superUser) {
|
||||||
if s.superUser != "" && user.GetName() == s.superUser {
|
return s.StandardStorage.Update(ctx, name, obj)
|
||||||
return s.StandardStorage.Update(ctx, name, obj)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
|
nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/rest"
|
"k8s.io/kubernetes/pkg/api/rest"
|
||||||
"k8s.io/kubernetes/pkg/apis/rbac"
|
"k8s.io/kubernetes/pkg/apis/rbac"
|
||||||
"k8s.io/kubernetes/pkg/apis/rbac/validation"
|
"k8s.io/kubernetes/pkg/apis/rbac/validation"
|
||||||
"k8s.io/kubernetes/pkg/auth/user"
|
rbacregistry "k8s.io/kubernetes/pkg/registry/rbac"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,18 +43,8 @@ func NewStorage(s rest.StandardStorage, ruleResolver validation.AuthorizationRul
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||||
if u, ok := api.UserFrom(ctx); ok {
|
if rbacregistry.EscalationAllowed(ctx, s.superUser) {
|
||||||
if s.superUser != "" && u.GetName() == s.superUser {
|
return s.StandardStorage.Create(ctx, obj)
|
||||||
return s.StandardStorage.Create(ctx, obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
// system:masters is special because the API server uses it for privileged loopback connections
|
|
||||||
// therefore we know that a member of system:masters can always do anything
|
|
||||||
for _, group := range u.GetGroups() {
|
|
||||||
if group == user.SystemPrivilegedGroup {
|
|
||||||
return s.StandardStorage.Create(ctx, obj)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clusterRoleBinding := obj.(*rbac.ClusterRoleBinding)
|
clusterRoleBinding := obj.(*rbac.ClusterRoleBinding)
|
||||||
@ -69,10 +59,8 @@ func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||||
if user, ok := api.UserFrom(ctx); ok {
|
if rbacregistry.EscalationAllowed(ctx, s.superUser) {
|
||||||
if s.superUser != "" && user.GetName() == s.superUser {
|
return s.StandardStorage.Update(ctx, name, obj)
|
||||||
return s.StandardStorage.Update(ctx, name, obj)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
|
nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
|
||||||
|
45
pkg/registry/rbac/escalation_check.go
Normal file
45
pkg/registry/rbac/escalation_check.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package rbac
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/auth/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EscalationAllowed(ctx api.Context, superUser string) bool {
|
||||||
|
u, ok := api.UserFrom(ctx)
|
||||||
|
if !ok {
|
||||||
|
// the only way to be without a user is to either have no authenticators by explicitly saying that's your preference
|
||||||
|
// or to be connecting via the insecure port, in which case this logically doesn't apply
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to see if this subject is allowed to escalate
|
||||||
|
if len(superUser) != 0 && u.GetName() == superUser {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// system:masters is special because the API server uses it for privileged loopback connections
|
||||||
|
// therefore we know that a member of system:masters can always do anything
|
||||||
|
for _, group := range u.GetGroups() {
|
||||||
|
if group == user.SystemPrivilegedGroup {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
@ -23,7 +23,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/rest"
|
"k8s.io/kubernetes/pkg/api/rest"
|
||||||
"k8s.io/kubernetes/pkg/apis/rbac"
|
"k8s.io/kubernetes/pkg/apis/rbac"
|
||||||
"k8s.io/kubernetes/pkg/apis/rbac/validation"
|
"k8s.io/kubernetes/pkg/apis/rbac/validation"
|
||||||
"k8s.io/kubernetes/pkg/auth/user"
|
rbacregistry "k8s.io/kubernetes/pkg/registry/rbac"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,18 +43,8 @@ func NewStorage(s rest.StandardStorage, ruleResolver validation.AuthorizationRul
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||||
if u, ok := api.UserFrom(ctx); ok {
|
if rbacregistry.EscalationAllowed(ctx, s.superUser) {
|
||||||
if s.superUser != "" && u.GetName() == s.superUser {
|
return s.StandardStorage.Create(ctx, obj)
|
||||||
return s.StandardStorage.Create(ctx, obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
// system:masters is special because the API server uses it for privileged loopback connections
|
|
||||||
// therefore we know that a member of system:masters can always do anything
|
|
||||||
for _, group := range u.GetGroups() {
|
|
||||||
if group == user.SystemPrivilegedGroup {
|
|
||||||
return s.StandardStorage.Create(ctx, obj)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
role := obj.(*rbac.Role)
|
role := obj.(*rbac.Role)
|
||||||
@ -66,10 +56,8 @@ func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||||
if user, ok := api.UserFrom(ctx); ok {
|
if rbacregistry.EscalationAllowed(ctx, s.superUser) {
|
||||||
if s.superUser != "" && user.GetName() == s.superUser {
|
return s.StandardStorage.Update(ctx, name, obj)
|
||||||
return s.StandardStorage.Update(ctx, name, obj)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
|
nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/rest"
|
"k8s.io/kubernetes/pkg/api/rest"
|
||||||
"k8s.io/kubernetes/pkg/apis/rbac"
|
"k8s.io/kubernetes/pkg/apis/rbac"
|
||||||
"k8s.io/kubernetes/pkg/apis/rbac/validation"
|
"k8s.io/kubernetes/pkg/apis/rbac/validation"
|
||||||
"k8s.io/kubernetes/pkg/auth/user"
|
rbacregistry "k8s.io/kubernetes/pkg/registry/rbac"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,18 +43,8 @@ func NewStorage(s rest.StandardStorage, ruleResolver validation.AuthorizationRul
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
|
||||||
if u, ok := api.UserFrom(ctx); ok {
|
if rbacregistry.EscalationAllowed(ctx, s.superUser) {
|
||||||
if s.superUser != "" && u.GetName() == s.superUser {
|
return s.StandardStorage.Create(ctx, obj)
|
||||||
return s.StandardStorage.Create(ctx, obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
// system:masters is special because the API server uses it for privileged loopback connections
|
|
||||||
// therefore we know that a member of system:masters can always do anything
|
|
||||||
for _, group := range u.GetGroups() {
|
|
||||||
if group == user.SystemPrivilegedGroup {
|
|
||||||
return s.StandardStorage.Create(ctx, obj)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
roleBinding := obj.(*rbac.RoleBinding)
|
roleBinding := obj.(*rbac.RoleBinding)
|
||||||
@ -69,10 +59,8 @@ func (s *Storage) Create(ctx api.Context, obj runtime.Object) (runtime.Object, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
func (s *Storage) Update(ctx api.Context, name string, obj rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||||
if user, ok := api.UserFrom(ctx); ok {
|
if rbacregistry.EscalationAllowed(ctx, s.superUser) {
|
||||||
if s.superUser != "" && user.GetName() == s.superUser {
|
return s.StandardStorage.Update(ctx, name, obj)
|
||||||
return s.StandardStorage.Update(ctx, name, obj)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
|
nonEscalatingInfo := wrapUpdatedObjectInfo(obj, func(ctx api.Context, obj runtime.Object, oldObj runtime.Object) (runtime.Object, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user