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

ui: logging in with capitalized username prevent access to Databases and Statements pages #51663

Open
sheaffej opened this issue Jul 21, 2020 · 13 comments
Labels
A-authentication Pertains to authn subsystems A-cc-enablement Pertains to current CC production issues or short-term projects A-webui Triage label for DB Console (fka admin UI) issues. Add this if nothing else is clear. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-observability

Comments

@sheaffej
Copy link
Collaborator

sheaffej commented Jul 21, 2020

Edit 2021-03-01 (@knz) The issue description is misguided. See comment belows by @aaron-crl and myself.


Describe the problem

When logging into the Admin UI and specifying a valid user with the admin role with the username capitalized, the Admin UI mostly works OK except the Databases and Statements pages do not work properly. Logging in using the same user with the username lower-cased does provides proper access to these pages.

To Reproduce

  1. Create a secure CRDB cluster
  2. Create a new user and assign the admin role to the user. You can create this user in any combination of lower-, upper- or mixed-case. The user will be created in the database with a username that is lower-case.
create user j4 password 'j4';
grant admin to j4;
  1. Login to the Admin UI using the user created above, but specifying the username capitalized --> J4
    Notice the UI displays the logged in user with the capitalized name
    image

  2. Attempt to access the Statements page, and observe the error message.
    image

  3. Attempt to access the Databases page, and observe the page does not populate.
    image

  4. Logout. Then login using the same username, but specify the username in lower-case.
    Notice the UI displays the logged in user with the lower case name.
    image

  5. Access the Statements and Database pages, and observe that they work properly.

Expected behavior
Admin UI should convert the username specified during login into lower-case, matching the username expected by the database.

Environment:
Build Tag: v20.1.1
Build Time: 2020/05/19 14:40:33
Distribution: CCL
Platform: darwin amd64 (x86_64-apple-darwin14)
Go Version: go1.13.9
C Compiler: 4.2.1 Compatible Clang 3.8.0 (tags/RELEASE_380/final)
Build SHA-1: 6123c0c
Build Type: release

Jira issue: CRDB-4017

@sheaffej sheaffej added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-webui Triage label for DB Console (fka admin UI) issues. Add this if nothing else is clear. labels Jul 21, 2020
@tharun208
Copy link
Contributor

@asubiotto, I like to work on this, before starting the implementation, can we change it to lower-case while storing it in the state or throw a validation error when the capital letter is entered.

@asubiotto
Copy link
Contributor

Good question. Intuitively, I think we should throw a validation error, but cc @aaron-crl who might have a more informed opinion of this.

@aaron-crl
Copy link

This is a correctness bug for auth too; if we don't accept upper-case characters in usernames in the database we should not accept and use them in the UI.

I'd be opposed to silently normalizing too as this may result in user surprise when using a password manager where they've stored the uppercase username and it works on one interface but not another.

On an aside it sounds like some but not all of our UI code is normalizing usernames before they are sent to the database. We should review these endpoints to ensure they are properly sanitizing input.

Possibly related: #55398

cc @knz @bdarnell

@knz
Copy link
Contributor

knz commented Mar 2, 2021

To start, I don't think this is a project we're willing to farm out to contributors outside of our team. It needs to touch multiple areas across the product and also align with our (internal) CockroachCloud authentication strategy.

Now to the specific issue, in the description at top:

Admin UI should convert the username specified during login into lower-case, matching the username expected by the database.

This behavior would be incorrect. If the username inside the database contains capitals, then it would become impossible for that user to log in into the UI.

What we need here is twofold:

  1. stop normalizing usernames in the web UI altogether
  2. when a user enters a username in the login form and no user with that name is found in the database, but there is another username with a different case, give a hint in the web form that the form is case-sensitive as a reminder (But do not actually show the different-case username in the tooltip, this would be a confidentiality breach)

In general I am not keen to looking at this issue in isolation. There should be a wider discussion.

@knz knz added this to To do in DB Server & Security via automation Mar 2, 2021
@bdarnell
Copy link
Member

bdarnell commented Mar 2, 2021

Last time this came up, I thought we decided that usernames should be case-insensitive (possibly for compatibility with postgres), and that all entry points should be normalizing to lowercase (see the MakeSQLUsernameFromUserInput function). The CREATE USER statement already does this; I'm not sure if it's possible to create a user with a non-lowercase name unless you modify the system.users table manually.

