Skip to content

Commit

Permalink
Merge pull request cockroachdb#24393 from mberhault/backport2.0-24390
Browse files Browse the repository at this point in the history
backport-2.0: sql: fill in required privileges at Validate time.
  • Loading branch information
mberhault authored Apr 1, 2018
2 parents 1a47bd5 + 592e4c2 commit 1421bd1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 0 additions & 2 deletions pkg/sql/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ func getDescriptorByID(
return errors.Errorf("%q is not a database", desc.String())
}

database.Privileges.MaybeFixPrivileges(id)

if err := database.Validate(); err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/grant_revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func (p *planner) changePrivileges(
changePrivilege(privileges, string(grantee))
}

// Validate privilege descriptors directly as the db/table level Validate
// may fix up the descriptor.
if err := privileges.Validate(descriptor.GetID()); err != nil {
return nil, err
}

switch d := descriptor.(type) {
case *sqlbase.DatabaseDescriptor:
if err := d.Validate(); err != nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/sqlbase/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,11 @@ func (desc *TableDescriptor) ValidateTable(st *cluster.Settings) error {
}
}

// Fill in any incorrect privileges that may have been missed due to mixed-versions.
// TODO(mberhault): remove this in 2.1 (maybe 2.2) when privilege-fixing migrations have been
// run again and mixed-version clusters always write "good" descriptors.
desc.Privileges.MaybeFixPrivileges(desc.GetID())

// Validate the privilege descriptor.
return desc.Privileges.Validate(desc.GetID())
}
Expand Down Expand Up @@ -2404,6 +2409,12 @@ func (desc *DatabaseDescriptor) Validate() error {
if desc.ID == 0 {
return fmt.Errorf("invalid database ID %d", desc.ID)
}

// Fill in any incorrect privileges that may have been missed due to mixed-versions.
// TODO(mberhault): remove this in 2.1 (maybe 2.2) when privilege-fixing migrations have been
// run again and mixed-version clusters always write "good" descriptors.
desc.Privileges.MaybeFixPrivileges(desc.GetID())

// Validate the privilege descriptor.
return desc.Privileges.Validate(desc.GetID())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlmigrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ var backwardCompatibleMigrations = []migrationDescriptor{
},
{
// Introduced in v2.0.
// TODO(benesch): bake this migration into v2.1, but create a new migration
// TODO(mberhault): bake this migration into v2.1, but create a new migration
// with the same function to catch any tables written in a mixed-version setting.
name: "ensure admin role privileges in all descriptors",
workFn: ensureMaxPrivileges,
Expand Down

0 comments on commit 1421bd1

Please sign in to comment.