Skip to content

Commit

Permalink
catprivilege: remove special cases for cluster restore
Browse files Browse the repository at this point in the history
Release note: none.
  • Loading branch information
dt committed Aug 11, 2022
1 parent 71d277b commit b008287
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 37 deletions.
1 change: 0 additions & 1 deletion pkg/ccl/backupccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ go_test(
"//pkg/sql/catalog",
"//pkg/sql/catalog/bootstrap",
"//pkg/sql/catalog/catalogkeys",
"//pkg/sql/catalog/catprivilege",
"//pkg/sql/catalog/descpb",
"//pkg/sql/catalog/descs",
"//pkg/sql/catalog/desctestutils",
Expand Down
4 changes: 1 addition & 3 deletions pkg/ccl/backupccl/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/systemschema"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
"github.com/cockroachdb/cockroach/pkg/testutils"
Expand Down Expand Up @@ -663,8 +662,7 @@ func TestDataDriven(t *testing.T) {
}
mut := dummyTable.NewBuilder().BuildCreatedMutable().(*tabledesc.Mutable)
mut.ID = id
mut.Name = fmt.Sprintf("%s_%d",
catprivilege.RestoreCopySystemTablePrefix, id)
mut.Name = fmt.Sprintf("%s_%d", "crdb_internal_copy", id)
tKey := catalogkeys.EncodeNameKey(codec, mut)
b := txn.NewBatch()
b.CPut(tKey, mut.GetID(), nil)
Expand Down
12 changes: 0 additions & 12 deletions pkg/sql/catalog/catprivilege/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
package catprivilege

import (
"strings"

"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/security/username"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
Expand Down Expand Up @@ -88,15 +85,6 @@ func MaybeFixPrivileges(
if systemPrivs != nil {
// System databases and tables have custom maximum allowed privileges.
allowedPrivilegesBits = systemPrivs.ToBitField()
} else if parentID == keys.SystemDatabaseID && strings.Contains(objectName, RestoreCopySystemTablePrefix) {
// Cluster restores move certain system tables to a higher ID to prevent
// conflicts with non-system descriptors that are going to be restored. The
// newly created tables in the system database must be given ReadWrite
// privileges to satisfy descriptor validation.
//
// TODO(adityamaru,dt): Remove once we fix the handling of dynamic system
// table IDs during restore.
allowedPrivilegesBits = privilege.ReadWriteData.ToBitField()
}

changed := false
Expand Down
9 changes: 1 addition & 8 deletions pkg/sql/catalog/catprivilege/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,7 @@ var (
catconstants.SystemExternalConnectionsTableName,
}

// RestoreCopySystemTablePrefix is the prefix of the table name that we give
// to the copy of the system table we are moving to a higher ID during
// restore.
//
// TODO(adityamaru,dt): Remove once we fix the handling of dynamic system
// table IDs during restore.
RestoreCopySystemTablePrefix = "crdb_internal_copy"
readWriteSystemSequences = []catconstants.SystemTableName{
readWriteSystemSequences = []catconstants.SystemTableName{
catconstants.RoleIDSequenceName,
}

Expand Down
13 changes: 0 additions & 13 deletions pkg/sql/catalog/catprivilege/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ package catprivilege

import (
"reflect"
"strings"

"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
Expand Down Expand Up @@ -56,17 +54,6 @@ func allowedSuperuserPrivileges(objectNameKey catalog.NameKey) privilege.List {
if privs != nil {
return privs
}
// Cluster restores move certain system tables to a higher ID to prevent
// conflicts with non-system descriptors that are going to be restored. The
// newly created tables in the system database will be given ReadWrite
// privileges.
//
// TODO(adityamaru,dt): Remove once we fix the handling of dynamic system
// table IDs during restore.
if objectNameKey.GetParentID() == keys.SystemDatabaseID &&
strings.Contains(objectNameKey.GetName(), RestoreCopySystemTablePrefix) {
return privilege.ReadWriteData
}
return catpb.DefaultSuperuserPrivileges
}

Expand Down

0 comments on commit b008287

Please sign in to comment.