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

release-19.2: cli, sql: allow usernames to start with digits #42989

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,7 @@ func Example_user() {
c.Run("user set f,oo")
c.Run("user set foo,")
c.Run("user set 0foo")
c.Run("user set 0123")
c.Run("user set foo0")
c.Run("user set f0oo")
c.Run("user set foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof")
Expand Down Expand Up @@ -1483,16 +1484,19 @@ 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.
// pq: username ",foo" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// 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
// user set f,oo
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// pq: username "f,oo" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// pq: 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
// user set foo,
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// pq: username "foo," invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// 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
// user set 0foo
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// pq: username "0foo" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// CREATE USER 1
// user set 0123
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// CREATE USER 1
// user set foo0
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// CREATE USER 1
Expand All @@ -1501,7 +1505,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.
// pq: username "foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// pq: 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
// user set foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo
// warning: This command is deprecated. Use CREATE USER or ALTER USER ... WITH PASSWORD ... in a SQL session.
// CREATE USER 1
Expand All @@ -1518,6 +1522,8 @@ func Example_user() {
// warning: This command is deprecated. Use SHOW USERS or SHOW ROLES in a SQL session.
// user_name
// +-----------------------------------------------------------------+
// 0123
// 0foo
// _foo
// and
// f0oo
Expand All @@ -1529,14 +1535,16 @@ func Example_user() {
// root
// table
// ομηρος
// (11 rows)
// (13 rows)
// user rm foo
// warning: This command is deprecated. Use DROP USER or DROP ROLE in a SQL session.
// DROP USER 1
// user ls --format=table
// warning: This command is deprecated. Use SHOW USERS or SHOW ROLES in a SQL session.
// user_name
// +-----------------------------------------------------------------+
// 0123
// 0foo
// _foo
// and
// f0oo
Expand All @@ -1547,7 +1555,7 @@ func Example_user() {
// root
// table
// ομηρος
// (10 rows)
// (12 rows)
// sql -e drop database defaultdb
// DROP DATABASE
// user set foo
Expand All @@ -1562,12 +1570,14 @@ func Example_cert() {
c.RunWithCAArgs([]string{"cert", "create-client", "foo"})
c.RunWithCAArgs([]string{"cert", "create-client", "Ομηρος"})
c.RunWithCAArgs([]string{"cert", "create-client", "0foo"})
c.RunWithCAArgs([]string{"cert", "create-client", ",foo"})

// Output:
// cert create-client foo
// cert create-client Ομηρος
// cert create-client 0foo
// failed to generate client certificate and key: username "0foo" invalid; usernames are case insensitive, must start with a letter or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters
// cert create-client ,foo
// failed to generate client certificate and key: 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
}

// TestFlagUsage is a basic test to make sure the fragile
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/create_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ func (*CreateUserNode) Close(context.Context) {}
// FastPathResults implements the planNodeFastPath interface.
func (n *CreateUserNode) FastPathResults() (int, bool) { return n.run.rowsAffected, true }

const usernameHelp = "usernames are case insensitive, must start with a letter " +
"or underscore, may contain letters, digits, dashes, or underscores, and must not exceed 63 characters"
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"

var usernameRE = regexp.MustCompile(`^[\p{Ll}_][\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 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, 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 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, 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 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, or underscores, and must not exceed 63 characters
CREATE USER "-foo"

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