sql: database grants don't get properly propagated to new users
Evidently, database-level grants aren't propagated to new users under certain circumstances.
[15:45]% cockroach sql --insecure jordan@Termato:~
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
#
# Client version: CockroachDB CCL v1.2-alpha.20170901-2084-ge457f9a19 (darwin amd64, built 2017/11/30 14:50:40, go1.9.1)
# Server version: CockroachDB CCL v1.2-alpha.20171211-123-g6172ba8d6 (darwin amd64, built 2017/12/11 22:32:52, go1.9.1)
# Cluster ID: b6057ca9-c5ef-47f4-800c-60ebc3749eff
#
# Enter \? for a brief introduction.
#
root@:26257/> create database xxx;
CREATE DATABASE
root@:26257/> use xxx;
SET
root@:26257/xxx> create table a (a int);
CREATE TABLE
root@:26257/xxx> create user xxxuser;
CREATE USER 1
root@:26257/xxx> grant all on database xxx to xxxuser;
GRANT
root@:26257/xxx> create table b (a int);
CREATE TABLE
root@:26257/xxx> ^D
[15:46]% cockroach sql --insecure -u xxxuser;
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
#
# Client version: CockroachDB CCL v1.2-alpha.20170901-2084-ge457f9a19 (darwin amd64, built 2017/11/30 14:50:40, go1.9.1)
# Server version: CockroachDB CCL v1.2-alpha.20171211-123-g6172ba8d6 (darwin amd64, built 2017/12/11 22:32:52, go1.9.1)
# Cluster ID: b6057ca9-c5ef-47f4-800c-60ebc3749eff
#
# Enter \? for a brief introduction.
#
xxxuser@:26257/> use xxx;
SET
xxxuser@:26257/xxx> show tables;
+-------+
| Table |
+-------+
| b |
+-------+
(1 row)
I expect the above show tables to include table a.
xxxuser has no privileges on table a so it doesn't get to see it. Privileges are inherited at creation time only, they are not updated.
A reasonable behavior change would be to allow users with permissions on the database to see its tables, but that's debatable.
Oh yeah, removing "bug" label
Vivek for triage, this is a behavior change, not a bug fix.
I do like the change in behavior but I think we should fix this when we move the privileges outside of the table descriptor through https://github.com/cockroachdb/cockroach/issues/2939
Thoughts?
It can easily be done right now. show_table.go just does checks for p.CheckAnyPrivilege(table_desc). It could simply be p.CheckAnyPrivilege(parentDB_desc) || p.CheckAnyPrivilege(table_desc).
I'm not sure what the point would be though, the user still won't have privileges to do anything to the table, and that I don't think we should change.
isn't that the non intuitive part, that the user doesn't have privileges to do anything to the table?
Perhaps, but it can be just as disturbing to grant SELECT on the database when X tables exist and suddenly: blam! you can read all the tables. That's kind of a security nightmare.
and in reverse, taking away SELECT privileges on the database doesn't take away those privileges from the tables.
I think the privileges as defined are the "current" privileges on the database and should be applied to all the "current" tables associated with the database independent of when they were created. That's why I feel that we ought to do this when we move the privileges to a system table.
Hey, this issue is causing some confusion.
We should rethink this, granting priveleges to a user on the database level should propagate to tables created before as well.
Rich has opened a docs issue to document the behavior more clearly and how to work around it.
See https://github.com/cockroachdb/docs/issues/5083
Another user reported running into this same issue recently on this issue.
We should rethink this, granting priveleges to a user on the database level should propagate to tables created before as well.
No, this is not how we or postgres work. Sure our privilege model is a bit off but we should move towards postgres. The (current) syntax to grant to everything in a database is GRANT ALL ON <db>.* TO <user>. The syntax to ensure that the user gets privileges on new entities is GRANT ALL ON <db> TO <user>. I'm closing this. See #16790 for the root of the problems.
👍