-
Notifications
You must be signed in to change notification settings - Fork 6
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
Migrate elasticsearch plugin to v5 database plugin interface #19
Conversation
In DeleteUser, always try deleting the role, since the role name == user name, and we don't get the creation_statement in DeleteUser anymore.
delete the user before the role it uses
Added local_dev.sh and run_acceptance.sh scripts.
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.
Looks good overall. Almost all small nits with a couple of small changes.
elasticsearch.go
Outdated
if err := client.ChangePassword(ctx, req.Username, req.Password.NewPassword); err != nil { | ||
return newdbplugin.UpdateUserResponse{}, fmt.Errorf("unable to change password: %w", err) | ||
} | ||
|
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.
nit: can you add a comment explicitly saying the expiration change is a no-op?
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.
added in 507cc53
return nil, dbutil.ErrEmptyCreationStatement | ||
} | ||
stmt := &creationStatement{} | ||
if err := json.Unmarshal([]byte(statements.Creation[0]), stmt); err != nil { | ||
return nil, errwrap.Wrapf(fmt.Sprintf("unable to unmarshal %s: {{err}}", []byte(statements.Creation[0])), err) | ||
if err := json.Unmarshal([]byte(statements.Commands[0]), stmt); 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.
If I'm reading this correctly, this function will ignore any commands that aren't in the first index. If so, can you put an error if the length of the commands is >1 so the user doesn't get confused?
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.
Yep, added in 507cc53
elasticsearch_test.go
Outdated
if len(configToStore) != len(config) { | ||
t.Fatalf("expected %s, received %s", config, configToStore) | ||
resp := dbtesting.AssertInitialize(t, e.Elasticsearch, req) | ||
if len(resp.Config) != len(req.Config) { |
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.
Since this isn't going through a translation layer (like gRPC), the req.Config
could be manipulated in place, making these assertions useless. I recommend making an expected response object with a copy of the request config then comparing the two.
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.
Ah, ok, done in 507cc53
} | ||
dbtesting.AssertUpdateUser(t, e.Elasticsearch, req) |
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.
Also assert that you can log in with the new credentials?
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.
That is already being done in the integration tests:
vault-plugin-database-elasticsearch/integration_test.go
Lines 152 to 170 in 9cde79b
func (e *IntegrationTestEnv) TestElasticsearch_UpdateUser(t *testing.T) { | |
req := newdbplugin.UpdateUserRequest{ | |
Username: e.Username, | |
Password: &newdbplugin.ChangePassword{ | |
NewPassword: "new password", | |
}, | |
} | |
if !e.tc.Authenticate(t, e.Username, e.Password) { | |
t.Errorf("want successful authentication, got failed authentication for user:%s with password:%s", e.Username, e.Password) | |
} | |
dbtesting.AssertUpdateUser(t, e.Elasticsearch, req) | |
if e.tc.Authenticate(t, e.Username, e.Password) { | |
t.Errorf("want authentication failure, got successful authentication for user:%s with password:%s", e.Username, e.Password) | |
} | |
if !e.tc.Authenticate(t, e.Username, "new password") { | |
t.Errorf("want successful authentication, got failed authentication for user:%s with password:%s", e.Username, "new password") | |
} | |
} |
Seems like that's a better spot since these tests are using a mock elasticsearch.
scripts/local_dev.sh
Outdated
|
||
echo "--> Vault server" | ||
echo " Writing config" | ||
tee "$SCRATCH/vault.hcl" > /dev/null <<EOF |
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.
nit: Why not use -dev-plugin-dir
?
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.
Good idea, changed in 507cc53
-dev-ha -dev-transactional -dev-root-token-id=root \ | ||
& | ||
sleep 2 | ||
VAULT_PID=$! |
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.
Shouldn't this be one line up? Or will it ignore a PID from sleep 2
?
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.
Yeah, $!
is the pid of the last background process, so it ignores the sleep 2
. Doesn't hurt to move it up though.
@@ -13,7 +13,7 @@ func main() { | |||
flags := apiClientMeta.FlagSet() | |||
flags.Parse(os.Args[1:]) | |||
|
|||
if err := elasticsearch.Run(apiClientMeta.GetTLSConfig()); err != nil { | |||
if err := elasticsearch.Run(); 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.
Since we're punting on AutoMTLS
for the time being, this line should be reverted
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.
done in 507cc53
Co-authored-by: Michael Golowka <[email protected]>
Overview
Migrating this plugin to the new database plugin interface.
Design of Change
Then changing the functions to satisfy the newdbplugin Database interface.
Also adds testing docs and scripts.
Related Issues/Pull Requests
Contributor Checklist
My Docs PR Link
Example
Unit and integration tests
Acceptance tests with real elasticsearch