Skip to content

Commit 755d9e8

Browse files
committed
sql: make inspect a system privilege
Previously the inspect privilege was tied to specific objects (tables and databases). For simplicity, it has been changed to a system privilege. This has no user impact as the commands associated with the privilege are as yet unimplemented. Epic: CRDB-30356 Part of: #148925 Release note: None
1 parent 76b08e5 commit 755d9e8

12 files changed

+13
-59
lines changed

pkg/sql/catalog/catpb/privilege_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func TestPrivilege(t *testing.T) {
8787
{Kind: privilege.CREATE},
8888
{Kind: privilege.DELETE},
8989
{Kind: privilege.DROP},
90-
{Kind: privilege.INSPECT},
9190
{Kind: privilege.REPLICATIONDEST},
9291
{Kind: privilege.REPLICATIONSOURCE},
9392
{Kind: privilege.TRIGGER},
@@ -616,7 +615,7 @@ func TestRevokeWithGrantOption(t *testing.T) {
616615
true,
617616
privilege.List{privilege.CREATE},
618617
privilege.List{privilege.ALL},
619-
privilege.List{privilege.BACKUP, privilege.CHANGEFEED, privilege.DELETE, privilege.DROP, privilege.INSERT, privilege.INSPECT, privilege.REPLICATIONDEST, privilege.REPLICATIONSOURCE, privilege.SELECT, privilege.TRIGGER, privilege.UPDATE, privilege.ZONECONFIG},
618+
privilege.List{privilege.BACKUP, privilege.CHANGEFEED, privilege.DELETE, privilege.DROP, privilege.INSERT, privilege.REPLICATIONDEST, privilege.REPLICATIONSOURCE, privilege.SELECT, privilege.TRIGGER, privilege.UPDATE, privilege.ZONECONFIG},
620619
false},
621620
{catpb.NewPrivilegeDescriptor(testUser, privilege.List{privilege.ALL}, privilege.List{privilege.ALL}, username.AdminRoleName()),
622621
testUser, privilege.Table,
@@ -650,8 +649,8 @@ func TestRevokeWithGrantOption(t *testing.T) {
650649
testUser, privilege.Table,
651650
false,
652651
privilege.List{privilege.CREATE},
653-
privilege.List{privilege.BACKUP, privilege.CHANGEFEED, privilege.DELETE, privilege.DROP, privilege.INSERT, privilege.INSPECT, privilege.REPLICATIONDEST, privilege.REPLICATIONSOURCE, privilege.SELECT, privilege.TRIGGER, privilege.UPDATE, privilege.ZONECONFIG},
654-
privilege.List{privilege.BACKUP, privilege.CHANGEFEED, privilege.DELETE, privilege.DROP, privilege.INSERT, privilege.INSPECT, privilege.REPLICATIONDEST, privilege.REPLICATIONSOURCE, privilege.SELECT, privilege.TRIGGER, privilege.UPDATE, privilege.ZONECONFIG},
652+
privilege.List{privilege.BACKUP, privilege.CHANGEFEED, privilege.DELETE, privilege.DROP, privilege.INSERT, privilege.REPLICATIONDEST, privilege.REPLICATIONSOURCE, privilege.SELECT, privilege.TRIGGER, privilege.UPDATE, privilege.ZONECONFIG},
653+
privilege.List{privilege.BACKUP, privilege.CHANGEFEED, privilege.DELETE, privilege.DROP, privilege.INSERT, privilege.REPLICATIONDEST, privilege.REPLICATIONSOURCE, privilege.SELECT, privilege.TRIGGER, privilege.UPDATE, privilege.ZONECONFIG},
655654
false},
656655
{catpb.NewPrivilegeDescriptor(testUser, privilege.List{privilege.SELECT, privilege.INSERT}, privilege.List{privilege.INSERT}, username.AdminRoleName()),
657656
testUser, privilege.Table,

pkg/sql/inspect_node.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package sql
88
import (
99
"context"
1010

11-
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
1211
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
1312
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
1413
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
@@ -22,30 +21,25 @@ type inspectNode struct {
2221
}
2322

2423
// Inspect checks the database.
25-
// Privileges: INSPECT on table or database.
24+
// Privileges: INSPECT.
2625
func (p *planner) Inspect(ctx context.Context, n *tree.Inspect) (planNode, error) {
27-
var desc catalog.Descriptor
2826
switch n.Typ {
2927
case tree.InspectTable:
3028
tableName := n.Table.ToTableName()
31-
_, tableDesc, err := p.ResolveMutableTableDescriptor(ctx, &tableName, true /* required */, tree.ResolveRequireTableDesc)
29+
_, _, err := p.ResolveMutableTableDescriptor(ctx, &tableName, true /* required */, tree.ResolveRequireTableDesc)
3230
if err != nil {
3331
return nil, err
3432
}
35-
36-
desc = tableDesc
3733
case tree.InspectDatabase:
38-
dbDesc, err := p.Descriptors().ByName(p.txn).Get().Database(ctx, n.Database.ToUnresolvedName().String())
34+
_, err := p.Descriptors().ByName(p.txn).Get().Database(ctx, n.Database.ToUnresolvedName().String())
3935
if err != nil {
4036
return nil, err
4137
}
42-
43-
desc = dbDesc
4438
default:
4539
return nil, errors.AssertionFailedf("unexpected INSPECT type received, got: %v", n.Typ)
4640
}
4741

48-
if err := p.CheckPrivilege(ctx, desc, privilege.INSPECT); err != nil {
42+
if err := p.CheckGlobalPrivilegeOrRoleOption(ctx, privilege.INSPECT); err != nil {
4943
return nil, err
5044
}
5145

pkg/sql/logictest/testdata/logic_test/alter_default_privileges_for_table

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ d public t8 testuser CREATE false
266266
d public t8 testuser DELETE false
267267
d public t8 testuser DROP false
268268
d public t8 testuser INSERT false
269-
d public t8 testuser INSPECT false
270269
d public t8 testuser REPLICATIONDEST false
271270
d public t8 testuser REPLICATIONSOURCE false
272271
d public t8 testuser TRIGGER false
@@ -278,7 +277,6 @@ d public t8 testuser2 CREATE false
278277
d public t8 testuser2 DELETE false
279278
d public t8 testuser2 DROP false
280279
d public t8 testuser2 INSERT false
281-
d public t8 testuser2 INSPECT false
282280
d public t8 testuser2 REPLICATIONDEST false
283281
d public t8 testuser2 REPLICATIONSOURCE false
284282
d public t8 testuser2 TRIGGER false

pkg/sql/logictest/testdata/logic_test/crdb_internal_default_privileges

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ test NULL root false tables bar ZONE
554554
test NULL root false tables bar TRIGGER false
555555
test NULL root false tables bar REPLICATIONDEST false
556556
test NULL root false tables bar REPLICATIONSOURCE false
557-
test NULL root false tables bar INSPECT false
558557
test NULL root false tables foo BACKUP false
559558
test NULL root false tables foo CHANGEFEED false
560559
test NULL root false tables foo CREATE false
@@ -566,7 +565,6 @@ test NULL root false tables foo ZONE
566565
test NULL root false tables foo TRIGGER false
567566
test NULL root false tables foo REPLICATIONDEST false
568567
test NULL root false tables foo REPLICATIONSOURCE false
569-
test NULL root false tables foo INSPECT false
570568
test NULL root false tables root ALL true
571569
test NULL root false sequences root ALL true
572570
test NULL root false types root ALL true

pkg/sql/logictest/testdata/logic_test/grant_database

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@ a readwrite BACKUP true
6161
a readwrite CHANGEFEED true
6262
a readwrite CREATE true
6363
a readwrite DROP true
64-
a readwrite INSPECT true
6564
a readwrite RESTORE true
6665
a readwrite ZONECONFIG true
6766
a root ALL true
6867
a test-user BACKUP true
6968
a test-user CHANGEFEED true
7069
a test-user CREATE true
7170
a test-user DROP true
72-
a test-user INSPECT true
7371
a test-user RESTORE true
7472
a test-user ZONECONFIG true
7573

@@ -81,14 +79,12 @@ a readwrite BACKUP true
8179
a readwrite CHANGEFEED true
8280
a readwrite CREATE true
8381
a readwrite DROP true
84-
a readwrite INSPECT true
8582
a readwrite RESTORE true
8683
a readwrite ZONECONFIG true
8784
a test-user BACKUP true
8885
a test-user CHANGEFEED true
8986
a test-user CREATE true
9087
a test-user DROP true
91-
a test-user INSPECT true
9288
a test-user RESTORE true
9389
a test-user ZONECONFIG true
9490

@@ -104,14 +100,12 @@ a readwrite BACKUP true
104100
a readwrite CHANGEFEED true
105101
a readwrite CREATE true
106102
a readwrite DROP true
107-
a readwrite INSPECT true
108103
a readwrite RESTORE true
109104
a readwrite ZONECONFIG true
110105
a root ALL true
111106
a test-user BACKUP true
112107
a test-user CHANGEFEED true
113108
a test-user DROP true
114-
a test-user INSPECT true
115109
a test-user RESTORE true
116110
a test-user ZONECONFIG true
117111

@@ -126,7 +120,6 @@ a readwrite BACKUP true
126120
a readwrite CHANGEFEED true
127121
a readwrite CREATE true
128122
a readwrite DROP true
129-
a readwrite INSPECT true
130123
a readwrite RESTORE true
131124
a readwrite ZONECONFIG true
132125

pkg/sql/logictest/testdata/logic_test/grant_on_all_tables_in_schema

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ test s t table testuser CREATE
7474
test s t table testuser DELETE false
7575
test s t table testuser DROP false
7676
test s t table testuser INSERT false
77-
test s t table testuser INSPECT false
7877
test s t table testuser REPLICATIONDEST false
7978
test s t table testuser REPLICATIONSOURCE false
8079
test s t table testuser TRIGGER false
@@ -86,7 +85,6 @@ test s t table testuser2 CREATE
8685
test s t table testuser2 DELETE false
8786
test s t table testuser2 DROP false
8887
test s t table testuser2 INSERT false
89-
test s t table testuser2 INSPECT false
9088
test s t table testuser2 REPLICATIONDEST false
9189
test s t table testuser2 REPLICATIONSOURCE false
9290
test s t table testuser2 TRIGGER false
@@ -98,7 +96,6 @@ test s2 t table testuser CREATE
9896
test s2 t table testuser DELETE false
9997
test s2 t table testuser DROP false
10098
test s2 t table testuser INSERT false
101-
test s2 t table testuser INSPECT false
10299
test s2 t table testuser REPLICATIONDEST false
103100
test s2 t table testuser REPLICATIONSOURCE false
104101
test s2 t table testuser TRIGGER false
@@ -110,7 +107,6 @@ test s2 t table testuser2 CREATE
110107
test s2 t table testuser2 DELETE false
111108
test s2 t table testuser2 DROP false
112109
test s2 t table testuser2 INSERT false
113-
test s2 t table testuser2 INSPECT false
114110
test s2 t table testuser2 REPLICATIONDEST false
115111
test s2 t table testuser2 REPLICATIONSOURCE false
116112
test s2 t table testuser2 TRIGGER false

pkg/sql/logictest/testdata/logic_test/grant_revoke_with_grant_option

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ test public t table testuser CHANGEFEED
307307
test public t table testuser CREATE true
308308
test public t table testuser DROP true
309309
test public t table testuser INSERT true
310-
test public t table testuser INSPECT true
311310
test public t table testuser REPLICATIONDEST true
312311
test public t table testuser REPLICATIONSOURCE true
313312
test public t table testuser SELECT true

pkg/sql/logictest/testdata/logic_test/grant_table

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,6 @@ a public t readwrite BACKUP false
16711671
a public t readwrite CHANGEFEED false
16721672
a public t readwrite CREATE false
16731673
a public t readwrite DROP false
1674-
a public t readwrite INSPECT false
16751674
a public t readwrite REPLICATIONDEST false
16761675
a public t readwrite REPLICATIONSOURCE false
16771676
a public t readwrite SELECT false
@@ -1683,7 +1682,6 @@ a public t test-user BACKUP false
16831682
a public t test-user CHANGEFEED false
16841683
a public t test-user CREATE false
16851684
a public t test-user DROP false
1686-
a public t test-user INSPECT false
16871685
a public t test-user REPLICATIONDEST false
16881686
a public t test-user REPLICATIONSOURCE false
16891687
a public t test-user SELECT false
@@ -1698,7 +1696,6 @@ a public t readwrite BACKUP false
16981696
a public t readwrite CHANGEFEED false
16991697
a public t readwrite CREATE false
17001698
a public t readwrite DROP false
1701-
a public t readwrite INSPECT false
17021699
a public t readwrite REPLICATIONDEST false
17031700
a public t readwrite REPLICATIONSOURCE false
17041701
a public t readwrite SELECT false
@@ -1709,7 +1706,6 @@ a public t test-user BACKUP false
17091706
a public t test-user CHANGEFEED false
17101707
a public t test-user CREATE false
17111708
a public t test-user DROP false
1712-
a public t test-user INSPECT false
17131709
a public t test-user REPLICATIONDEST false
17141710
a public t test-user REPLICATIONSOURCE false
17151711
a public t test-user SELECT false
@@ -1728,7 +1724,6 @@ a public t readwrite BACKUP false
17281724
a public t readwrite CHANGEFEED false
17291725
a public t readwrite CREATE false
17301726
a public t readwrite DROP false
1731-
a public t readwrite INSPECT false
17321727
a public t readwrite REPLICATIONDEST false
17331728
a public t readwrite REPLICATIONSOURCE false
17341729
a public t readwrite SELECT false
@@ -1740,7 +1735,6 @@ a public t test-user BACKUP false
17401735
a public t test-user CHANGEFEED false
17411736
a public t test-user CREATE false
17421737
a public t test-user DROP false
1743-
a public t test-user INSPECT false
17441738
a public t test-user REPLICATIONDEST false
17451739
a public t test-user REPLICATIONSOURCE false
17461740
a public t test-user TRIGGER false
@@ -1754,7 +1748,6 @@ a public t readwrite BACKUP false
17541748
a public t readwrite CHANGEFEED false
17551749
a public t readwrite CREATE false
17561750
a public t readwrite DROP false
1757-
a public t readwrite INSPECT false
17581751
a public t readwrite REPLICATIONDEST false
17591752
a public t readwrite REPLICATIONSOURCE false
17601753
a public t readwrite SELECT false
@@ -1765,7 +1758,6 @@ a public t test-user BACKUP false
17651758
a public t test-user CHANGEFEED false
17661759
a public t test-user CREATE false
17671760
a public t test-user DROP false
1768-
a public t test-user INSPECT false
17691761
a public t test-user REPLICATIONDEST false
17701762
a public t test-user REPLICATIONSOURCE false
17711763
a public t test-user TRIGGER false
@@ -1832,7 +1824,6 @@ a public v readwrite BACKUP false
18321824
a public v readwrite CHANGEFEED false
18331825
a public v readwrite CREATE false
18341826
a public v readwrite DROP false
1835-
a public v readwrite INSPECT false
18361827
a public v readwrite REPLICATIONDEST false
18371828
a public v readwrite REPLICATIONSOURCE false
18381829
a public v readwrite SELECT false
@@ -1844,7 +1835,6 @@ a public v test-user BACKUP false
18441835
a public v test-user CHANGEFEED false
18451836
a public v test-user CREATE false
18461837
a public v test-user DROP false
1847-
a public v test-user INSPECT false
18481838
a public v test-user REPLICATIONDEST false
18491839
a public v test-user REPLICATIONSOURCE false
18501840
a public v test-user SELECT false
@@ -1859,7 +1849,6 @@ a public v readwrite BACKUP false
18591849
a public v readwrite CHANGEFEED false
18601850
a public v readwrite CREATE false
18611851
a public v readwrite DROP false
1862-
a public v readwrite INSPECT false
18631852
a public v readwrite REPLICATIONDEST false
18641853
a public v readwrite REPLICATIONSOURCE false
18651854
a public v readwrite SELECT false
@@ -1870,7 +1859,6 @@ a public v test-user BACKUP false
18701859
a public v test-user CHANGEFEED false
18711860
a public v test-user CREATE false
18721861
a public v test-user DROP false
1873-
a public v test-user INSPECT false
18741862
a public v test-user REPLICATIONDEST false
18751863
a public v test-user REPLICATIONSOURCE false
18761864
a public v test-user SELECT false
@@ -1889,7 +1877,6 @@ a public v readwrite BACKUP false
18891877
a public v readwrite CHANGEFEED false
18901878
a public v readwrite CREATE false
18911879
a public v readwrite DROP false
1892-
a public v readwrite INSPECT false
18931880
a public v readwrite REPLICATIONDEST false
18941881
a public v readwrite REPLICATIONSOURCE false
18951882
a public v readwrite SELECT false
@@ -1901,7 +1888,6 @@ a public v test-user BACKUP false
19011888
a public v test-user CHANGEFEED false
19021889
a public v test-user CREATE false
19031890
a public v test-user DROP false
1904-
a public v test-user INSPECT false
19051891
a public v test-user REPLICATIONDEST false
19061892
a public v test-user REPLICATIONSOURCE false
19071893
a public v test-user TRIGGER false
@@ -1915,7 +1901,6 @@ a public v readwrite BACKUP false
19151901
a public v readwrite CHANGEFEED false
19161902
a public v readwrite CREATE false
19171903
a public v readwrite DROP false
1918-
a public v readwrite INSPECT false
19191904
a public v readwrite REPLICATIONDEST false
19201905
a public v readwrite REPLICATIONSOURCE false
19211906
a public v readwrite SELECT false
@@ -1926,7 +1911,6 @@ a public v test-user BACKUP false
19261911
a public v test-user CHANGEFEED false
19271912
a public v test-user CREATE false
19281913
a public v test-user DROP false
1929-
a public v test-user INSPECT false
19301914
a public v test-user REPLICATIONDEST false
19311915
a public v test-user REPLICATIONSOURCE false
19321916
a public v test-user TRIGGER false
@@ -1943,7 +1927,6 @@ a public v table readwrite BACKUP false
19431927
a public v table readwrite CHANGEFEED false
19441928
a public v table readwrite CREATE false
19451929
a public v table readwrite DROP false
1946-
a public v table readwrite INSPECT false
19471930
a public v table readwrite REPLICATIONDEST false
19481931
a public v table readwrite REPLICATIONSOURCE false
19491932
a public v table readwrite SELECT false
@@ -1954,7 +1937,6 @@ a public v table test-user BACKUP false
19541937
a public v table test-user CHANGEFEED false
19551938
a public v table test-user CREATE false
19561939
a public v table test-user DROP false
1957-
a public v table test-user INSPECT false
19581940
a public v table test-user REPLICATIONDEST false
19591941
a public v table test-user REPLICATIONSOURCE false
19601942
a public v table test-user TRIGGER false

0 commit comments

Comments
 (0)