Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow special characters in pg-su-username #658

Merged

Conversation

dineshba
Copy link
Contributor

If we are having special characters in su username like below

./stolon-keeper --pg-su-username=user-name # other flags

We are getting below error

INFO    postgresql/postgresql.go:534    setting superuser password
2019-06-01 01:34:40.031 IST [60923] ERROR:  syntax error at or near "-" at character 14

But in postgres, having role as user-name is allowed. So it is better if stolon also allow this.

I just added double quotes for username in alter role command.

There are two more places in stolon where we are altering role. In those two places we are already using double quotes. https://github.com/sorintlab/stolon/blob/master/internal/postgresql/utils.go#L104 and https://github.com/sorintlab/stolon/blob/master/internal/postgresql/utils.go#L115

@sgotti
Copy link
Member

sgotti commented Jun 3, 2019

@dineshba Good catch!

What about using consistent single quotes (or double quotes, I don't know which is better in such case) like in with password '%s'.

As a note if someone is going to ask:

I'll have preferred to use sql prepared statements with arguments like:
dbExec(ctx, db, "alter role $1 with password $2", username, password)

but unfortunately this doesn't work (returning a syntax error) since in postgres prepared statements works only for SELECT, INSERT, UPDATE, DELETE, or VALUES statement: https://www.postgresql.org/docs/11/sql-prepare.html

@dineshba dineshba force-pushed the allow-special-character-in-su-username branch from d60926f to 82caece Compare June 3, 2019 17:19
@dineshba
Copy link
Contributor Author

dineshba commented Jun 3, 2019

Thanks for the quick review @sgotti. For consistency, I made everything as single quotes and amended to the same commit.
Initially, I made everything as single quotes. But it is not working

Below is the combination of different tries:

postgres=# alter role 'db-role' password "abcd";
ERROR:  syntax error at or near "'db-role'"
LINE 1: alter role 'db-role' password "abcd";
                   ^
postgres=# alter role "db-role" password "abcd";
ERROR:  syntax error at or near ""abcd""
LINE 1: alter role "db-role" password "abcd";
                                      ^
postgres=# alter role "db-role" password 'abcd';
ALTER ROLE
Conclusion:
  • For alter/create role we should use double quotes only ( no quotes if there is no special character in role name
  • For password we should use only single quotes (not optional)

@dineshba dineshba force-pushed the allow-special-character-in-su-username branch 3 times, most recently from eb6aaae to 2cf4040 Compare June 4, 2019 03:56
@dineshba dineshba force-pushed the allow-special-character-in-su-username branch from 2cf4040 to fa93d9a Compare June 4, 2019 04:44
@sgotti
Copy link
Member

sgotti commented Jun 4, 2019

@dineshba you're right. Merging. Thanks!

@sgotti sgotti merged commit 19f1d26 into sorintlab:master Jun 4, 2019
@dineshba dineshba deleted the allow-special-character-in-su-username branch June 4, 2019 13:45
@dineshba
Copy link
Contributor Author

dineshba commented Jun 4, 2019

@sgotti Thanks 👍

@sgotti sgotti modified the milestone: v0.14.0 Jun 6, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants