Skip to content

Added auth method for su/replication user#380

Merged
sgotti merged 1 commit into
sorintlab:masterfrom
emdem:master
Nov 29, 2017
Merged

Added auth method for su/replication user#380
sgotti merged 1 commit into
sorintlab:masterfrom
emdem:master

Conversation

@emdem

@emdem emdem commented Nov 14, 2017

Copy link
Copy Markdown
Contributor

For issue #362

@sgotti sgotti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@emdem Thanks for the PR! I added some comments in line.

It'll be good if you could also add some tests to test that the other auth methods works but if you don't have time I'll do this later in another PR.

Comment thread cmd/keeper/keeper.go Outdated
cmdKeeper.PersistentFlags().StringVar(&cfg.pgListenAddress, "pg-listen-address", "localhost", "postgresql instance listening address")
cmdKeeper.PersistentFlags().StringVar(&cfg.pgPort, "pg-port", "5432", "postgresql instance listening port")
cmdKeeper.PersistentFlags().StringVar(&cfg.pgBinPath, "pg-bin-path", "", "absolute path to postgresql binaries. If empty they will be searched in the current PATH")
cmdKeeper.PersistentFlags().StringVar(&cfg.pgReplAuthMethod, "pg-repl-auth-method", "md5", "postgres replication user auth method. Required.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'll remove "Required" since the default is set to md5 and will break current behavior.

Comment thread cmd/keeper/keeper.go Outdated
}

if cfg.pgReplAuthMethod == "" {
die("--pg-repl-auth-method is required")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't make it required. If not specified will used the default md5 as of now.

Comment thread cmd/keeper/keeper.go Outdated

func keeper(cmd *cobra.Command, args []string) {
var err error
validAuthMethods := map[string]bool{"md5": true, "password": true, "trust": true}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not a big deal but when a map doesn't require a values I prefer to use struct{}: map[string]struct{}

Comment thread cmd/keeper/keeper.go
@@ -1620,6 +1635,11 @@ func keeper(cmd *cobra.Command, args []string) {
if cfg.pgReplPassword != "" && cfg.pgReplPasswordFile != "" {
die("only one of --pg-repl-password or --pg-repl-passwordfile must be provided")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When using the trust auth method the user doesn't have to provide a password.

}

func NewManager(pgBinPath string, dataDir string, localConnParams, replConnParams ConnParams, suUsername, suPassword, replUsername, replPassword string, requestTimeout time.Duration) *Manager {
func NewManager(pgBinPath string, dataDir string, localConnParams, replConnParams ConnParams, suAuthMethod, suUsername, suPassword, replAuthMethod, replUsername, replPassword string, requestTimeout time.Duration) *Manager {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In https://github.com/emdem/stolon/blob/8635f157ab57190d8607c179b8b66b47af7f7d6b/pkg/postgresql/postgresql.go#L363 we also populate the su and repl user password. I'll change them to populate it only with md5 auth since with trust I'll ignore if the user have provided a password.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sgotti I gave it a lot of thought and decided to simply force the user to either utilize md5 + password and then over-ride specific connections via the spec/stolonctl update/init.

Need to confirm, but if I recall correctly, it's possible with this code to set a password/md5 auth for super user from the keeper, then to utilize stolonctl or the json spec provided to sentinel to add trust for localhost superuser connections.

I'll start working on the documentation changes when the code changes are at a state you feel comfortable.

Comment thread cmd/keeper/keeper.go Outdated

func keeper(cmd *cobra.Command, args []string) {
var err error
validAuthMethods := map[string]bool{"md5": true, "password": true, "trust": true}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure if we should also add the password method since postgres doc suggests to use md5.

@emdem emdem force-pushed the master branch 4 times, most recently from 512eb5a to 2975db9 Compare November 16, 2017 18:12
@emdem

emdem commented Nov 16, 2017

Copy link
Copy Markdown
Contributor Author

Added #42 code changes as well. Simply fails with error message indicating version 9.4 or greater is needed.

@sgotti

sgotti commented Nov 17, 2017

Copy link
Copy Markdown
Member

@emdem Thanks! I thinks this needs some tests but we can make them in another PR. So it looks good to me after removing the unrelated changes:

Added #42 code changes as well. Simply fails with error message indicating version 9.4 or greater is needed.

Please put this in another pull request since they are two completely different changes.

@emdem

emdem commented Nov 17, 2017

Copy link
Copy Markdown
Contributor Author

@sgotti #384

seperated the code to a seperate PR

@sgotti sgotti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@emdem I tried this PR but I'm getting some errors:

  • initializing the db when using trust for both su and repl users. I think it's related to my comment.

  • when using trust for only repl user the standby continuously restarts with the message: connection parameters changed. Reconfiguring. It thinks the replication parameters are changed because the parsed one doesn't contain the password key while the generated one contains a password key with an empty value. So the getReplConnParam method (and similar ones) should be changed to not add empty passwords to the returned ConnParams.

func (p *Manager) start(args ...string) error {
log.Infow("starting database")
name := filepath.Join(p.pgBinPath, "pg_ctl")
log.Infow("starting database")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this line has been moved?

Comment thread pkg/postgresql/postgresql.go Outdated
defer cancel()

if p.suUsername == p.replUsername {
if p.suUsername == p.replUsername && p.suAuthMethod != "trust" && p.replAuthMethod != "trust" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should add the replication role to superuser also when authmethod is trust. What shouldn't be done is to set a password. Probably alterRole method should be improved/changed to work with empty passwords.

The same also for the call to createRole below (in creating replication role).

@emdem emdem force-pushed the master branch 4 times, most recently from 86e6c64 to e434672 Compare November 21, 2017 20:07
@emdem

emdem commented Nov 21, 2017

Copy link
Copy Markdown
Contributor Author

@sgotti I made some changes, including incorporating the additional comments/suggestions you made... I'm testing them a bit more thoroughly. So far... much better.

@sgotti sgotti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@emdem Great! It LGTM. I just noted two minor changes but If you don't have time I'll merge this as is and then create a new PR to add these changes and some tests.

Comment thread cmd/keeper/keeper.go Outdated
}

if cfg.pgReplPasswordFile != "" {
if cfg.pgReplAuthMethod != "trust" && cfg.pgReplPasswordFile != "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The check for cfg.pgReplAuthMethod != "trust" can be omitted since it was already checked previously

Comment thread cmd/keeper/keeper.go Outdated
}
}
if cfg.pgSUPasswordFile != "" {
if cfg.pgSUAuthMethod != "trust" && cfg.pgSUPasswordFile != "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The check for cfg.pgSuAuthMethod != "trust" can be omitted since it was already checked previously

@sgotti sgotti merged commit d23713a into sorintlab:master Nov 29, 2017
sgotti added a commit that referenced this pull request Nov 29, 2017
Added auth method for su/replication user
@sgotti

sgotti commented Nov 29, 2017

Copy link
Copy Markdown
Member

@emdem Thanks a lot! Merged.

@sgotti sgotti added this to the v0.8.0 milestone Jan 18, 2018
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.

2 participants