Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
93930: catpb: use uint64 for privilege bitfield r=rafiss a=rafiss

fixes cockroachdb#91932

We are close to running out of bits, since we use a uint32 right now.
This commit buys us more time. If the privilege kinds don't keep
growing too much, then we should be safe for quite a while.

This causes functions that convert protos to json to use double quotes
for the privilege bitfield, since 64-bit integers must be handled as
strings in json.

Release note: None

Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
craig[bot] and rafiss committed Jan 11, 2023
2 parents dc273e0 + e59ef12 commit 0f6333c
Show file tree
Hide file tree
Showing 32 changed files with 619 additions and 637 deletions.
16 changes: 8 additions & 8 deletions pkg/ccl/logictestccl/testdata/logic_test/redact_descriptor
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ SELECT descriptor from redacted_descriptors where id = 'collate_partition'::REGC
"ownerProto": "root",
"users": [
{
"privileges": 2,
"privileges": "2",
"userProto": "admin",
"withGrantOption": 2
"withGrantOption": "2"
},
{
"privileges": 2,
"privileges": "2",
"userProto": "root",
"withGrantOption": 2
"withGrantOption": "2"
}
],
"version": 2
Expand Down Expand Up @@ -343,14 +343,14 @@ SELECT descriptor from redacted_descriptors where id = 'subpartition'::REGCLASS;
"ownerProto": "root",
"users": [
{
"privileges": 2,
"privileges": "2",
"userProto": "admin",
"withGrantOption": 2
"withGrantOption": "2"
},
{
"privileges": 2,
"privileges": "2",
"userProto": "root",
"withGrantOption": 2
"withGrantOption": "2"
}
],
"version": 2
Expand Down
24 changes: 12 additions & 12 deletions pkg/ccl/schemachangerccl/testdata/decomp/multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ ElementState:
Status: PUBLIC
- UserPrivileges:
descriptorId: 104
privileges: 2
privileges: "2"
userName: admin
Status: PUBLIC
- UserPrivileges:
descriptorId: 104
privileges: 2
privileges: "2"
userName: root
Status: PUBLIC
- UserPrivileges:
descriptorId: 104
privileges: 2048
privileges: "2048"
userName: public
Status: PUBLIC
- DatabaseRegionConfig:
Expand Down Expand Up @@ -311,12 +311,12 @@ ElementState:
Status: PUBLIC
- UserPrivileges:
descriptorId: 110
privileges: 2
privileges: "2"
userName: admin
Status: PUBLIC
- UserPrivileges:
descriptorId: 110
privileges: 2
privileges: "2"
userName: root
Status: PUBLIC
- ObjectParent:
Expand Down Expand Up @@ -573,12 +573,12 @@ ElementState:
Status: PUBLIC
- UserPrivileges:
descriptorId: 109
privileges: 2
privileges: "2"
userName: admin
Status: PUBLIC
- UserPrivileges:
descriptorId: 109
privileges: 2
privileges: "2"
userName: root
Status: PUBLIC
- ObjectParent:
Expand Down Expand Up @@ -940,12 +940,12 @@ ElementState:
Status: PUBLIC
- UserPrivileges:
descriptorId: 108
privileges: 2
privileges: "2"
userName: admin
Status: PUBLIC
- UserPrivileges:
descriptorId: 108
privileges: 2
privileges: "2"
userName: root
Status: PUBLIC
- ObjectParent:
Expand Down Expand Up @@ -977,17 +977,17 @@ ElementState:
Status: PUBLIC
- UserPrivileges:
descriptorId: 106
privileges: 2
privileges: "2"
userName: admin
Status: PUBLIC
- UserPrivileges:
descriptorId: 106
privileges: 2
privileges: "2"
userName: root
Status: PUBLIC
- UserPrivileges:
descriptorId: 106
privileges: 512
privileges: "512"
userName: public
Status: PUBLIC
- ObjectParent:
Expand Down
8 changes: 4 additions & 4 deletions pkg/ccl/schemachangerccl/testdata/decomp/partitioning
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ ElementState:
Status: PUBLIC
- UserPrivileges:
descriptorId: 104
privileges: 2
privileges: "2"
userName: admin
Status: PUBLIC
- UserPrivileges:
descriptorId: 104
privileges: 2
privileges: "2"
userName: root
Status: PUBLIC
- ObjectParent:
Expand Down Expand Up @@ -715,12 +715,12 @@ ElementState:
Status: PUBLIC
- UserPrivileges:
descriptorId: 105
privileges: 2
privileges: "2"
userName: admin
Status: PUBLIC
- UserPrivileges:
descriptorId: 105
privileges: 2
privileges: "2"
userName: root
Status: PUBLIC
- ObjectParent:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ add synthetic descriptor #105:
name: public
parentId: 104
...
withGrantOption: 2
withGrantOption: "2"
version: 2
+ state: DROP
version: "1"
Expand Down Expand Up @@ -69,7 +69,7 @@ add synthetic descriptor #107:
name: _crdb_internal_region
parentId: 104
...
withGrantOption: 2
withGrantOption: "2"
version: 2
+ state: DROP
version: "1"
Expand Down Expand Up @@ -139,7 +139,7 @@ upsert descriptor #105
id: 105
modificationTime: {}
...
withGrantOption: 2
withGrantOption: "2"
version: 2
- version: "1"
+ state: DROP
Expand Down Expand Up @@ -186,7 +186,7 @@ upsert descriptor #107
id: 107
kind: ALIAS
...
withGrantOption: 2
withGrantOption: "2"
version: 2
- version: "1"
+ state: DROP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ upsert descriptor #106
enumMembers:
- logicalRepresentation: us-east1
...
withGrantOption: 2
withGrantOption: "2"
version: 2
- referencingDescriptorIds:
- - 108
Expand All @@ -69,7 +69,7 @@ upsert descriptor #107
id: 107
kind: ALIAS
...
withGrantOption: 2
withGrantOption: "2"
version: 2
- referencingDescriptorIds:
- - 108
Expand Down Expand Up @@ -136,7 +136,7 @@ upsert descriptor #107
id: 107
kind: ALIAS
...
withGrantOption: 2
withGrantOption: "2"
version: 2
- version: "3"
+ version: "4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ upsert descriptor #106
enumMembers:
- logicalRepresentation: us-east1
...
withGrantOption: 2
withGrantOption: "2"
version: 2
- referencingDescriptorIds:
- - 108
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/catalog/catpb/privilege.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func (p PrivilegeDescriptor) Validate(
// privileges.
func (p PrivilegeDescriptor) IsValidPrivilegesForObjectType(
objectType privilege.ObjectType,
) (bool, UserPrivileges, uint32) {
) (bool, UserPrivileges, uint64) {
allowedPrivilegesBits := privilege.GetValidPrivilegesForObject(objectType).ToBitField()

// Validate can be called during the fix_privileges_migration introduced in
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/catalog/catpb/privilege.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ message UserPrivileges {
optional string user_proto = 1 [(gogoproto.nullable) = false,
(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/security/username.SQLUsernameProto"];
// privileges is a bitfield of 1<<Privilege values.
optional uint32 privileges = 2 [(gogoproto.nullable) = false];
optional uint32 with_grant_option = 3 [(gogoproto.nullable) = false];
optional uint64 privileges = 2 [(gogoproto.nullable) = false];
optional uint64 with_grant_option = 3 [(gogoproto.nullable) = false];
}

// PrivilegeDescriptor describes a list of users and attached
Expand Down
Loading

0 comments on commit 0f6333c

Please sign in to comment.