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

fix: ALTER xxx OWNER TO xxx should check the CREATE privilege on the schema #13593

Merged
merged 6 commits into from
Nov 23, 2023

Conversation

Rossil2012
Copy link
Contributor

@Rossil2012 Rossil2012 commented Nov 22, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Resolve #13509.

psql -h localhost -p 4566 -d dev -U root
create user test1;
create user test2;
psql -h localhost -p 4566 -d dev -U test1
create table t(id int);
alter table t owner to test2;
# ERROR:  QueryError
# Caused by:
#  Permission denied: Require new owner to have create privilege on the object
psql -h localhost -p 4566 -d dev -U root
grant create on schema public TO test2;
psql -h localhost -p 4566 -d dev -U test1
alter table t owner to test2;
# ALTER_TABLE

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@Rossil2012 Rossil2012 self-assigned this Nov 22, 2023
@github-actions github-actions bot added the type/fix Bug fix label Nov 22, 2023
@Rossil2012
Copy link
Contributor Author

It is weird that test1/test2 does not has create privilege on dev.public schema whereas they can create table on it :)

@yezizp2012
Copy link
Member

It is weird that test1/test2 does not has create privilege on dev.public schema whereas they can create table on it :)

Because public is writable for all users. 😄

if schema.name() != DEFAULT_SCHEMA_NAME {
self.check_privileges(&[ObjectCheckItem::new(
schema.owner(),
AclMode::Create,
Object::SchemaId(schema.id()),
)])?;
}

@Rossil2012
Copy link
Contributor Author

It is weird that test1/test2 does not has create privilege on dev.public schema whereas they can create table on it :)

Because public is writable for all users. 😄

if schema.name() != DEFAULT_SCHEMA_NAME {
self.check_privileges(&[ObjectCheckItem::new(
schema.owner(),
AclMode::Create,
Object::SchemaId(schema.id()),
)])?;
}

Is it designed for RW? I found in PG a user still needs create privilege to create a table in public schema.

Copy link

codecov bot commented Nov 23, 2023

Codecov Report

Attention: 87 lines in your changes are missing coverage. Please review.

Comparison is base (38a78d8) 68.06% compared to head (20340e6) 68.03%.
Report is 5 commits behind head on main.

Files Patch % Lines
src/frontend/src/handler/alter_owner.rs 0.00% 87 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13593      +/-   ##
==========================================
- Coverage   68.06%   68.03%   -0.03%     
==========================================
  Files        1516     1516              
  Lines      261570   261607      +37     
==========================================
- Hits       178049   177997      -52     
- Misses      83521    83610      +89     
Flag Coverage Δ
rust 68.03% <1.13%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@yezizp2012 yezizp2012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some e2e tests for it?
For example altering a table's owner which is under a non-public schema To see if it will be rejected. And altering again after granted CREATE privilege of the schema to see if it will success.

src/frontend/src/handler/alter_owner.rs Outdated Show resolved Hide resolved
src/frontend/src/handler/alter_owner.rs Outdated Show resolved Hide resolved
@yezizp2012
Copy link
Member

It is weird that test1/test2 does not has create privilege on dev.public schema whereas they can create table on it :)

Because public is writable for all users. 😄

if schema.name() != DEFAULT_SCHEMA_NAME {
self.check_privileges(&[ObjectCheckItem::new(
schema.owner(),
AclMode::Create,
Object::SchemaId(schema.id()),
)])?;
}

Is it designed for RW? I found in PG a user still needs create privilege to create a table in public schema.

I think that's because RW don't have role concept and PUBLIC role, so we simply allow all new created user to have CREATE privilege on it.

Copy link
Member

@yezizp2012 yezizp2012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM.

src/frontend/src/handler/alter_owner.rs Outdated Show resolved Hide resolved
@Rossil2012 Rossil2012 added this pull request to the merge queue Nov 23, 2023
Merged via the queue into main with commit 0c4f8c6 Nov 23, 2023
26 of 27 checks passed
@Rossil2012 Rossil2012 deleted the kanzhen/fix-alter-owner-create-privilege branch November 23, 2023 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: new owner should have CREATE privilege for ALTER OWNER TO syntax
2 participants