Skip to content

Commit

Permalink
Merge pull request #92083 from rafiss/backport22.1-92075
Browse files Browse the repository at this point in the history
fixes #89764
  • Loading branch information
rafiss authored Nov 18, 2022
2 parents be3cd3e + 719e6e8 commit 2f305b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/sql/alter_default_privileges.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"context"

"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege"
Expand Down Expand Up @@ -60,6 +61,9 @@ func (p *planner) alterDefaultPrivileges(
if err != nil {
return nil, err
}
if dbDesc.GetID() == keys.SystemDatabaseID {
return nil, pgerror.Newf(pgcode.InvalidParameterValue, "cannot alter system database")
}

objectType := n.Grant.Target
if !n.IsGrant {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ ALTER DEFAULT PRIVILEGES FOR ROLE testuser GRANT SELECT ON TABLES to testuser, w
statement error pq: invalid privilege type USAGE for table
ALTER DEFAULT PRIVILEGES GRANT USAGE ON TABLES to testuser

# Should not be able to alter system database.
statement ok
USE system

statement error cannot alter system database
ALTER DEFAULT PRIVILEGES FOR ROLE testuser REVOKE ALL ON TABLES FROM testuser

statement ok
RESET database

# For Tables.
statement ok
CREATE DATABASE d;
Expand Down

0 comments on commit 2f305b3

Please sign in to comment.