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

Update HanaDb to v5 Database interface #10142

Merged
merged 10 commits into from
Oct 21, 2020
Merged

Update HanaDb to v5 Database interface #10142

merged 10 commits into from
Oct 21, 2020

Conversation

Valarissa
Copy link
Contributor

@Valarissa Valarissa commented Oct 14, 2020

Updates the HANA Database plugin to adhere to the v5 Database interface.

/usr/local/go/bin/go tool test2json -t /private/var/folders/4v/k2rn39v578d238ttqpwdkkkh0000gp/T/___hana_test_go -test.v -test.run ^\QTestHANA_Initialize\E|\QTestHANA_NewUser\E|\QTestHANA_UpdateUser\E|\QTestHANA_DeleteUser\E$
=== RUN   TestHANA_Initialize
--- PASS: TestHANA_Initialize (0.01s)
=== RUN   TestHANA_NewUser
--- PASS: TestHANA_NewUser (0.08s)
=== RUN   TestHANA_UpdateUser
--- PASS: TestHANA_UpdateUser (0.24s)
=== RUN   TestHANA_DeleteUser
--- PASS: TestHANA_DeleteUser (1.09s)
PASS

Process finished with exit code 0

@Valarissa Valarissa requested review from pcman312 and a team October 14, 2020 00:07
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana.go Show resolved Hide resolved
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
@Valarissa Valarissa requested a review from tvoran October 14, 2020 22:02
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
@Valarissa Valarissa requested a review from tvoran October 15, 2020 20:18
Copy link
Member

@tvoran tvoran left a comment

Choose a reason for hiding this comment

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

Sorry, this is getting caught in the changeover from newdbplugin --> dbplugin/v5.

The other thing I noticed is that updating a user's expiration isn't being tested, though I'm not sure how hard that would be to add.

plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana_test.go Outdated Show resolved Hide resolved
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana.go Show resolved Hide resolved
if err != nil {
return err
if req.Password != nil {
err = h.updateUserPassword(ctx, tx, req.Username, req.Password)
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing passwords and expirations will share a transaction. Is that intentional? I'm okay with it, I just want to make sure everyone else is good with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did, in fact, do that intentionally. The way I see it, if a user attempts to do two different actions and one fails, knowing the same request can be used is helpful. I'm not sure how others feel, but that's my preference with most interactions with an API.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, if I update two pieces of configuration in the same API call to Vault, I would find it least surprising as a user if they either both succeed or both fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome! That's the same logic I had in my head, I just wanted to make sure everyone was on the same page.

plugins/database/hana/hana.go Outdated Show resolved Hide resolved
plugins/database/hana/hana_test.go Outdated Show resolved Hide resolved
plugins/database/hana/hana_test.go Outdated Show resolved Hide resolved
plugins/database/hana/hana_test.go Outdated Show resolved Hide resolved
plugins/database/hana/hana_test.go Outdated Show resolved Hide resolved
plugins/database/hana/hana_test.go Outdated Show resolved Hide resolved
func (h *HANA) RenewUser(ctx context.Context, statements dbplugin.Statements, username string, expiration time.Time) error {
statements = dbutil.StatementCompatibilityHelper(statements)
func (h *HANA) UpdateUser(ctx context.Context, req newdbplugin.UpdateUserRequest) (newdbplugin.UpdateUserResponse, error) {
h.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Asking because I have the same question for the Redshift DB migration: why do we need to hold a mutex lock inside the plugin? I can see that Vault needs to serialise password updates so that it knows which is the current password after concurrent rotate requests. However, the state is stored outside of this plugin, so the synchronisation would also need to be outside of the plugin i.e. around the state update in the caller. Am I missing another synchronisation requirement? cc @pcman312

Copy link
Contributor

Choose a reason for hiding this comment

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

This was protecting against races when multiple calls are made to the engine at the same time. Specifically: rotate root credentials + any other call since rotate root was changing the plugin instance's configuration. I'm not 100% sure this is needed any longer, but I'd like to keep it for safety until we can confirm that it isn't needed.

plugins/database/hana/hana_test.go Outdated Show resolved Hide resolved
plugins/database/hana/hana_test.go Show resolved Hide resolved
if err != nil {
t.Fatalf("err: %s", err)
db := new()
initResp := dbtesting.AssertInitialize(t, db, initReq)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: probably should include a defer dbtesting.AssertClose(t, db)

userResp := dbtesting.AssertNewUser(t, db, newReq)
assertCredsExist(t, connURL, userResp.Username, password)

test.req.Username = userResp.Username
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of manipulating the test case, what do you think about making the test case have a list of deletion statements rather than the full request object? That way you can construct the request here without having it be a part of the test case.

@Valarissa Valarissa merged commit 4860146 into master Oct 21, 2020
pcman312 pushed a commit that referenced this pull request Oct 23, 2020
* Update HanaDb to v5 dbplugin
* Add ability to update passwords for HANA db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants