forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Release note (security update): The validation rule for principal names was extended to support periods and thus allow domainname-like principals. For reference, the validation rule is currently the regular expression `^[\p{Ll}0-9_][---\p{Ll}0-9_.]+$` and a size limit of 63 UTF-8 bytes (larger usernames are rejected with an error); for comparison, PostgreSQL allows many more characters and truncates at 63 chacters silently.
- Loading branch information
Showing
5 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package sql_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/sql" | ||
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" | ||
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" | ||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
) | ||
|
||
func TestUserName(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
testCases := []struct { | ||
username string | ||
normalized string | ||
err string | ||
sqlstate string | ||
}{ | ||
{"Abc123", "abc123", "", ""}, | ||
{"0123121132", "0123121132", "", ""}, | ||
{"HeLlO", "hello", "", ""}, | ||
{"Ομηρος", "ομηρος", "", ""}, | ||
{"_HeLlO", "_hello", "", ""}, | ||
{"a-BC-d", "a-bc-d", "", ""}, | ||
{"A.Bcd", "a.bcd", "", ""}, | ||
{"WWW.BIGSITE.NET", "www.bigsite.net", "", ""}, | ||
{"", "", `username "" invalid`, pgcode.InvalidName}, | ||
{"-ABC", "", `username "-abc" invalid`, pgcode.InvalidName}, | ||
{".ABC", "", `username ".abc" invalid`, pgcode.InvalidName}, | ||
{"*.wildcard", "", `username "\*.wildcard" invalid`, pgcode.InvalidName}, | ||
{"foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof", "", `username "foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoof" is too long`, pgcode.NameTooLong}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
normalized, err := sql.NormalizeAndValidateUsername(tc.username) | ||
if !testutils.IsError(err, tc.err) { | ||
t.Errorf("%q: expected %q, got %v", tc.username, tc.err, err) | ||
continue | ||
} | ||
if err != nil { | ||
if pgcode := pgerror.GetPGCode(err); pgcode != tc.sqlstate { | ||
t.Errorf("%q: expected SQLSTATE %s, got %s", tc.username, tc.sqlstate, pgcode) | ||
continue | ||
} | ||
} | ||
if normalized != tc.normalized { | ||
t.Errorf("%q: expected %q, got %q", tc.username, tc.normalized, normalized) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters