简体   繁体   English

配置了 Azure AD RBAC 的 Azure DevOp Pipelines 身份验证到 AKS?

[英]Azure DevOp Pipelines authentication to AKS with Azure AD RBAC configured?

We have configured our Azure Kubernetes Clusters to use Azure Active Directory RBAC.我们已将 Azure Kubernetes 集群配置为使用 Azure Active Directory RBAC。 This means when using kubectl we need to first authenticate as an AD user (usually done through manually completing device code authentication via the web browser).这意味着在使用 kubectl 时,我们需要首先以 AD 用户身份进行身份验证(通常通过 Web 浏览器手动完成设备代码身份验证来完成)。 We have configured this almost exactly as per the MSDN article Integrate Azure Active Directory with Azure Kubernetes Service .我们几乎完全按照 MSDN 文章“将 Azure Active Directory 与 Azure Kubernetes 服务集成”进行了配置。

The issue is that this authentication is now also required for Kubernetes build/release tasks in Azure DevOp Pipelines, for example when we run kubectl apply:问题是 Azure DevOp Pipelines 中的 Kubernetes 构建/发布任务现在也需要此身份验证,例如当我们运行 kubectl apply 时:

2019-01-02T08:48:21.2070286Z ##[section]Starting: kubectl apply
2019-01-02T08:48:21.2074936Z ==============================================================================
2019-01-02T08:48:21.2075160Z Task         : Deploy to Kubernetes
2019-01-02T08:48:21.2075398Z Description  : Deploy, configure, update your Kubernetes cluster in Azure Container Service by running kubectl commands.
2019-01-02T08:48:21.2075625Z Version      : 1.1.17
2019-01-02T08:48:21.2075792Z Author       : Microsoft Corporation
2019-01-02T08:48:21.2076009Z Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=851275)
2019-01-02T08:48:21.2076245Z ==============================================================================
2019-01-02T08:48:25.7971481Z Found tool in cache: kubectl 1.7.0 x64
2019-01-02T08:48:25.7980222Z Prepending PATH environment variable with directory: C:\agents\HephaestusForge\_work\_tool\kubectl\1.7.0\x64
2019-01-02T08:48:25.8666111Z [command]C:\agents\HephaestusForge\_work\_tool\kubectl\1.7.0\x64\kubectl.exe apply -f C:\agents\HephaestusForge\_work\r8\a\_MyProject\kubernetes\deploy.yaml -o json
2019-01-02T08:48:26.3518703Z To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code CUYYYYYVV to authenticate.

What is a workaround for this?什么是解决方法? Is it possible to have Azure DevOps authenticate itself as a server client instead of an AD client?是否可以让 Azure DevOps 作为服务器客户端而不是 AD 客户端进行身份验证?

You can use the admin profile which doesn't require interactive login but unfortunately bypasses any RBAC controls you may have setup.您可以使用不需要交互式登录的管理员配置文件,但不幸的是绕过了您可能设置的任何 RBAC 控件。

Vote here: https://feedback.azure.com/forums/914020-azure-kubernetes-service-aks/suggestions/35146387-support-non-interactive-login-for-aad-integrated-c在这里投票: https : //feedback.azure.com/forums/914020-azure-kubernetes-service-aks/suggestions/35146387-support-non-interactive-login-for-aad-integrated-c

You can use kubelogin for your pipeline from https://github.com/Azure/kubelogin您可以从https://github.com/Azure/kubelogin为您的管道使用 kubelogin

Here's the full example by starting at the login step, Until getting the namespace resource inside Kubernetes.这是从登录步骤开始的完整示例,直到在 Kubernetes 中获取命名空间资源。

az login --service-principal -u $APP_ID -p $PASSWORD -t $TENANT

This statement more important, If you don't have existing cluster context in your ~/.kube/config file这句话更重要,如果你的~/.kube/config文件中没有现有的集群上下文

az aks get-credentials --resource-group $RG_AKS --name $CLUSTER_NAME --overwrite-existing --file .kubeconfig-${CLUSTER_NAME}
Merged "my-aks-cluster-name" as current context in .kubeconfig-my-aks-cluster-name

Use kubelogin instead of az aks get-credential ....使用 kubelogin 而不是az aks get-credential ....

export KUBECONFIG=$(pwd)/.kubeconfig-${CLUSTER_NAME}
kubelogin convert-kubeconfig -l spn
export AAD_SERVICE_PRINCIPAL_CLIENT_ID=$APP_ID
export AAD_SERVICE_PRINCIPAL_CLIENT_SECRET=$PASSWORD

Now you can run kubectl without device authentication现在你可以在没有设备身份验证的情况下运行 kubectl

kubectl get pods -n $NAMESPACE
NAME                       READY   STATUS    RESTARTS   AGE
myapp-be-7c8cf7d8b9-gnj2t   1/1     Running   0          103m
myapp-cms-65fd6df9c-z7752   1/1     Running   0          14m
myapp-fe-5dbcdd8d9c-fzxgh   1/1     Running   0          52m

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM