Skip to content

Commit

Permalink
*: allow periods (.) in usernames
Browse files Browse the repository at this point in the history
Requested by a user:

> Currently, there is a restriction for the database username which
> will limit the certificate-based authentication. It's very common to
> include .local (e.g.: internal-service2.local) in the CN (Common Name)
> of a certificate.  The AWS Certificate Manager (ACM) won't even issue
> a certificate if the "dot" (.) is not present.

Release note (sql change): Usernames can now contain periods, for
compatibility with certificate managers that require domain names to
be used as usernames.
  • Loading branch information
knz committed Dec 11, 2019
1 parent edc18a6 commit e0e8fa2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1487,13 +1487,13 @@ func Example_user() {
// CREATE USER 1
// user set ,foo
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// ERROR: username ",foo" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// ERROR: username ",foo" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, periods, or underscores, and must not exceed 63 characters
// user set f,oo
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// ERROR: username "f,oo" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// ERROR: username "f,oo" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, periods, or underscores, and must not exceed 63 characters
// user set foo,
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// ERROR: username "foo," invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// ERROR: username "foo," invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, periods, or underscores, and must not exceed 63 characters
// user set 0foo
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// CREATE USER 1
Expand All @@ -1508,7 +1508,7 @@ func Example_user() {
// CREATE USER 1
// user set foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// ERROR: username "foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// ERROR: username "foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, periods, or underscores, and must not exceed 63 characters
// user set foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// CREATE USER 1
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/create_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ func (*CreateUserNode) Close(context.Context) {}
func (n *CreateUserNode) FastPathResults() (int, bool) { return n.run.rowsAffected, true }

const usernameHelp = "usernames are case insensitive, must start with a letter, " +
"digit or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters"
"digit or underscore, may contain letters, digits, dashes, periods, or underscores, and must not exceed 63 characters"

var usernameRE = regexp.MustCompile(`^[\p{Ll}0-9_][\p{Ll}0-9_-]{0,62}$`)
var usernameRE = regexp.MustCompile(`^[\p{Ll}0-9_][\p{Ll}0-9_.---]{0,62}$`)

var blacklistedUsernames = map[string]struct{}{
security.NodeUser: {},
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/drop_user
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ DROP USER IF EXISTS user1
statement error username "node" reserved
DROP USER node

statement error pq: username "foo☂" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
statement error pq: username "foo☂" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, periods, or underscores, and must not exceed 63 characters
DROP USER foo☂

statement ok
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/user
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ CREATE USER uSEr2 WITH PASSWORD 'cockroach'
statement ok
CREATE USER user3 WITH PASSWORD '蟑螂'

statement error pq: username "foo☂" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
statement error pq: username "foo☂" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, periods, or underscores, and must not exceed 63 characters
CREATE USER foo☂

statement error pq: username "-foo" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
statement error pq: username "-foo" invalid; usernames are case insensitive, must start with a letter, digit or underscore, may contain letters, digits, dashes, periods, or underscores, and must not exceed 63 characters
CREATE USER "-foo"

statement error at or near "-": syntax error
Expand Down

0 comments on commit e0e8fa2

Please sign in to comment.