@jlinder jlinder added the T-server-and-security DB Server & Security label Jun 16, 2021
@knz knz added A-authentication Pertains to authn subsystems A-cc-enablement Pertains to current CC production issues or short-term projects labels Jul 29, 2021
@knz
Copy link
Contributor

knz commented Jul 29, 2021

Ok so I think the "next action" here is to normalize the input in the login form in the UI, so that the UI does not retain a username that's not normalized for subsequent lookups in views.

How does this sound?

@dhartunian can you help us triage this?

@knz knz added this to Backlog in Cluster UI via automation Jul 29, 2021
@knz knz added this to To do in Observability Infrastructure via automation Jul 29, 2021
@knz knz removed this from To do in DB Server & Security Jul 29, 2021
@mgoddard
Copy link

mgoddard commented Nov 4, 2021

My experience just now seems related to this issue, around case sensitivity (or insensitivity) for objects in the DB. When I run CREATE ROLE IF NOT EXISTS "rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-Nm9bM"; I get a role that looks like this: root@localhost:5432/defaultdb> show roles; username | options | member_of -----------------------------------------------------+---------+------------ admin | | {} root | | {admin} rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-nm9bm | NOLOGIN | {} (3 rows)

Later, when I attempt to run this, it fails since this role doesn't exist (in this context, the uppercase characters are preserved): ALTER TABLE public.user_mapping OWNER TO "rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-Nm9bM";

Is there any way to get around this apart from lower-casing any of these role names?

@knz
Copy link
Contributor

knz commented Nov 4, 2021

this is a different issue. Let's file it separately.

@knz
Copy link
Contributor

knz commented Nov 4, 2021

@mgoddard can you double check this? I just ran the following without error:

 CREATE ROLE IF NOT EXISTS "rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-Nm9bM";
 grant create on database defaultdb to "rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-Nm9bM";
 create table user_mapping(x int);
 ALTER TABLE public.user_mapping OWNER TO "rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-Nm9bM";

@mgoddard
Copy link

mgoddard commented Nov 4, 2021

$ cockroach sql --certs-dir ../certs  --host=localhost:5432
#
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
#
# Server version: CockroachDB CCL v21.1.11 (x86_64-unknown-linux-gnu, built 2021/10/18 14:39:35, go1.15.14) (same version as client)
# Cluster ID: 84c1cece-112f-456e-9334-52193e60f809
#
# Enter \? for a brief introduction.
#
root@localhost:5432/defaultdb> CREATE ROLE IF NOT EXISTS "rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-Nm9bM";
CREATE ROLE

Time: 11ms total (execution 11ms / network 0ms)

root@localhost:5432/defaultdb> grant create on database defaultdb to "rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-Nm9bM";
GRANT

Time: 42ms total (execution 41ms / network 0ms)

root@localhost:5432/defaultdb> create table user_mapping(x int);
CREATE TABLE

Time: 10ms total (execution 10ms / network 0ms)

root@localhost:5432/defaultdb> ALTER TABLE public.user_mapping OWNER TO "rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-Nm9bM";
ERROR: role/user "rw-role-94e1ffe8-d4e3-46a3-8968-0c034537b6a9-Nm9bM" does not exist
SQLSTATE: 42704
root@localhost:5432/defaultdb>

@knz
Copy link
Contributor

knz commented Nov 4, 2021

@rafiss can you look at the failure reported by @mgoddard in the last comment?

This error does not occur in the master branch but does occur in 21.2 and 21.1. I think this might be a missing backport.
Is this commit d2fc2a3 perhaps the one that would help?

@rafiss
Copy link
Collaborator

rafiss commented Nov 4, 2021

The PR that fixes this bug is #70439

specifically this part of the diff
image

It's quite a large change which is why it wasn't backported. Given that there's a workaround, I think instead we should list it as a known limitation for v21.2 and earlier. I'll file a docs issue. Edit: on second thought, let me try a smaller fix

However, as @knz mentioned above, this is different than the original issue reported here. The DB Console still needs to normalize usernames into lower case to address this issue.

@github-actions
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-authentication Pertains to authn subsystems A-cc-enablement Pertains to current CC production issues or short-term projects A-webui Triage label for DB Console (fka admin UI) issues. Add this if nothing else is clear. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-observability
Projects
No open projects
Development

No branches or pull requests

9 participants