-
-
Notifications
You must be signed in to change notification settings - Fork 121
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
adding support for service principal-based authentication, and non-default tenants #109
Conversation
…incipal-based authetication
…incipal-based authetication -- readme and release
Thanks for the PR, but I think we might be able to do this differently. The current authentication depends on the TokenCredential. Currently, it uses the The Another option is to use the az cli to login first. Use the login with a service principle and you have an authenticated connection that the azure cost cli will use to connect to Azure. At least, that is the theory, as I always use the Would this approach also work for you? |
I do want to say that this option (of specifying credentials) is not obvious and not listed in the readme. The DefaultAzureCredentials has a lot of hidden logic. |
The SecurityCredential class I have added includes the first part if EnvironmentCredencials. If this can be used, the PR would not be necessary. I tried with az login but I couldn't make it. That's why I added the code. I'll review az login tonight and see how would work. |
I added this to the Readme.md. but as said in previous message, if can be done with az cli, or az login, I'd close the PR. Reason is simplicity of code. I had doubts if adding the security part would add unnecesary logic to your nice app. " azure-cost costByResource -s 574385a9-08e9-49fe-91a2-27660d92b8f5 --tenantId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx -o json azure-cost costByResource -s 574385a9-08e9-49fe-91a2-27660d92b8f5 --tenantId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx --servicePrincipalId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx --servicePrincipalSecret <secret_value> -o json Tenant Id: --tenantId If the three values ara provided, service principal-based authentication will be used. |
The ChainedTokenProvider I added favors the AzureCliProvider (to speed up the process), so in that sense overwriting the default first EnvironmentProvider. So if there is already an Azure CLI token, it wont pick up the environment one. |
I remove the PR as it is covered already in az login: |
I have added support to query costs using service principals.
I have added these command options:
that populates the class SecurityCredentials.
It might look many changes, but it is not.
I had to pass the SecurityCredencials object to the RetrieveToken method by parameter.
I am not great in C#, nor in the app, so it might be possible in a different manner.
I had to change the Retrievers parameters, ExecuteCallToCostApi parameter,
Global SecurityCredencials might be easier, but I didn't know how to define it, and I just wanted to add to your good code.
The logic to retrieve the token is simple:
non default tenant id authentication would not be neccesary into the application if you connect using az login --tenant.
But, as the tenant id is necessary for service principal authenthcation, I have added non default tenants.
I've explained the logic in the readme.md too.
Review the wording, as I am not English native.