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

MSSQL: Credential rotation does not work with Azure SQL Databases #10806

Closed
g-psantos opened this issue Jan 28, 2021 · 1 comment · Fixed by #12839
Closed

MSSQL: Credential rotation does not work with Azure SQL Databases #10806

g-psantos opened this issue Jan 28, 2021 · 1 comment · Fixed by #12839
Labels
bug Used to indicate a potential bug secret/database/mssql secret/database

Comments

@g-psantos
Copy link

g-psantos commented Jan 28, 2021

Describe the bug
Rotation of root credentials for Azure SQL Databases (MSSQL) ceased working with the changes that were made in support of static roles (#9062) and v5 of the Vault database interface (#10128). When attempting to rotate the root credentials for a contained user account created to enable Vault to issue dynamic credentials, the following error occurs:

$ vault write -force database/rotate-root/conn-name
Error writing data to database/rotate-root/conn-name: Error making API request.

URL: PUT https://vault-server:8200/v1/database/rotate-root/conn-name
Code: 500. Errors:

* 1 error occurred:
        * failed to update user: mssql: Reference to database and/or server name in 'master.sys.server_principals' is not supported in this version of SQL Server.

To Reproduce

  1. Create an Azure SQL Database for testing (e.g., mydb).
  2. Create a contained user in your database, so that Vault can issue dynamic credentials to that database:
CREATE USER vault WITH PASSWORD = 'secretPassword2021!';
  1. Add a database connection to Vault along these lines; note that the root_credentials_rotate_statements parameter is what previously enabled root credentials to be successfully rotated without attempting to call the master database:
Key                                   Value
---                                   -----
connection_details          map[connection_url:sqlserver://{{username}}:{{password}}@my-server-name.database.windows.net:1433?encrypt=true&TrustServerCertificate=false&database=mydb&app+name=vault username:vault]
plugin_name                    mssql-database-plugin
root_credentials_rotate_statements    [ALTER USER {{username}} WITH PASSWORD='{{password}}']
  1. Attempt to rotate the root credentials: vault write -force database/rotate-root/conn-name
  2. See error

Expected behavior
The root credentials were previously rotated without issue (confirmed working with Vault 1.4.7).

Environment:

  • Vault Server Version (retrieve with vault status): 1.6.1
  • Vault CLI Version (retrieve with vault version): 1.6.0
  • Server Operating System/Architecture: CentOS 7.x

Vault server configuration file(s):
Likely irrelevant so not posted, but can post if need be.

Additional context
The problem appears to stem from the new implementation of updateUserPass(), which is now assuming that it's dealing with a SQL Server Login (in the server's master database) and doesn't account for the possibility of contained users, which are associated exclusively with each database.

@g-psantos
Copy link
Author

g-psantos commented May 7, 2021

@johnathanschmidt I'm considering starting a PR to address this issue.

It looks like the PostgreSQL plugin also checks whether a user exists before changing its password, but others (MySQL, Cassandra) don't have that check built in.

So, I would propose to delete the check from the MSSQL plugin. This will allow the custom rotation statements to be the only ones executed, and those can target contained users or server logins, as appropriate. If a server login or contained user do not exist, the operation will fail anyway.

Am I missing anything?

g-psantos added a commit to g-psantos/vault that referenced this issue May 7, 2021
Removes a query from the MSSQL plugin that checks that a Server Login
exists before attempting to change its password. This behavior is
incompatible with SQL Server instances that rely on contained users
and that do not allow cross-database queries, as is the case with
Azure SQL Databases.

The deletion of this query does not materially impact the behavior,
as attempting to change the password for an inexistent login (on a
regular SQL Server instance) will result in an error message that
states that the user either does not exist (or the Vault user does
not have permission to change its password).

If the Vault user is a contained user, then the "root rotation
statements" parameter can be modified to alter the password of a
`user` rather than a `login` (`ALTER USER vault WITH PASSWORD ...`).

Fixes hashicorp#10806
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to indicate a potential bug secret/database/mssql secret/database
Projects
None yet
3 participants