-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: allow non-admins to perform some RESTOREs
Release justification: Low risk, high reward change to existing functionality Release note (sql change): Non-admin users are now permitted to execute RESTORE statements as long as the restore does not depend on implicit credentials and the user has the appropriate privileges to create all of the resulting database objects. For database restores, this means the user must have the CREATEDB role privilege. For table restores, the user must have CREATE privileges on the parent database. Full cluster restores still require admin privileges.
- Loading branch information
1 parent
a5628ba
commit cffe8b0
Showing
6 changed files
with
217 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Test permissions checks for non-admin users running RESTORE. | ||
new-server name=s1 | ||
---- | ||
|
||
exec-sql | ||
CREATE DATABASE d; | ||
CREATE TABLE d.t (x INT); | ||
INSERT INTO d.t VALUES (1), (2), (3); | ||
---- | ||
|
||
exec-sql | ||
BACKUP TO 'nodelocal://0/test/' | ||
---- | ||
|
||
# Start a new cluster with the same IO dir. | ||
new-server name=s2 share-io-dir=s1 allow-implicit-access | ||
---- | ||
|
||
exec-sql server=s2 | ||
CREATE USER testuser | ||
---- | ||
|
||
# Restore into the new cluster. | ||
exec-sql server=s2 user=testuser | ||
RESTORE FROM 'nodelocal://0/test/' | ||
---- | ||
pq: only users with the admin role are allowed to restore full cluster backups | ||
|
||
exec-sql server=s2 user=testuser | ||
RESTORE DATABASE d FROM 'nodelocal://0/test/' | ||
---- | ||
pq: only users with the CREATEDB privilege can restore databases | ||
|
||
exec-sql server=s2 | ||
CREATE DATABASE d | ||
---- | ||
|
||
exec-sql server=s2 user=testuser | ||
RESTORE TABLE d.t FROM 'nodelocal://0/test/' | ||
---- | ||
pq: user testuser does not have CREATE privilege on database d | ||
|
||
exec-sql server=s2 | ||
GRANT CREATE ON DATABASE d TO testuser | ||
---- | ||
|
||
exec-sql server=s2 user=testuser | ||
RESTORE TABLE d.t FROM 'nodelocal://0/test/' | ||
---- | ||
|
||
query-sql server=s2 | ||
SELECT x FROM d.t ORDER BY x | ||
---- | ||
1 | ||
2 | ||
3 | ||
|
||
exec-sql server=s2 | ||
DROP DATABASE d | ||
---- | ||
|
||
exec-sql server=s2 | ||
ALTER USER testuser CREATEDB | ||
---- | ||
|
||
exec-sql server=s2 user=testuser | ||
RESTORE DATABASE d FROM 'nodelocal://0/test/' | ||
---- | ||
|
||
query-sql server=s2 | ||
SELECT x FROM d.t ORDER BY x | ||
---- | ||
1 | ||
2 | ||
3 | ||
|
||
# Test that implicit access is disallowed when the testing knob isn't set. | ||
new-server name=s3 share-io-dir=s1 | ||
---- | ||
|
||
exec-sql server=s3 | ||
CREATE USER testuser | ||
---- | ||
|
||
exec-sql server=s3 user=testuser | ||
RESTORE TABLE d.t FROM 'nodelocal://0/test/' | ||
---- | ||
pq: only users with the admin role are allowed to RESTORE from the specified nodelocal URI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters