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
MSSQL storage backend does not work with Azure SQL Server #6104
Comments
Line 108 in df18871
Error initializing storage of type mssql: failed to create mssql database: Login error: mssql: Cannot open user default database. Using master database instead. when a user with access to just the "Vault" database is created. (That is not what this issue is about, that was worked around by just adding the user to the master database)
The problematic line seems to be this one. It seems like using the object_id method should work on both normal SQL Server and the Azure version. |
I found a solution to this bug. I added two pieces to vault/physical/mssql/mssql.go file: My config.hcl file now looks like:
I'd love to do a pull request if this is a viable solution to get the backend working with Azure SQL. I didn't want to potentially break any SQL commands by changing them, but rather just add the database to the connectionString if it was already created for the Azure SQL VM in question. Also, verified that there is a new table "dbo.vault" under tables in this database when starting vault. |
To add, the much easier solution with connecting to an Azure SQL is to add the database connection string the end of the server parameter. This doesn't require changing the underlying Go code at all.
ie:
|
@hbwheat Thanks for digging into this and finding a workaround! My preference would be to keep the configuration simple and update our code to handle both cases gracefully, if possible. I've not looked in the details of what that might be (maybe the object_id approach, or something else), and would welcome a PR. Do you have access to both a normal SQL server as well as Azure's version to try it out? |
@kalafut Unfortunately I’m not much of a DB Admin, and I only have access to Azure AQL at the moment. From what I can tell, it’s an inherit limitation in Azure SQL and the way it allows connections. The Go module connects to the master by default and Azure doesn’t like queries across databases if the database exists already. So if the db doesn’t exist Vault will create a db with a bunch of default settings. If it does exist already it errors out with cross db query not allowed. |
Describe the bug
When attempting to use an Azure MSSQL database, vault fails with the following error on startup:
To Reproduce
Steps to reproduce the behavior:
/etc/vault/config.hcl
vault server -config /etc/vault/config.hcl
Expected behavior
Vault starts up and uses the database
Environment:
vault status
):Vault v1.0.2 ('37a1dc9c477c1c68c022d2084550f25bf20cac33')
vault version
):Vault v1.0.2 ('37a1dc9c477c1c68c022d2084550f25bf20cac33')
Ubuntu 18.04 x86_64
Vault server configuration file(s):
The text was updated successfully, but these errors were encountered: