-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
add mssql physical backend #2546
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Overall this look pretty good. There are just a few things relating to required arguments and handling of schemas.
Also, can you please add documentation for configuring this plugin. You can add the documentation here website/source/docs/configuration/storage
physical/mssql.go
Outdated
return nil, fmt.Errorf("failed to create mssql database: %v", err) | ||
} | ||
|
||
dbTable := database + ".." + table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is assuming the default schema, presumably dbo
. Can you please add a configuration option for the schema with a default value of dbo
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I add schema option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement will no longer be necessary if you remove the conditional schema logic.
physical/mssql.go
Outdated
connectionString := "server=" + server + ";app name" + appname + ";connection timeout=" + connectionTimeout + ";log=" + logLevel | ||
if username != "" { | ||
connectionString += ";user id=" + username | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of case where there is no username or password. I think it should fail if this is not provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without username and password, driver is using SSO.
From driver documentation:
"user id" - enter the SQL Server Authentication user id or the Windows Authentication user id in the DOMAIN\User format. On Windows, if user id is empty or missing Single-Sign-On is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the most likely usage would be providing a username and password to this backend. Are you expecting to use the Single Sign-On features of the driver? I would be curious to see how this works in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can provide username and password. SSO is only option of mssql go driver so I added it as a feature to this provider.
Yes, In our environment we use sso. For example when I am logged to my workstation I can connect to mssql database on different machine. (It's works same as Windows Auth in this example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some further internal discussions, we believe this is fine. Even though SSO makes a lot of sense in a user workstation context it could also work in this context. This is especially true since the same person configuring the Vault installation will also be in charge of the physical backend configuration.
} | ||
|
||
if password != "" { | ||
connectionString += ";password=" + password |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above reply ;)
return nil, fmt.Errorf("failed to connect to mssql: %v", err) | ||
} | ||
|
||
if _, err := db.Exec("IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = '" + database + "') CREATE DATABASE " + database); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should work without specifying the database. To be more explicit, it may make sense to add the master
database to this query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I you don't include database name, default name 'Vault' will be used. It's working same as mysql and postgres provider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that sys.databases
was a special table that resided in master
but I don't actually think that is the case, so I think this is fine.
physical/mssql.go
Outdated
} | ||
|
||
dbTable := database + ".." + table | ||
createQuery := "IF NOT EXISTS(SELECT 1 FROM " + database + ".INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND TABLE_NAME='" + table + "') CREATE TABLE " + dbTable + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on adding schema above, TABLE_SCHEMA will need to be added to the criteria for this query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement will no longer be necessary if you remove the conditional schema logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the docs. A few minor edits to the docs and a couple of changes to handling schema.
physical/mssql.go
Outdated
schema = "dbo" | ||
} | ||
|
||
connectionString := "server=" + server + ";app name" + appname + ";connection timeout=" + connectionTimeout + ";log=" + logLevel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a missing =
after app name
. Would you mind converting this to a fmt.Sprintf
which may make it easier to spot these issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok changed.
physical/mssql.go
Outdated
createQuery := "IF NOT EXISTS(SELECT 1 FROM " + database + ".INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND TABLE_NAME='" + table + "') CREATE TABLE " + dbTable + | ||
" (Path VARCHAR(512) PRIMARY KEY, Value VARBINARY(MAX))" | ||
|
||
if schema != "dbo" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this guard is necessary. It is likely the dbo
schema is going to be available but it probably still makes sense to do the same check for dbo
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must check if user want different schema than dbo and create it when it does not exists. You can't drop schema dbo and it always exists. MSDN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the docs. I thought dbo
was just a default schema and could itself be dropped.
|
||
## `mssql` Parameters | ||
|
||
- `server` `(string: "localhost")` – host or host\instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this to <required>
instead of "localhost"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
|
||
- `server` `(string: "localhost")` – host or host\instance. | ||
|
||
- `username` `(string: "user1234")` - enter the SQL Server Authentication user id or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this to the default value of ""
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
the Windows Authentication user id in the DOMAIN\User format. | ||
On Windows, if user id is empty or missing Single-Sign-On is used. | ||
|
||
- `password` `(string: "secret123!")` – specifies the MSSQL password to connect to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update this to the default value of ""
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
- `schema` `(string: "dbo")` – Specifies the name of the schema. If the schema | ||
does not exist, Vault will attempt to create it. | ||
|
||
- `appname` `(string: "vault")` – the application name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/vault/Vault/ to match the default in code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
|
||
### Custom Database, Table and Schema | ||
|
||
This example shows configuring the MySQL backend to use a custom database and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/MySql/MSSQL/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
physical/mssql.go
Outdated
connectionString := "server=" + server + ";app name" + appname + ";connection timeout=" + connectionTimeout + ";log=" + logLevel | ||
if username != "" { | ||
connectionString += ";user id=" + username | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some further internal discussions, we believe this is fine. Even though SSO makes a lot of sense in a user workstation context it could also work in this context. This is especially true since the same person configuring the Vault installation will also be in charge of the physical backend configuration.
physical/mssql.go
Outdated
} | ||
|
||
dbTable := database + ".." + table | ||
createQuery := "IF NOT EXISTS(SELECT 1 FROM " + database + ".INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND TABLE_NAME='" + table + "') CREATE TABLE " + dbTable + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement will no longer be necessary if you remove the conditional schema logic.
physical/mssql.go
Outdated
return nil, fmt.Errorf("failed to create mssql database: %v", err) | ||
} | ||
|
||
dbTable := database + ".." + table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement will no longer be necessary if you remove the conditional schema logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.