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

add mssql physical backend #2546

Merged
merged 6 commits into from
Apr 6, 2017
Merged

Conversation

sebastianhabaing
Copy link
Contributor

No description provided.

@jefferai jefferai added this to the 0.7.1 milestone Mar 30, 2017
Copy link
Contributor

@chrishoffman chrishoffman left a 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

return nil, fmt.Errorf("failed to create mssql database: %v", err)
}

dbTable := database + ".." + table
Copy link
Contributor

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?

Copy link
Contributor Author

@sebastianhabaing sebastianhabaing Mar 31, 2017

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.

Copy link
Contributor

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.

connectionString := "server=" + server + ";app name" + appname + ";connection timeout=" + connectionTimeout + ";log=" + logLevel
if username != "" {
connectionString += ";user id=" + username
}
Copy link
Contributor

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.

Copy link
Contributor Author

@sebastianhabaing sebastianhabaing Mar 31, 2017

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@sebastianhabaing sebastianhabaing Apr 3, 2017

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)

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

@sebastianhabaing sebastianhabaing Mar 31, 2017

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.

Copy link
Contributor

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.

}

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 +
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@chrishoffman chrishoffman left a 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.

schema = "dbo"
}

connectionString := "server=" + server + ";app name" + appname + ";connection timeout=" + connectionTimeout + ";log=" + logLevel
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok changed.

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" {
Copy link
Contributor

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.

Copy link
Contributor Author

@sebastianhabaing sebastianhabaing Apr 6, 2017

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

Copy link
Contributor

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.
Copy link
Contributor

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"?

Copy link
Contributor Author

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
Copy link
Contributor

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 ""?

Copy link
Contributor Author

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
Copy link
Contributor

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 ""?

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/MySql/MSSQL/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

connectionString := "server=" + server + ";app name" + appname + ";connection timeout=" + connectionTimeout + ";log=" + logLevel
if username != "" {
connectionString += ";user id=" + username
}
Copy link
Contributor

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.

}

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 +
Copy link
Contributor

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.

return nil, fmt.Errorf("failed to create mssql database: %v", err)
}

dbTable := database + ".." + table
Copy link
Contributor

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.

Copy link
Contributor

@chrishoffman chrishoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chrishoffman chrishoffman merged commit 9d013a0 into hashicorp:master Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants