Skip to content

Commit a9d1482

Browse files
authored
Merge pull request kubernetes#93311 from logicalhan/monitoring-role
Add bootstrap policy for monitoring endpoints
2 parents 8466b5b + f576119 commit a9d1482

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
@@ -699,6 +699,9 @@ function create-master-auth {
699699
append_or_replace_prefixed_line "${known_tokens_csv}" "${KONNECTIVITY_SERVER_TOKEN}," "system:konnectivity-server,uid:system:konnectivity-server"
700700
create-kubeconfig "konnectivity-server" "${KONNECTIVITY_SERVER_TOKEN}"
701701
fi
702+
if [[ -n "${MONITORING_TOKEN:-}" ]]; then
703+
append_or_replace_prefixed_line "${known_tokens_csv}" "${MONITORING_TOKEN}," "system:monitoring,uid:system:monitoring,system:monitoring"
704+
fi
702705

703706
if [[ -n "${EXTRA_STATIC_AUTH_COMPONENTS:-}" ]]; then
704707
# Create a static Bearer token and kubeconfig for extra, comma-separated components.
@@ -2936,7 +2939,9 @@ function main() {
29362939
if [[ "${ENABLE_EGRESS_VIA_KONNECTIVITY_SERVICE:-false}" == "true" ]]; then
29372940
KONNECTIVITY_SERVER_TOKEN="$(secure_random 32)"
29382941
fi
2939-
2942+
if [[ "${ENABLE_MONITORING_TOKEN:-false}" == "true" ]]; then
2943+
MONITORING_TOKEN="$(secure_random 32)"
2944+
fi
29402945

29412946
setup-os-params
29422947
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)