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

Kubelet autentikacija

From the docss:

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=true ili 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/v1beta1 API grupa omogućena u API serveru
  • pokrenite kubelet sa --authentication-token-webhook i --kubeconfig zastavicama ili koristite sledeće podešavanje:
"authentication": {
"webhook": {
"cacheTTL": "2m0s",
"enabled": true
},

Note

Kubelet poziva TokenReview API 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-file flagom, 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 verbrequest verb
POSTcreate
GET, HEADget (for individual resources), list (for collections, including full object content), watch (for watching an individual resource or collection of resources)
PUTupdate
PATCHpatch
DELETEdelete (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 APIresurssubresurs
/stats/*nodesstats
/metrics/*nodesmetrics
/logs/*nodeslog
/spec/*nodesspec
all othersnodesproxy

Note

WebSocket-based /exec, /run, /attach, and /portforward fall into the default proxy subresource and are authorized using the initial HTTP GET handshake. A principal with only nodes/proxy GET can still exec containers if it connects directly to https://<node_ip>:10250 over 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 Unauthorised poruku.
  • 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

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