usql: Can't connect via Azure Active Directory authentication
Following go-mssqldb
user@server:~$ go install -tags sqlserver github.com/xo/usql@8a0cccf
user@server:~$ usql --version
usql 0.0.0-dev
user@server:~$ usql 'sqlserver://xxx.database.windows.net?database=xxx&user id=xxx&password=xxx'
Connected with driver sqlserver (Microsoft SQL Server x.x, RTM, SQL Azure)
Type "help" for help.
ms:xxx=>
user@server:~$ usql 'azuresql://xxx.database.windows.net?database=xxx&fedauth=ActiveDirectoryMSI'
error: sqlserver: 18456: login error: Login failed for user ''.
Enter password:
user@server:~$ usql 'azuresql://xxx.database.windows.net?database=xxx&fedauth=ActiveDirectoryMSI&user id=xxx'
error: sqlserver: 18456: login error: Login failed for user 'xxx'.
Enter password:
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 42 (22 by maintainers)
@kenshaw
SUCCESS!!!
Shortly after you posted your response, I actually did get it working with usql. So the problem does not lie therein. The reason I had encountered those errors was because the Virtual Machine (in Azure) in which I was running the usql command from, did not have the user-assigned managed identity properly setup on the backend. Once I set that up properly, I was able to successfully run the usql command as well as my Go code.
But it was still failing inside my sql_exporter Kubernetes deployment (aka pod, aka container), which I thought was properly setup on the backside to work with the user-assigned managed identity I had created. So I created a usql Docker container and ran that inside a Kubernetes deployment with the connection to my SQL server in Azure using the
fedauth=ActiveDirectoryManagedIdentityparameter and it successfully connected.So this brings me back to my problem with sql_exporter, where I believe the problem lies: https://github.com/burningalchemist/sql_exporter/issues/169
CC @reubano
@kenshaw, TLDR: Your code has been successfully tested with an Azure SQL Server.
@reubano Never mind – I think I found the issue.
You’re very welcome @kenshaw! I’m glad I could help out.
@reubano You may have an Azure misconfiguration. However, Azure is quite new to me and I’m still figuring things out. It took me 1-2 weeks to finally get user-assigned managed identities working correctly (Azure setup/configuration – lots of reading and trial and error).
As to not clutter this GitHub issue with discussion that may not actually be related to a problem with usql, feel free to contact me via email and I will help you to the best of my abilities. You can find my email on my profile.