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

db_datawriter should have update privilege on sequences #3210

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
8 changes: 7 additions & 1 deletion contrib/babelfishpg_tsql/src/dbcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1403,17 +1403,19 @@ grant_perms_to_dbreader_dbwriter_ddladmin(const uint16 dbid,
initStringInfo(&query);
appendStringInfo(&query, "GRANT SELECT ON ALL TABLES IN SCHEMA dummy TO dummy; ");
appendStringInfo(&query, "GRANT INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA dummy TO dummy; ");
appendStringInfo(&query, "GRANT UPDATE ON ALL SEQUENCES IN SCHEMA dummy TO dummy; ");
appendStringInfo(&query, "GRANT TRUNCATE ON ALL TABLES IN SCHEMA dummy TO dummy; ");
appendStringInfo(&query, "GRANT CREATE ON SCHEMA dummy TO dummy ; ");

/* Grant ALTER DEFAULT PRIVILEGES on schema owner and dbo user. */
appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES FOR ROLE dummy, dummy IN SCHEMA dummy GRANT SELECT ON TABLES TO dummy; ");
appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES FOR ROLE dummy, dummy IN SCHEMA dummy GRANT INSERT, UPDATE, DELETE ON TABLES TO dummy; ");
appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES FOR ROLE dummy, dummy IN SCHEMA dummy GRANT UPDATE ON SEQUENCES TO dummy; ");
appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES FOR ROLE dummy, dummy IN SCHEMA dummy GRANT TRUNCATE ON TABLES TO dummy; ");

stmt_list = raw_parser(query.data, RAW_PARSE_DEFAULT);

Assert(list_length(stmt_list) == 7);
Assert(list_length(stmt_list) == 9);

ScanKeyInit(&key,
Anum_namespace_ext_dbid,
Expand Down Expand Up @@ -1444,6 +1446,8 @@ grant_perms_to_dbreader_dbwriter_ddladmin(const uint16 dbid,
stmts = parsetree_nth_stmt(stmt_list, i++);
update_GrantStmt(stmts, schema_name, NULL, db_datawriter, NULL);
stmts = parsetree_nth_stmt(stmt_list, i++);
update_GrantStmt(stmts, schema_name, NULL, db_datawriter, NULL);
stmts = parsetree_nth_stmt(stmt_list, i++);
update_GrantStmt(stmts, schema_name, NULL, db_ddladmin, NULL);
stmts = parsetree_nth_stmt(stmt_list, i++);
update_GrantStmt(stmts, schema_name, NULL, db_ddladmin, NULL);
Expand All @@ -1453,6 +1457,8 @@ grant_perms_to_dbreader_dbwriter_ddladmin(const uint16 dbid,
stmts = parsetree_nth_stmt(stmt_list, i++);
update_AlterDefaultPrivilegesStmt(stmts, schema_name, schema_owner, dbo_user, db_datawriter, NULL);
stmts = parsetree_nth_stmt(stmt_list, i++);
update_AlterDefaultPrivilegesStmt(stmts, schema_name, schema_owner, dbo_user, db_datawriter, NULL);
stmts = parsetree_nth_stmt(stmt_list, i++);
update_AlterDefaultPrivilegesStmt(stmts, schema_name, schema_owner, dbo_user, db_ddladmin, NULL);

/* Run all subcommands */
Expand Down
5 changes: 4 additions & 1 deletion contrib/babelfishpg_tsql/src/pltsql_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ exec_database_roles_subcmds(const char *schema)
char *schema_owner;
const char *dbname = get_current_pltsql_db_name();
List *stmt_list;
int expected_stmts = 4;
int expected_stmts = 5;
ListCell *parsetree_item;
Node *stmts;
int i=0;
Expand All @@ -2550,6 +2550,7 @@ exec_database_roles_subcmds(const char *schema)
appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES FOR ROLE dummy, dummy IN SCHEMA dummy GRANT SELECT ON TABLES TO dummy; ");
/* Grant privileges to db_datawriter */
appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES FOR ROLE dummy, dummy IN SCHEMA dummy GRANT INSERT, UPDATE, DELETE ON TABLES TO dummy; ");
appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES FOR ROLE dummy, dummy IN SCHEMA dummy GRANT UPDATE ON SEQUENCES TO dummy; ");
/* Grant privileges to db_ddladmin */
appendStringInfo(&query, "ALTER DEFAULT PRIVILEGES FOR ROLE dummy, dummy IN SCHEMA dummy GRANT TRUNCATE ON TABLES TO dummy; ");
appendStringInfo(&query, "GRANT CREATE ON SCHEMA dummy TO dummy ; ");
Expand All @@ -2564,6 +2565,8 @@ exec_database_roles_subcmds(const char *schema)
stmts = parsetree_nth_stmt(stmt_list, i++);
update_AlterDefaultPrivilegesStmt(stmts, schema, schema_owner, dbo_role, db_datareader, NULL);

stmts = parsetree_nth_stmt(stmt_list, i++);
update_AlterDefaultPrivilegesStmt(stmts, schema, schema_owner, dbo_role, db_datawriter, NULL);
stmts = parsetree_nth_stmt(stmt_list, i++);
update_AlterDefaultPrivilegesStmt(stmts, schema, schema_owner, dbo_role, db_datawriter, NULL);

Expand Down
27 changes: 27 additions & 0 deletions test/JDBC/expected/datareader_datawriter-vu-cleanup.out
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,33 @@ void
use db_roles_db1
go

drop sequence db_roles_schema_1.before_sq1;
go

drop sequence db_roles_schema_1.after_sq1;
go

drop sequence db_roles_schema_1.after_sq2;
go

drop sequence db_roles_schema_2.before_created_by_dbo_sq1;
go

drop sequence db_roles_schema_2.after_created_by_dbo_sq1;
go

drop sequence db_roles_schema_2.after_created_by_dbo_sq2;
go

drop sequence db_roles_schema_2.before_created_by_u2_sq1;
go

drop sequence db_roles_schema_2.after_created_by_u2_sq1;
go

drop sequence db_roles_schema_2.after_created_by_u2_sq2;
go

drop table db_roles_schema_1.before_t1;
go

Expand Down
9 changes: 9 additions & 0 deletions test/JDBC/expected/datareader_datawriter-vu-prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ go
create table db_roles_schema_1.before_t1(a int);
go

create sequence db_roles_schema_1.before_sq1 start with 1 increment by 1 ;
go

create view db_roles_schema_1.before_v1 as select 2;
go

create table db_roles_schema_2.before_created_by_dbo_t1(a int);
go

create sequence db_roles_schema_2.before_created_by_dbo_sq1 start with 1 increment by 1 ;
go

create view db_roles_schema_2.before_created_by_dbo_v1 as select 2;
go

Expand All @@ -46,6 +52,9 @@ go
create table db_roles_schema_2.before_created_by_u2_t1(a int);
go

create sequence db_roles_schema_2.before_created_by_u2_sq1 start with 1 increment by 1 ;
go

create view db_roles_schema_2.before_created_by_u2_v1 as select 2;
go

Expand Down
Loading
Loading