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

Added auth method for su/replication user #380

Merged
merged 1 commit into from
Nov 29, 2017
Merged

Conversation

emdem
Copy link
Contributor

@emdem emdem commented Nov 14, 2017

For issue #362

Copy link
Member

@sgotti sgotti left a comment

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.

@@ -112,9 +114,11 @@ func init() {
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
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.

@@ -1610,6 +1619,12 @@ func keeper(cmd *cobra.Command, args []string) {
die("cannot create data dir: %v", err)
}

if cfg.pgReplAuthMethod == "" {
die("--pg-repl-auth-method is required")
Copy link
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.

@@ -1579,6 +1587,7 @@ func main() {

func keeper(cmd *cobra.Command, args []string) {
var err error
validAuthMethods := map[string]bool{"md5": true, "password": true, "trust": true}
Copy link
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{}

@@ -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
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.

@@ -76,16 +78,18 @@ type InitConfig struct {
DataChecksums bool
}

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
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
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.

@@ -1579,6 +1587,7 @@ func main() {

func keeper(cmd *cobra.Command, args []string) {
var err error
validAuthMethods := map[string]bool{"md5": true, "password": true, "trust": true}
Copy link
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
Copy link
Contributor Author

emdem commented Nov 16, 2017

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

@sgotti
Copy link
Member

sgotti commented Nov 17, 2017

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

emdem commented Nov 17, 2017

@sgotti #384

seperated the code to a seperate PR

Copy link
Member

@sgotti sgotti left a comment

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.

name := filepath.Join(p.pgBinPath, "pg_ctl")
log.Infow("starting database")
Copy link
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?

@@ -360,15 +364,15 @@ func (p *Manager) SetupRoles() error {
ctx, cancel := context.WithTimeout(context.Background(), p.requestTimeout)
defer cancel()

if p.suUsername == p.replUsername {
if p.suUsername == p.replUsername && p.suAuthMethod != "trust" && p.replAuthMethod != "trust" {
Copy link
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
Copy link
Contributor Author

emdem commented Nov 21, 2017

@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.

Copy link
Member

@sgotti sgotti left a comment

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.

die("provided superuser name and replication user name are the same but provided passwords are different")
}
}

if cfg.pgReplPasswordFile != "" {
if cfg.pgReplAuthMethod != "trust" && cfg.pgReplPasswordFile != "" {
Copy link
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

cfg.pgReplPassword, err = readPasswordFromFile(cfg.pgReplPasswordFile)
if err != nil {
die("cannot read pg replication user password: %v", err)
}
}
if cfg.pgSUPasswordFile != "" {
if cfg.pgSUAuthMethod != "trust" && cfg.pgSUPasswordFile != "" {
Copy link
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
Copy link
Member

sgotti commented Nov 29, 2017

@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