|
| 1 | +package bootstrappolicy |
| 2 | + |
| 3 | +import ( |
| 4 | + rbacv1 "k8s.io/api/rbac/v1" |
| 5 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 6 | + rbacv1helpers "k8s.io/kubernetes/pkg/apis/rbac/v1" |
| 7 | +) |
| 8 | + |
| 9 | +var ClusterRoles = clusterRoles |
| 10 | + |
| 11 | +func OpenshiftClusterRoles() []rbacv1.ClusterRole { |
| 12 | + const ( |
| 13 | + // These are valid under the "nodes" resource |
| 14 | + NodeMetricsSubresource = "metrics" |
| 15 | + NodeStatsSubresource = "stats" |
| 16 | + NodeSpecSubresource = "spec" |
| 17 | + NodeLogSubresource = "log" |
| 18 | + ) |
| 19 | + |
| 20 | + roles := clusterRoles() |
| 21 | + roles = append(roles, []rbacv1.ClusterRole{ |
| 22 | + { |
| 23 | + ObjectMeta: metav1.ObjectMeta{ |
| 24 | + Name: "system:node-admin", |
| 25 | + }, |
| 26 | + Rules: []rbacv1.PolicyRule{ |
| 27 | + // Allow read-only access to the API objects |
| 28 | + rbacv1helpers.NewRule(Read...).Groups(legacyGroup).Resources("nodes").RuleOrDie(), |
| 29 | + // Allow all API calls to the nodes |
| 30 | + rbacv1helpers.NewRule("proxy").Groups(legacyGroup).Resources("nodes").RuleOrDie(), |
| 31 | + rbacv1helpers.NewRule("*").Groups(legacyGroup).Resources("nodes/proxy", "nodes/"+NodeMetricsSubresource, "nodes/"+NodeSpecSubresource, "nodes/"+NodeStatsSubresource, "nodes/"+NodeLogSubresource).RuleOrDie(), |
| 32 | + }, |
| 33 | + }, |
| 34 | + { |
| 35 | + ObjectMeta: metav1.ObjectMeta{ |
| 36 | + Name: "system:node-reader", |
| 37 | + }, |
| 38 | + Rules: []rbacv1.PolicyRule{ |
| 39 | + // Allow read-only access to the API objects |
| 40 | + rbacv1helpers.NewRule(Read...).Groups(legacyGroup).Resources("nodes").RuleOrDie(), |
| 41 | + // Allow read access to node metrics |
| 42 | + rbacv1helpers.NewRule("get").Groups(legacyGroup).Resources("nodes/"+NodeMetricsSubresource, "nodes/"+NodeSpecSubresource).RuleOrDie(), |
| 43 | + // Allow read access to stats |
| 44 | + // Node stats requests are submitted as POSTs. These creates are non-mutating |
| 45 | + rbacv1helpers.NewRule("get", "create").Groups(legacyGroup).Resources("nodes/" + NodeStatsSubresource).RuleOrDie(), |
| 46 | + // TODO: expose other things like /healthz on the node once we figure out non-resource URL policy across systems |
| 47 | + }, |
| 48 | + }, |
| 49 | + }...) |
| 50 | + |
| 51 | + addClusterRoleLabel(roles) |
| 52 | + return roles |
| 53 | +} |
| 54 | + |
| 55 | +var ClusterRoleBindings = clusterRoleBindings |
| 56 | + |
| 57 | +func OpenshiftClusterRoleBindings() []rbacv1.ClusterRoleBinding { |
| 58 | + bindings := clusterRoleBindings() |
| 59 | + bindings = append(bindings, []rbacv1.ClusterRoleBinding{ |
| 60 | + rbacv1helpers.NewClusterBinding("system:node-admin").Users("system:master", "system:kube-apiserver").Groups("system:node-admins").BindingOrDie(), |
| 61 | + }...) |
| 62 | + |
| 63 | + addClusterRoleBindingLabel(bindings) |
| 64 | + return bindings |
| 65 | +} |
0 commit comments