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

cli: fix username semantics for userfile #56046

Merged
merged 1 commit into from
Oct 29, 2020

Conversation

adityamaru
Copy link
Contributor

Previously, userfile would break if a user had a username with special
characters, which is otherwise supported by CRDB.
This is because, unless specified, userfile uses the username to
generate the underlying storage table names.

This change introduces a new name generation scheme which accounts for
all usernames supported by the database. The details are explained in:
#55389 (comment)

Fixes: #55389

Release note: None

@adityamaru adityamaru requested a review from knz October 28, 2020 13:08
@adityamaru adityamaru requested a review from a team as a code owner October 28, 2020 13:08
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@adityamaru adityamaru force-pushed the userfile-username-improvements branch from dfb13a4 to 707a8b5 Compare October 28, 2020 13:15
Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! 💯

Reviewed 5 of 5 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru)


pkg/cli/userfile.go, line 182 at r1 (raw file):

// - Support for all current and future valid usernames.
func getDefaultQualifiedTableName(user security.SQLUsername) string {
	if !lexbase.IsRestrictedSQLIdentQuotedOnEncode(user.Normalized()) {
  1. to ease readability, what about a username := user.Normalized() at the beginning then reuse that.

  2. can you explain why you care whether the username is a reserved keyword? When concatenated with username_, its reserved nature disappears because of the prefix. What do you think?

@adityamaru adityamaru force-pushed the userfile-username-improvements branch from 707a8b5 to e988766 Compare October 28, 2020 13:50
Copy link
Contributor Author

@adityamaru adityamaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/cli/userfile.go, line 182 at r1 (raw file):

Previously, knz (kena) wrote…
  1. to ease readability, what about a username := user.Normalized() at the beginning then reuse that.

  2. can you explain why you care whether the username is a reserved keyword? When concatenated with username_, its reserved nature disappears because of the prefix. What do you think?

good point, i didn't think of that. Switched to just checking whether it is a bare identifier or not.

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: but please revert the now-unnecessary changes

Reviewed 2 of 3 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @adityamaru)


pkg/sql/lexbase/encode.go, line 54 at r2 (raw file):

// keyword.
func EncodeRestrictedSQLIdent(buf *bytes.Buffer, s string, flags EncodeFlags) {
	if flags.HasFlags(EncBareIdentifiers) || (!isReservedKeyword(s) && IsBareIdentifier(s)) {

you can revert the changes to this file now


pkg/sql/lexbase/predicates.go, line 72 at r2 (raw file):

// IsBareIdentifier returns true if the input string is a permissible bare SQL
// identifier.
func IsBareIdentifier(s string) bool {

ditto

@adityamaru
Copy link
Contributor Author

I had to export IsBareIdentifier() so that I could use it in the userfile logic. The changes to those files are all related to that. Am I misunderstanding something?

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had misread. This is fine as is. Go ahead.

Reviewed 1 of 3 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @adityamaru)

Previously, userfile would break if a user had a username with special
characters, which is otherwise supported by CRDB.
This is because, unless specified, userfile uses the username to
generate the underlying storage table names.

This change introduces a new name generation scheme which accounts for
all usernames supported by the database. The details are explained in:
cockroachdb#55389 (comment)

Fixes: cockroachdb#55389

Release note: None
@adityamaru adityamaru force-pushed the userfile-username-improvements branch from e988766 to e2130f7 Compare October 29, 2020 13:32
@adityamaru
Copy link
Contributor Author

TFTR!

bors r=knz

@craig
Copy link
Contributor

craig bot commented Oct 29, 2020

Build succeeded:

@craig craig bot merged commit c40c007 into cockroachdb:master Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants