Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ccl: drop privileges when dropping external connection #86823

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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