Skip to content

Commit

Permalink
ccl: drop privileges when dropping external connection
Browse files Browse the repository at this point in the history
Release justification: Bug fix to newly added feature

Release note: None
  • Loading branch information
RichardJCai committed Aug 29, 2022
1 parent 00aa1c4 commit ce92aac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ exec-sql
GRANT DROP ON EXTERNAL CONNECTION "drop-privileged" TO testuser;
----

# Verify that the privileges exist.
query-sql
SELECT * FROM system.privileges
----
root /externalconn/drop-privileged {ALL} {}
root /externalconn/drop-privileged-dup {ALL} {}
testuser /externalconn/drop-privileged {DROP} {}

exec-sql user=testuser
DROP EXTERNAL CONNECTION "drop-privileged"
----
Expand All @@ -79,6 +87,11 @@ exec-sql
DROP EXTERNAL CONNECTION 'drop-privileged-dup'
----

# Verify that the privileges are dropped.
query-sql
SELECT * FROM system.privileges
----

subtest end

subtest create-grants-all
Expand Down Expand Up @@ -116,6 +129,14 @@ exec-sql user=testuser
CREATE EXTERNAL CONNECTION 'not-root' AS 'userfile:///bar'
----

# Verify that the privileges exist.
query-sql
SELECT * FROM system.privileges
----
root /externalconn/root {ALL} {}
testuser /externalconn/not-root {ALL} {}
testuser /global/ {EXTERNALCONNECTION} {}

exec-sql user=testuser
BACKUP TABLE foo INTO 'external://not-root'
----
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql/drop_external_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ func (p *planner) dropExternalConnection(params runParams, n *tree.DropExternalC
return errors.Wrapf(err, "failed to delete external connection")
}

// We must also DELETE all rows from system.privileges that refer to
// external connection.
if _, err = params.extendedEvalCtx.ExecCfg.InternalExecutor.ExecEx(
params.ctx,
dropExternalConnectionOp,
params.p.Txn(),
sessiondata.InternalExecutorOverride{User: username.NodeUserName()},
`DELETE FROM system.privileges WHERE path = $1`, ecPrivilege.GetPath(),
); err != nil {
return errors.Wrapf(err, "failed to delete external connection")
}

return nil
}

Expand Down

0 comments on commit ce92aac

Please sign in to comment.