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

Basic privilege granting and checking #763

Merged
merged 1 commit into from
Jan 28, 2022
Merged

Basic privilege granting and checking #763

merged 1 commit into from
Jan 28, 2022

Conversation

Hydrocharged
Copy link
Contributor

This adds an extremely basic implementation of privilege checking, along with the ability to grant a subset of privileges. In addition, connections carry along their authentication information, and direct queries on the engine (through use of the *sql.Context) also carry auth information for later privilege checking.

Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

Overall pretty good, great tests as usual.

Just a few things to clean up and think about.

enginetest/enginetests.go Show resolved Hide resolved
enginetest/enginetests.go Show resolved Hide resolved
enginetest/enginetests.go Outdated Show resolved Hide resolved
sql/analyzer/privileges.go Outdated Show resolved Hide resolved
@@ -50,6 +49,7 @@ var OnceBeforeDefault = []Rule{
{"validate_read_only_database", validateReadOnlyDatabase},
{"validate_read_only_transaction", validateReadOnlyTransaction},
{"validate_database_set", validateDatabaseSet},
{"check_privileges", checkPrivileges}, // Ensure that checking privileges happens after db & table resolution
Copy link
Member

Choose a reason for hiding this comment

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

Do unprivileged users have "show tables" access? If not, you might need to do checks on raw names, not sure.

In a lot of auth systems it's considered a security leak to let an unprivileged user probe the namespaces, so resolving tables before checking auth might not be correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like I need to do possibly checks in multiple places. Did a bit more research and testing in MySQL and this is basically how it seems to work:

First we check for a valid user authentication, whether that be password, certificate, etc. Next, gather which databases the user has access to. Everyone has access to information_schema (note about this later), so that's added to the list. If the user has any global static privileges (those in the user table), then they can see all databases and all tables. If not, check which databases they have database-level privileges on (those in the db table, not yet implemented). Any privileges there give you full view of the tables in that database. Last, check the tables_priv table (also not yet implemented), with any privileges there showing their associated table.

So if you have global static privileges, you'll get a "database/table does not exist" error on an invalid database/table. If you only have access to specific databases, then any database (valid or invalid) that you don't have access to will give you an "access denied" error. Same goes for the table level. Also, if you have privileges on a database or table that doesn't exist (GRANT doesn't check for database or table existence, so DBAs can set up users before the rest of the repo), you'll get that "does not exist" error on only those databases/tables.

About information_schema, as everyone has access to it, it actually restricts its output based on the privileges of the connected user. So even though you can fully query it, you don't have access to all of the information it contains. Pretty neat, but also a lot more work.

Also also, I think partial revokes remove entries from that big list of databases and tables, but I didn't test those as they're not coming any time soon.

sql/errors.go Show resolved Hide resolved
sql/plan/grant.go Outdated Show resolved Hide resolved
Base automatically changed from daylon/users-4 to main January 28, 2022 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants