Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login using an aad service account on an aad integrated aks #354

Closed
adasseville opened this issue Feb 6, 2020 · 6 comments
Closed

Login using an aad service account on an aad integrated aks #354

adasseville opened this issue Feb 6, 2020 · 6 comments

Comments

@adasseville
Copy link

Hi,

Based on this #235 comment, I'm trying to connect to an aad integrated aks instance. For a non aad integrated cluster this works fine, but for an aad integrated cluster the kubeConfigFileContent generated by the code snippet below is missing the "access-token" config key in the azure auth-provider section.

var client = Azure
 .Configure()
 .Authenticate(credentials)
 .WithSubscription(subscription);
var kubeConfigFileContent = client.KubernetesClusters
 .GetUserKubeConfigContentsAsync(resourceGroup, clusterName).Result;

This means the sdk fails to build the KubernetesClientConfiguration object throwing this error. This is because the access-token is required for method SetUserDetails to work with the azure auth provider. This all makes sense to me. However I do not understand, or am unable to create a kubeConfigFileContent containing an access-token. I tried naively to generate an access token myself to later inject in the kubeConfigFileContent and succeeded in generating the token itself, but failed to get it to work.

string resourceUri = "my-correct-resource-uri";
string authorityUri = "https://login.windows.net/common/oauth2/" + tenantId;
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(authorityUri);

var clientCredential = new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(clientId, clientSecret);
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult token = authContext.AcquireTokenAsync(resourceUri, clientCredential).Result; 

Namely because the generated access token is not accepted by the k8s api which throws 401 when trying to use it.

Is it at all possible to use a aad service account for this scenario? Am I missing something? Do I need to specify specific arguments when requesting the access token? Do I need to grant specific api access to the service account to make it work?
I'm a bit puzzled here and hope someone can point me in the right direction.

Thanks a lot.

@brendandburns
Copy link
Contributor

Do you have a kubeconfig file that works with kubectl?

If you use that kubectl file with this client it should all work correctly.

That's the best tested path.

Let me know if that doesn't work, or if there are more questions.

@adasseville
Copy link
Author

Yes I have a kubeconfig working with a named aad "user" (by using az aks get-credentials), but not for a service principal. I did not succeed in creating one with the service principle for the azure auth-provider containing an access token.

@brendandburns
Copy link
Contributor

Ah, yes, I missed the Service Principal part. AAD + Kubernetes doesn't currently support service accounts unfortunately, it only supports interactive login.

We're working on improving that in the upstream Kubernetes.

@adasseville
Copy link
Author

Thanks @brendandburns
Any way I can track progress on that feature(request) ?

@brendandburns
Copy link
Contributor

You can file an issue here:
https://github.com/Azure/AKS

If you'd like, please reference this issue in that one.

@adasseville
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants