forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPSTREAM: <carry>: kube-apiserver: allow injection of kube-apiserver …
…options Origin-commit: 33a71aff9bb4e204bf2e15af4cdfb5bd0525ce4e
- Loading branch information
Showing
7 changed files
with
127 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package app | ||
|
||
import ( | ||
"k8s.io/apiserver/pkg/admission" | ||
genericapiserver "k8s.io/apiserver/pkg/server" | ||
clientgoinformers "k8s.io/client-go/informers" | ||
"k8s.io/kubernetes/pkg/master" | ||
) | ||
|
||
type KubeAPIServerConfigFunc func(config *genericapiserver.Config, versionedInformers clientgoinformers.SharedInformerFactory, pluginInitializers *[]admission.PluginInitializer) (genericapiserver.DelegationTarget, error) | ||
|
||
var OpenShiftKubeAPIServerConfigPatch KubeAPIServerConfigFunc = nil | ||
|
||
type KubeAPIServerServerFunc func(server *master.Master) error | ||
|
||
func PatchKubeAPIServerConfig(config *genericapiserver.Config, versionedInformers clientgoinformers.SharedInformerFactory, pluginInitializers *[]admission.PluginInitializer) (genericapiserver.DelegationTarget, error) { | ||
if OpenShiftKubeAPIServerConfigPatch == nil { | ||
return genericapiserver.NewEmptyDelegate(), nil | ||
} | ||
|
||
return OpenShiftKubeAPIServerConfigPatch(config, versionedInformers, pluginInitializers) | ||
} | ||
|
||
var OpenShiftKubeAPIServerServerPatch KubeAPIServerServerFunc = nil | ||
|
||
func PatchKubeAPIServerServer(server *master.Master) error { | ||
if OpenShiftKubeAPIServerServerPatch == nil { | ||
return nil | ||
} | ||
|
||
return OpenShiftKubeAPIServerServerPatch(server) | ||
} | ||
|
||
var StartingDelegate genericapiserver.DelegationTarget = genericapiserver.NewEmptyDelegate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package options | ||
|
||
import "k8s.io/apiserver/pkg/admission" | ||
|
||
var RegisterAllAdmissionPlugins = registerAllAdmissionPlugins | ||
|
||
var DefaultOffAdmissionPlugins = defaultOffAdmissionPlugins | ||
|
||
var Decorators = []admission.Decorator{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
plugin/pkg/auth/authorizer/rbac/bootstrappolicy/patch_policy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package bootstrappolicy | ||
|
||
import ( | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
rbacv1helpers "k8s.io/kubernetes/pkg/apis/rbac/v1" | ||
) | ||
|
||
var ClusterRoles = clusterRoles | ||
|
||
func OpenshiftClusterRoles() []rbacv1.ClusterRole { | ||
const ( | ||
// These are valid under the "nodes" resource | ||
NodeMetricsSubresource = "metrics" | ||
NodeStatsSubresource = "stats" | ||
NodeSpecSubresource = "spec" | ||
NodeLogSubresource = "log" | ||
) | ||
|
||
roles := clusterRoles() | ||
roles = append(roles, []rbacv1.ClusterRole{ | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "system:node-admin", | ||
}, | ||
Rules: []rbacv1.PolicyRule{ | ||
// Allow read-only access to the API objects | ||
rbacv1helpers.NewRule(Read...).Groups(legacyGroup).Resources("nodes").RuleOrDie(), | ||
// Allow all API calls to the nodes | ||
rbacv1helpers.NewRule("proxy").Groups(legacyGroup).Resources("nodes").RuleOrDie(), | ||
rbacv1helpers.NewRule("*").Groups(legacyGroup).Resources("nodes/proxy", "nodes/"+NodeMetricsSubresource, "nodes/"+NodeSpecSubresource, "nodes/"+NodeStatsSubresource, "nodes/"+NodeLogSubresource).RuleOrDie(), | ||
}, | ||
}, | ||
{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "system:node-reader", | ||
}, | ||
Rules: []rbacv1.PolicyRule{ | ||
// Allow read-only access to the API objects | ||
rbacv1helpers.NewRule(Read...).Groups(legacyGroup).Resources("nodes").RuleOrDie(), | ||
// Allow read access to node metrics | ||
rbacv1helpers.NewRule("get").Groups(legacyGroup).Resources("nodes/"+NodeMetricsSubresource, "nodes/"+NodeSpecSubresource).RuleOrDie(), | ||
// Allow read access to stats | ||
// Node stats requests are submitted as POSTs. These creates are non-mutating | ||
rbacv1helpers.NewRule("get", "create").Groups(legacyGroup).Resources("nodes/" + NodeStatsSubresource).RuleOrDie(), | ||
// TODO: expose other things like /healthz on the node once we figure out non-resource URL policy across systems | ||
}, | ||
}, | ||
}...) | ||
|
||
addClusterRoleLabel(roles) | ||
return roles | ||
} | ||
|
||
var ClusterRoleBindings = clusterRoleBindings | ||
|
||
func OpenshiftClusterRoleBindings() []rbacv1.ClusterRoleBinding { | ||
bindings := clusterRoleBindings() | ||
bindings = append(bindings, []rbacv1.ClusterRoleBinding{ | ||
rbacv1helpers.NewClusterBinding("system:node-admin").Users("system:master", "system:kube-apiserver").Groups("system:node-admins").BindingOrDie(), | ||
}...) | ||
|
||
addClusterRoleBindingLabel(bindings) | ||
return bindings | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters