Kubelet autentikacija i autorizacija
Tip
Nauči & vežbaj AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Nauči & vežbaj GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Nauči & vežbaj Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Podržite HackTricks
- Pogledajte subscription plans!
- Pridružite se 💬 Discord group or the telegram group or pratite nas na Twitter 🐦 @hacktricks_live.
- Podelite hacking tricks slanjem PR-ova na HackTricks i HackTricks Cloud github repos.
Kubelet autentikacija
By default, requests to the kubelet’s HTTPS endpoint that are not rejected by other configured authentication methods are treated as anonymous requests, and given a korisničko ime system:anonymous and a grupa system:unauthenticated.
Postoje 3 metode autentikacije su:
- Anonymous (podrazumevano): Dozvoljeno ako je podešen parametar
--anonymous-auth=trueili u konfiguraciji:
"authentication": {
"anonymous": {
"enabled": true
},
- Webhook: Ovo će omogućiti kubectl API bearer tokens kao autorizaciju (bilo koji važeći token će biti važeći). Dozvolite to sa:
- osigurajte da je
authentication.k8s.io/v1beta1API grupa omogućena u API serveru - pokrenite kubelet sa
--authentication-token-webhooki--kubeconfigzastavicama ili koristite sledeće podešavanje:
"authentication": {
"webhook": {
"cacheTTL": "2m0s",
"enabled": true
},
Note
Kubelet poziva
TokenReviewAPI na konfigurisanom API serveru da bi odredio informacije o korisniku iz bearer tokena
- X509 klijentski sertifikati: Omogućavaju autentifikaciju putem X509 klijentskih sertifikata
- pogledajte apiserver authentication documentation za više detalja
- pokrenite kubelet sa
--client-ca-fileflagom, obezbeđujući CA bundle za verifikaciju klijentskih sertifikata. Ili sa konfiguracijom:
"authentication": {
"x509": {
"clientCAFile": "/etc/kubernetes/pki/ca.crt"
}
}
Kubelet autorizacija
Svaki zahtev koji je uspešno autentifikovan (uključujući anonimni zahtev) se zatim autorizuje. Podrazumevani režim autorizacije je AlwaysAllow, koji dozvoljava sve zahteve.
Međutim, druga moguća vrednost je webhook (što je ono što ćete uglavnom sresti napolju). Ovaj režim će proveriti dozvole autentifikovanog korisnika da dozvoli ili onemogući neku akciju.
Warning
Imajte na umu da čak i ako je anonimna autentifikacija omogućena, anonimni pristup možda nema nikakve dozvole za izvođenje bilo koje akcije.
Autorizacija preko webhook-a se može konfigurisati koristeći parametar --authorization-mode=Webhook ili putem konfiguracionog fajla sa:
"authorization": {
"mode": "Webhook",
"webhook": {
"cacheAuthorizedTTL": "5m0s",
"cacheUnauthorizedTTL": "30s"
}
},
Kubelet poziva SubjectAccessReview API na konfigurisanom API serveru da utvrdi da li je svaki zahtev autorizovan.
Kubelet autorizuje API zahteve koristeći isti request attributes pristup kao apiserver:
- Akcija
| HTTP verb | request verb |
|---|---|
| POST | create |
| GET, HEAD | get (for individual resources), list (for collections, including full object content), watch (for watching an individual resource or collection of resources) |
| PUT | update |
| PATCH | patch |
| DELETE | delete (for individual resources), deletecollection (for collections) |
- The resource talking to the Kubelet api is always nodes and subresource is determined from the incoming request’s path:
| Kubelet API | resurs | subresurs |
|---|---|---|
| /stats/* | nodes | stats |
| /metrics/* | nodes | metrics |
| /logs/* | nodes | log |
| /spec/* | nodes | spec |
| all others | nodes | proxy |
Note
WebSocket-based
/exec,/run,/attach, and/portforwardfall into the default proxy subresource and are authorized using the initial HTTP GET handshake. A principal with onlynodes/proxyGET can still exec containers if it connects directly tohttps://<node_ip>:10250over WebSockets. See the nodes/proxy GET -> Kubelet /exec verb confusion abuse for details.
Na primer, sledeći zahtev je pokušao da pristupi informacijama o pods kubeleta bez dozvole:
curl -k --header "Authorization: Bearer ${TOKEN}" 'https://172.31.28.172:10250/pods'
Forbidden (user=system:node:ip-172-31-28-172.ec2.internal, verb=get, resource=nodes, subresource=proxy)
- Dobili smo Forbidden, dakle zahtev je passed the Authentication check. Da nije tako, dobili bismo samo
Unauthorisedporuku. - Možemo videti username (u ovom slučaju iz tokena)
- Pogledajte kako je resource bio nodes i subresource proxy (što je u skladu sa prethodnim informacijama)
References
- https://kubernetes.io/docs/reference/access-authn-authz/kubelet-authn-authz/
- nodes/proxy GET -> kubelet exec via WebSocket bypass
Tip
Nauči & vežbaj AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Nauči & vežbaj GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Nauči & vežbaj Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Podržite HackTricks
- Pogledajte subscription plans!
- Pridružite se 💬 Discord group or the telegram group or pratite nas na Twitter 🐦 @hacktricks_live.
- Podelite hacking tricks slanjem PR-ova na HackTricks i HackTricks Cloud github repos.
HackTricks Cloud

