Oli*_*uby 2 active-directory rbac azure kubernetes
我需要授予进程(构建管道)对 AKS API 的 RBAC 访问权限以进行部署。但目标 AKS 群集已激活 AAD 集成(如此处所述)
我原本希望能够通过简单的服务主体访问 AKS API,但我被重定向到设备登录页面:
$ az login --service-principal --username [REDACTED]-XXXX-XXXX-XXXX-XXXXXXXXXXXX --password [REDACTED]XXxxXXxxXXxxxXXXxxXXxxXXxx= --tenant [REDACTED]-XXXX-XXXX-XXXX-XXXXXXXXXXXX
$ az aks get-credentials -n oli-aksdemo01 -g oli-aksdemo01
Merged "oli-aksdemo01" as current context in /home/olivier/.kube/config
$ kubectl get nodes
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code C2NP77EGR to authenticate.
Run Code Online (Sandbox Code Playgroud)
:-(
在 Azure 上集成 AAD 的 AKS 群集上对服务主体进行身份验证时,是否有办法避免设备登录页面?
与@Festus Fashola的答案不同,它的工作原理只是因为它--admin在命令中使用了绕过AAD验证的标志(不是OP所要求的),现在正确的方法是使用KubeLogin,它允许服务主体非交互式身份验证:https://github.com/Azure/kubelogin#service-principal-login-flow-non-interactive
使用示例:
# login
az login --service-principal --username <sp_client_id> --password <password> --tenant <tenant>
# Get the admin credentials for the kubeconfig context
az aks get-credentials --resource-group <resource_group> --name <aks_name>
# convert your kubeconfig file
kubelogin convert-kubeconfig -l spn
# export variables with sp credentials
export AAD_SERVICE_PRINCIPAL_CLIENT_ID=<sp_client_id>
export AAD_SERVICE_PRINCIPAL_CLIENT_SECRET=<sp_password>
# run any kubectl command, you shouldn't get the devicelogin verification message
kubectl get pods
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6573 次 |
| 最近记录: |