Tailscale経由でkube-apiserverにアクセスできなくなってしまった
急にkubectlが以下を吐くようになってしまった
kubectl get pods
Error from server (Forbidden): pods is forbidden: User "***" cannot list resource "pods" in API group "" in the namespace "default"以前、ArgoCD dashboardにtailscale経由でアクセスする。でセットアップ自体は行った。
今回も一旦https://tailscale.com/kb/1437/kubernetes-operator-api-server-proxyを見てみる。
思い出した。tailscale-operatorをinstallする際にapiServerProxyConfigをmode: "true"に設定しておくことでtailscale-operatorがよしなにやってくれているわけだ。
kube contextへの追加はtailscale configure kubeconfigコマンドで行っている。
kubectl config view
apiVersion: v1
clusters:
- cluster:
server: https://tailscale-operator.xxx.ts.net
name: tailscale-operator.xxx.net
contexts:
- context:
cluster: tailscale-operator.xxx.ts.net
user: tailscale-auth
name: tailscale-operator.xxx.ts.net
kind: Config
preferences: {}
users:
- name: tailscale-auth
user:
token: REDACTED
このtoken自体の中身も実際にはunusedとなっていて、実際にkube-apiserverに対して使用される認証情報はtailscale-operator内のkube-apiserver-proxyが付与している(impersonation)
どのようなユーザーとして認証されているかを確認する。
kubectl auth whoami
ATTRIBUTE VALUE
Username xxx@xxx.com
Groups [system:authenticated]問題の切り分けとして、tailscaleを通さずにlocalのnetworkから疎通するcontextに変えて試してみる。
kubectl get nodes
NAME STATUS ROLES AGE VERSION
talos-gbq-owt Ready <none> 291d v1.32.0
talos-gyi-70o Ready control-plane 294d v1.32.0
talos-h7r-wox Ready <none> 294d v1.32.0
talos-plu-5dz Ready <none> 291d v1.32.0コマンドも通る。kube-apiserver自体が落ちているというレベルでの話ではなさそう。
kubectl get pods
No resources found in default namespace.ついでにproxmox自体でVMの様子も見てみたときに、Keyがexpireしてtailscaleのprocessも落ちていたので更新して立ち上げ直しておいた。ちょこちょこお世話してあげないといけない。
適切な権限がついていないように見受けられる。
kubectl auth can-i --list
Resources Non-Resource URLs Resource Names Verbs
selfsubjectreviews.authentication.k8s.io [] [] [create]
selfsubjectaccessreviews.authorization.k8s.io [] [] [create]
selfsubjectrulesreviews.authorization.k8s.io [] [] [create]
[/api/*] [] [get]
[/api] [] [get]
[/apis/*] [] [get]
[/apis] [] [get]
[/healthz] [] [get]
[/healthz] [] [get]
[/livez] [] [get]
[/livez] [] [get]
[/openapi/*] [] [get]
[/openapi] [] [get]
[/readyz] [] [get]
[/readyz] [] [get]
[/version/] [] [get]
[/version/] [] [get]
[/version] [] [get]
[/version] [] [get]にあるような適切なimpersonationができていない。grantが使われていなければtagがgroupとして使用されるべきだが、それもされていないので単にtailnet上のusernameがk8s上のusernameとして利用されているという状況っぽい。
tailscaleのACLをgrants方式に変換する
https://tailscale.com/kb/1542/grants-migration
tailscaleのドキュメントに従ってimpersonationを行うためには、ACLsから推奨される方式であるgrantsの方式に設定を書き換える必要がある。
現状特に凝った設定を行っているわけでもなかったため、dashboardの"Convert to grants..."で十分だった。