Skip to content

Commit f576119

Browse files
author
Han Kang
committed
add bootstrap policy for monitoring roles
(we enable metrics and pprof by default, but that doesn't mean we should have full cluster-admin access to use those endpoints) Change-Id: I20cf1a0c817ffe3b7fb8e5d3967f804dc063ab03 remove pprof but add read access to detailed health checks Change-Id: I96c0997be2a538aa8c689dea25026bba638d6e7d add base health check endpoints and remove the todo for flowcontrol, as there is an existing ticket Change-Id: I8a7d6debeaf91e06d8ace3cb2bd04d71ef3e68a9 drop blank line Change-Id: I691e72e9dee3cf7276c725a12207d64db88f4651
1 parent 4b2cb07 commit f576119

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

cluster/gce/gci/configure-helper.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@ function create-master-auth {
687687
append_or_replace_prefixed_line "${known_tokens_csv}" "${KONNECTIVITY_SERVER_TOKEN}," "system:konnectivity-server,uid:system:konnectivity-server"
688688
create-kubeconfig "konnectivity-server" ${KONNECTIVITY_SERVER_TOKEN}
689689
fi
690+
if [[ -n "${MONITORING_TOKEN:-}" ]]; then
691+
append_or_replace_prefixed_line "${known_tokens_csv}" "${MONITORING_TOKEN}," "system:monitoring,uid:system:monitoring,system:monitoring"
692+
fi
690693

691694
if [[ -n "${EXTRA_STATIC_AUTH_COMPONENTS:-}" ]]; then
692695
# Create a static Bearer token and kubeconfig for extra, comma-separated components.
@@ -2899,7 +2902,9 @@ function main() {
28992902
if [[ "${ENABLE_EGRESS_VIA_KONNECTIVITY_SERVICE:-false}" == "true" ]]; then
29002903
KONNECTIVITY_SERVER_TOKEN="$(secure_random 32)"
29012904
fi
2902-
2905+
if [[ "${ENABLE_MONITORING_TOKEN:-false}" == "true" ]]; then
2906+
MONITORING_TOKEN="$(secure_random 32)"
2907+
fi
29032908

29042909
setup-os-params
29052910
config-ip-firewall

plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ func ClusterRoles() []rbacv1.ClusterRole {
196196
},
197197
},
198198
{
199-
// a role which provides just enough power to determine if the server is ready and discover API versions for negotiation
199+
// a role which provides just enough power to determine if the server is
200+
// ready and discover API versions for negotiation
200201
ObjectMeta: metav1.ObjectMeta{Name: "system:discovery"},
201202
Rules: []rbacv1.PolicyRule{
202203
rbacv1helpers.NewRule("get").URLs(
@@ -208,6 +209,20 @@ func ClusterRoles() []rbacv1.ClusterRole {
208209
).RuleOrDie(),
209210
},
210211
},
212+
{
213+
// a role which provides minimal read access to the monitoring endpoints
214+
// (i.e. /metrics, /livez/*, /readyz/*, /healthz/*, /livez, /readyz, /healthz)
215+
// The splatted health check endpoints allow read access to individual health check
216+
// endpoints which may contain more sensitive cluster information information
217+
ObjectMeta: metav1.ObjectMeta{Name: "system:monitoring"},
218+
Rules: []rbacv1.PolicyRule{
219+
rbacv1helpers.NewRule("get").URLs(
220+
"/metrics",
221+
"/livez", "/readyz", "/healthz",
222+
"/livez/*", "/readyz/*", "/healthz/*",
223+
).RuleOrDie(),
224+
},
225+
},
211226
{
212227
// a role which provides minimal resource access to allow a "normal" user to learn information about themselves
213228
ObjectMeta: metav1.ObjectMeta{Name: "system:basic-user"},
@@ -563,6 +578,7 @@ const systemNodeRoleName = "system:node"
563578
func ClusterRoleBindings() []rbacv1.ClusterRoleBinding {
564579
rolebindings := []rbacv1.ClusterRoleBinding{
565580
rbacv1helpers.NewClusterBinding("cluster-admin").Groups(user.SystemPrivilegedGroup).BindingOrDie(),
581+
rbacv1helpers.NewClusterBinding("system:monitoring").Groups(user.MonitoringGroup).BindingOrDie(),
566582
rbacv1helpers.NewClusterBinding("system:discovery").Groups(user.AllAuthenticated).BindingOrDie(),
567583
rbacv1helpers.NewClusterBinding("system:basic-user").Groups(user.AllAuthenticated).BindingOrDie(),
568584
rbacv1helpers.NewClusterBinding("system:public-info-viewer").Groups(user.AllAuthenticated, user.AllUnauthenticated).BindingOrDie(),

plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-role-bindings.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ items:
102102
- apiGroup: rbac.authorization.k8s.io
103103
kind: User
104104
name: system:kube-scheduler
105+
- apiVersion: rbac.authorization.k8s.io/v1
106+
kind: ClusterRoleBinding
107+
metadata:
108+
annotations:
109+
rbac.authorization.kubernetes.io/autoupdate: "true"
110+
creationTimestamp: null
111+
labels:
112+
kubernetes.io/bootstrapping: rbac-defaults
113+
name: system:monitoring
114+
roleRef:
115+
apiGroup: rbac.authorization.k8s.io
116+
kind: ClusterRole
117+
name: system:monitoring
118+
subjects:
119+
- apiGroup: rbac.authorization.k8s.io
120+
kind: Group
121+
name: system:monitoring
105122
- apiVersion: rbac.authorization.k8s.io/v1
106123
kind: ClusterRoleBinding
107124
metadata:

plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,26 @@ items:
861861
- nodes/stats
862862
verbs:
863863
- '*'
864+
- apiVersion: rbac.authorization.k8s.io/v1
865+
kind: ClusterRole
866+
metadata:
867+
annotations:
868+
rbac.authorization.kubernetes.io/autoupdate: "true"
869+
creationTimestamp: null
870+
labels:
871+
kubernetes.io/bootstrapping: rbac-defaults
872+
name: system:monitoring
873+
rules:
874+
- nonResourceURLs:
875+
- /healthz
876+
- /healthz/*
877+
- /livez
878+
- /livez/*
879+
- /metrics
880+
- /readyz
881+
- /readyz/*
882+
verbs:
883+
- get
864884
- apiVersion: rbac.authorization.k8s.io/v1
865885
kind: ClusterRole
866886
metadata:

staging/src/k8s.io/apiserver/pkg/authentication/user/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (i *DefaultInfo) GetExtra() map[string][]string {
7070
const (
7171
SystemPrivilegedGroup = "system:masters"
7272
NodesGroup = "system:nodes"
73+
MonitoringGroup = "system:monitoring"
7374
AllUnauthenticated = "system:unauthenticated"
7475
AllAuthenticated = "system:authenticated"
7576

0 commit comments

Comments
 (0)