MSSQL Database Secrets Engine
MSSQL is one of the supported plugins for the database secrets engine. This plugin generates database credentials dynamically based on configured roles for the MSSQL database.
See the database secrets engine docs for more information about setting up the database secrets engine.
Capabilities
Plugin Name | Root Credential Rotation | Dynamic Roles | Static Roles | Username Customization |
---|---|---|---|---|
mssql-database-plugin | Yes | Yes | Yes | Yes (1.7+) |
Setup
Enable the database secrets engine if it is not already enabled:
By default, the secrets engine will enable at the name of the engine. To enable the secrets engine at a different path, use the
-path
argument.Configure Vault with the proper plugin and connection information:
Note: The example above demonstrates a connection with SQL server user named
vaultuser
, although the uservaultuser
might be Windows Authentication user part of Active Directory domain, for example:DOMAIN\vaultuser
.In this case, we've configured Vault with the user "vaultuser" and password "yourStrong(!)Password", connecting to an instance at "localhost" on port 1433. It is not necessary that Vault has the vaultuser login, but the user must have privileges to create logins and manage processes. The fixed server roles
securityadmin
andprocessadmin
are examples of built-in roles that grant these permissions. The user also must have privileges to create database users and grant permissions in the databases that Vault manages. The fixed database rolesdb_accessadmin
anddb_securityadmin
are examples or built-in roles that grant these permissions.Configure a role that maps a name in Vault to an SQL statement to execute to create the database credential:
Be aware! If no revocation_statement
is supplied,
vault will execute the default revocation procedure.
In larger databases, this might cause connection timeouts.
Please specify a revocation statement in such a scenario.
Usage
After the secrets engine is configured and a user/machine has a Vault token with the proper permission, it can generate credentials.
Generate a new credential by reading from the
/creds
endpoint with the name of the role:
Example for Azure SQL Database
Here is a complete example using Azure SQL Database. Note that databases in Azure SQL Database are contained databases and that we do not create a login for the user; instead, we associate the password directly with the user itself. Also note that you will need a separate connection and role for each Azure SQL database for which you want to generate dynamic credentials. You can use a single database backend mount for all these databases or use a separate mount for of them. In this example, we use a custom path for the database backend.
First, we mount a database backend at the azuresql path with vault secrets enable -path=azuresql database
. Then we configure a connection called "testvault" to connect to a database called "test-vault", using "azuresql" at the beginning of our path:
Now we add a role called "test" for use with the "testvault" connection:
We can now use this role to dynamically generate credentials for the Azure SQL database, test-vault:
When we no longer need the backend, we can unmount it with vault unmount azuresql
. Now, you can use the MSSQL Database Plugin with your Azure SQL databases.
Amazon RDS
The MSSQL plugin supports databases running on Amazon RDS, but there are differences that need to be accommodated. A key limitation is that Amazon RDS doesn't support the "sysadmin" role, which is used by default during Vault's revocation process for MSSQL. The workaround is to add custom revocation statements to roles, for example:
API
The full list of configurable options can be seen in the MSSQL database plugin API page.
For more information on the database secrets engine's HTTP API please see the Database secrets engine API page.