Kubelet Authentication & Authorization

Support HackTricks

Kubelet Authentication

来自文档:

默认情况下,未被其他配置的身份验证方法拒绝的对kubelet的HTTPS端点的请求被视为匿名请求,并被赋予用户名 system:anonymous和组 system:unauthenticated

3种身份验证方法是:

  • 匿名(默认):使用设置参数**--anonymous-auth=true或配置:**

"authentication": {
"anonymous": {
"enabled": true
},
  • Webhook: 这将 启用 kubectl API bearer tokens 作为授权(任何有效的令牌都将有效)。允许它:

  • 确保在 API 服务器中启用 authentication.k8s.io/v1beta1 API 组

  • 使用 --authentication-token-webhook--kubeconfig 标志启动 kubelet,或使用以下设置:

"authentication": {
"webhook": {
"cacheTTL": "2m0s",
"enabled": true
},

kubelet 在配置的 API 服务器上调用 TokenReview API确定用户信息 从承载令牌

  • X509 客户端证书: 允许通过 X509 客户端证书进行身份验证

  • 有关更多详细信息,请参见 apiserver 身份验证文档

  • 使用 --client-ca-file 标志启动 kubelet,提供 CA 包以验证客户端证书。或者使用配置:

"authentication": {
"x509": {
"clientCAFile": "/etc/kubernetes/pki/ca.crt"
}
}

Kubelet Authorization

任何成功认证的请求(包括匿名请求)随后会被授权默认的授权模式是**AlwaysAllow,这允许所有请求**。

然而,另一个可能的值是**webhook(这就是你大多数情况下会发现的**)。此模式将检查已认证用户的权限以允许或拒绝某个操作。

请注意,即使启用了匿名认证匿名访问可能没有执行任何操作的权限

通过 webhook 的授权可以使用**参数 --authorization-mode=Webhook**或通过配置文件进行配置:

"authorization": {
"mode": "Webhook",
"webhook": {
"cacheAuthorizedTTL": "5m0s",
"cacheUnauthorizedTTL": "30s"
}
},

The kubelet calls the SubjectAccessReview API on the configured API server to 确定 whether each request is 授权.

The kubelet authorizes API requests using the same request attributes approach as the apiserver:

  • Action

HTTP verbrequest 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 始终 nodes and subresource is the incoming request's path 决定:

Kubelet APIresourcesubresource

/stats/*

nodes

stats

/metrics/*

nodes

metrics

/logs/*

nodes

log

/spec/*

nodes

spec

all others

nodes

proxy

For example, the following request tried to access the pods info of kubelet without permission:

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)
  • 我们得到了一个 Forbidden,所以请求 通过了身份验证检查。如果没有,我们只会收到一个 Unauthorised 消息。

  • 我们可以看到 用户名(在这种情况下来自令牌)

  • 检查 资源nodes,而 子资源proxy(这与之前的信息相符)

References

Support HackTricks

Last updated