-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
sql: Database-level permissions are confusing #16790
Comments
👍 on choosing either the mysql or pg semantics unless we had our own separate syntax, the inconsiderate reuse here is indeed confusing |
I've done some research on this topic and am going to use this issue to both Concepts in the Postgres Privilege WorldIn postgres, catalog entities contain privileges which can be explicitly CockroachIn cockroach, databases and tables carry a In upcoming work we'll be making user-defined schemas carry privileges and we're We need to decide how we want to model these new things in terms of DifferencesBelow find a non-exhaustive list of distinct differences between postgres Separated notions of privileges and default privilegesBecause of this you can run: crdb> CREATE DATABASE foo_db;
crdb> GRANT SELECT ON foo_db TO bar_user; Which would be an error in postgres. There is no postgres direct equivalent. -- posgres
postgres=> ALTER DEFAULT PRIVILEGES IN SCHEMA baz_schema GRANT SELECT TO bar_user; You can similarly set the default privileges on the database for new schemas postgres=> ALTER DEFAULT PRIVILEGES GRANT SELECT TO bar_user; Glob patterns vs explicit statements (#55049)This creates ambiguity problems because of the lack of specification for the In postgres, to grant GRANT SELECT ON ALL TABLES IN SCHEMA baz_schema TO bar_user; In cockroach however, for a database you'd write: GRANT SELECT ON foo_db.* TO bar_user; Of course, that's nonsense in postgres on several levels. With user-defined GRANT SELECT ON baz_schema.* TO bar_user; Furthermore, postgres provides support for granting all privileges with Check out this nasty logic: // GetObjectNames returns the list of all objects in the given
// database and schema.
// TODO(solon): when separate schemas are supported, this
// API should be extended to use schema descriptors.
//
// TODO(ajwerner,rohany): This API is utilized to support glob patterns that
// are fundamentally sometimes ambiguous (see GRANT and the ambiguity between
// tables and types). Furthermore, the fact that this buffers everything
// in ram in unfortunate.
GetObjectNames(
ctx context.Context, txn *kv.Txn, codec keys.SQLCodec,
db sqlbase.DatabaseDescriptorInterface,
scName string, flags tree.DatabaseListFlags,
) (tree.TableNames, error) Lines 285 to 289 in 4912bee
Public schemas contain default
|
cc @thtruo |
With the new ALTER DEFAULT PRIVILEGES work (#66785) that is arriving in v21.2, I think we are in a better place. A few remaining items remain that we will be finishing up in the near-term:
And there are a few smaller items that we aren't getting to in the near-term, but are tracked:
Given the state of all the above, I'll go ahead and close this issue in favor of the smaller remaining open issues. If I have missed something that warrants keeping this open, please don't hesitate to re-open it and comment. |
Our database-level permissions don't work in quite the same way as in either postgres or mysql, and this can be confusing. (This applies to the DDL permissions SELECT/INSERT/UPDATE/DELETE; the CREATE and DROP permissions work as expected)
In CockroachDB, database-level permissions are copied to new tables when they are created, but subsequent changes to the database permissions are not reflected on existing tables. To change permissions on all current and future tables, two commands are required:
In MySQL, database-level permissions are not copied to newly-created tables. Instead, permission checks use the union of database-level and table-level permissions at runtime, so changes to the database permissions affect all tables. Admins can choose to use database-level permissions exclusively and never touch table-level permissions.
In PostgreSQL, the DDL permissions are not allowed at the database level (i.e. you can't say anything equivalent to
GRANT SELECT ON DATABASE d TO u
). Instead, there is a separateALTER DEFAULT PRIVILEGES
command (which works the same as in CockroachDB, by copying the grants to new tables but changes do not affect existing ones):CockroachDB uses the same syntax as mysql, but the semantics of postgres. I think we should change to match one or the other: either introduce the postgres-style ALTER DEFAULT PRIVILEGES syntax and deprecate GRANT ON DATABASE, or keep the current syntax and change to mysql-style semantics.
CC @cockroachdb/sql-language @mberhault
Epic CRDB-2586
The text was updated successfully, but these errors were encountered: