-
Notifications
You must be signed in to change notification settings - Fork 97
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
Adding support to sys.server_role_members #1722
Merged
shardgupta
merged 13 commits into
babelfish-for-postgresql:BABEL_3_X_DEV
from
amazon-aurora:JIRA-BABEL-2532
Oct 26, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8f1cf79
Adding support to sys.server_role_members
01ae42c
Merge branch 'BABEL_3_X_DEV' into JIRA-BABEL-2532
anju15bharti c87c73a
made view for JDBC testcase
332535d
Adding procedure and function in JDBC testcases
534b254
Merge branch 'BABEL_3_X_DEV' into JIRA-BABEL-2532
bfa43df
updated expected_dependency file
440946a
Merge branch 'BABEL_3_X_DEV' into JIRA-BABEL-2532
80ecf91
Added more testcases
73f3810
reset login password in testfile
c85826f
Merge branch 'BABEL_3_X_DEV' into JIRA-BABEL-2532
99e8333
Merge branch 'BABEL_3_X_DEV' into JIRA-BABEL-2532
anju15bharti 992547e
Merge branch 'BABEL_3_X_DEV' into JIRA-BABEL-2532
daed721
updated expected file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
DROP LOGIN sys_server_role_members_vu_prepare_login1; | ||
GO | ||
|
||
DROP LOGIN sys_server_role_members_vu_prepare_login2; | ||
GO | ||
|
||
DROP LOGIN sys_server_role_members_vu_prepare_login3; | ||
GO | ||
|
||
DROP LOGIN sys_server_role_members_vu_prepare_login4; | ||
GO | ||
|
||
DROP VIEW sys_server_role_members_vu_prepare_view; | ||
GO | ||
|
||
DROP FUNCTION sys_server_role_members_vu_prepare_func; | ||
GO | ||
|
||
DROP PROCEDURE sys_server_role_members_vu_prepare_proc; | ||
GO | ||
|
||
DROP USER sys_server_role_members_vu_prepare_without_sa; | ||
GO | ||
|
||
DROP LOGIN sys_server_role_members_vu_prepare_without_sa; | ||
GO |
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,58 @@ | ||
-- tsql | ||
CREATE LOGIN sys_server_role_members_vu_prepare_login1 WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE LOGIN sys_server_role_members_vu_prepare_login2 WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE LOGIN sys_server_role_members_vu_prepare_login3 WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE LOGIN sys_server_role_members_vu_prepare_login4 WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE LOGIN sys_server_role_members_vu_prepare_without_sa WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE USER sys_server_role_members_vu_prepare_without_sa for login sys_server_role_members_vu_prepare_without_sa; | ||
GO | ||
|
||
CREATE VIEW sys_server_role_members_vu_prepare_view AS | ||
SELECT | ||
roles.name AS RolePrincipalName | ||
, members.name AS MemberPrincipalName | ||
FROM sys.server_role_members AS server_role_members | ||
INNER JOIN sys.server_principals AS roles | ||
ON server_role_members.role_principal_id = roles.principal_id | ||
INNER JOIN sys.server_principals AS members | ||
ON server_role_members.member_principal_id = members.principal_id order by MemberPrincipalName; | ||
GO | ||
|
||
CREATE FUNCTION sys_server_role_members_vu_prepare_func () | ||
RETURNS TABLE | ||
AS | ||
RETURN ( | ||
SELECT | ||
roles.name AS RolePrincipalName | ||
, members.name AS MemberPrincipalName | ||
FROM sys.server_role_members AS server_role_members | ||
INNER JOIN sys.server_principals AS roles | ||
ON server_role_members.role_principal_id = roles.principal_id | ||
INNER JOIN sys.server_principals AS members | ||
ON server_role_members.member_principal_id = members.principal_id order by MemberPrincipalName | ||
); | ||
GO | ||
|
||
CREATE PROCEDURE sys_server_role_members_vu_prepare_proc | ||
AS | ||
BEGIN | ||
SELECT | ||
roles.name AS RolePrincipalName | ||
, members.name AS MemberPrincipalName | ||
FROM sys.server_role_members AS server_role_members | ||
INNER JOIN sys.server_principals AS roles | ||
ON server_role_members.role_principal_id = roles.principal_id | ||
INNER JOIN sys.server_principals AS members | ||
ON server_role_members.member_principal_id = members.principal_id order by MemberPrincipalName; | ||
END; | ||
GO |
146 changes: 146 additions & 0 deletions
146
test/JDBC/expected/sys_server_role_members-vu-verify.out
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,146 @@ | ||
-- tsql | ||
SELECT * from sys_server_role_members_vu_prepare_view; | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
~~END~~ | ||
|
||
|
||
ALTER SERVER ROLE sysadmin ADD MEMBER sys_server_role_members_vu_prepare_login1; | ||
GO | ||
|
||
ALTER SERVER ROLE sysadmin ADD MEMBER sys_server_role_members_vu_prepare_login2; | ||
GO | ||
|
||
SELECT * from sys_server_role_members_vu_prepare_view; | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
sysadmin#!#sys_server_role_members_vu_prepare_login1 | ||
sysadmin#!#sys_server_role_members_vu_prepare_login2 | ||
~~END~~ | ||
|
||
|
||
ALTER SERVER ROLE sysadmin ADD MEMBER sys_server_role_members_vu_prepare_login3; | ||
GO | ||
|
||
SELECT * from sys_server_role_members_vu_prepare_view; | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
sysadmin#!#sys_server_role_members_vu_prepare_login1 | ||
sysadmin#!#sys_server_role_members_vu_prepare_login2 | ||
sysadmin#!#sys_server_role_members_vu_prepare_login3 | ||
~~END~~ | ||
|
||
|
||
--granting access to user | ||
GRANT SELECT ON sys_server_role_members_vu_prepare_view TO sys_server_role_members_vu_prepare_without_sa; | ||
GO | ||
|
||
GRANT EXECUTE ON sys_server_role_members_vu_prepare_proc TO sys_server_role_members_vu_prepare_without_sa; | ||
GO | ||
|
||
GRANT EXECUTE ON sys_server_role_members_vu_prepare_func TO sys_server_role_members_vu_prepare_without_sa; | ||
GO | ||
|
||
-- reset the login password | ||
ALTER LOGIN sys_server_role_members_vu_prepare_without_sa WITH PASSWORD = '123'; | ||
GO | ||
|
||
-- tsql user=sys_server_role_members_vu_prepare_without_sa password=123 | ||
|
||
SELECT * FROM sys_server_role_members_vu_prepare_view; | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
~~END~~ | ||
|
||
|
||
EXEC sys_server_role_members_vu_prepare_proc | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
~~END~~ | ||
|
||
|
||
SELECT * FROM sys_server_role_members_vu_prepare_func(); | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
~~END~~ | ||
|
||
|
||
-- psql | ||
ALTER USER sys_server_role_members_vu_prepare_login1 PASSWORD '123'; | ||
GO | ||
|
||
-- tsql user=sys_server_role_members_vu_prepare_login1 password=123 | ||
SELECT * from sys_server_role_members_vu_prepare_view; | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
sysadmin#!#sys_server_role_members_vu_prepare_login1 | ||
sysadmin#!#sys_server_role_members_vu_prepare_login2 | ||
sysadmin#!#sys_server_role_members_vu_prepare_login3 | ||
~~END~~ | ||
|
||
|
||
EXEC sys_server_role_members_vu_prepare_proc | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
sysadmin#!#sys_server_role_members_vu_prepare_login1 | ||
sysadmin#!#sys_server_role_members_vu_prepare_login2 | ||
sysadmin#!#sys_server_role_members_vu_prepare_login3 | ||
~~END~~ | ||
|
||
|
||
SELECT * FROM sys_server_role_members_vu_prepare_func(); | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
sysadmin#!#sys_server_role_members_vu_prepare_login1 | ||
sysadmin#!#sys_server_role_members_vu_prepare_login2 | ||
sysadmin#!#sys_server_role_members_vu_prepare_login3 | ||
~~END~~ | ||
|
||
|
||
-- tsql | ||
ALTER SERVER ROLE sysadmin DROP MEMBER sys_server_role_members_vu_prepare_login1; | ||
GO | ||
|
||
ALTER SERVER ROLE sysadmin DROP MEMBER sys_server_role_members_vu_prepare_login2; | ||
GO | ||
|
||
ALTER SERVER ROLE sysadmin DROP MEMBER sys_server_role_members_vu_prepare_login3; | ||
GO | ||
|
||
ALTER SERVER ROLE sysadmin DROP MEMBER sys_server_role_members_vu_prepare_login4; | ||
GO | ||
|
||
EXEC sys_server_role_members_vu_prepare_proc | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
~~END~~ | ||
|
||
|
||
SELECT * FROM sys_server_role_members_vu_prepare_func(); | ||
GO | ||
~~START~~ | ||
varchar#!#varchar | ||
sysadmin#!#jdbc_user | ||
~~END~~ | ||
|
||
|
26 changes: 26 additions & 0 deletions
26
test/JDBC/input/ownership/sys_server_role_members-vu-cleanup.mix
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,26 @@ | ||
DROP LOGIN sys_server_role_members_vu_prepare_login1; | ||
GO | ||
|
||
DROP LOGIN sys_server_role_members_vu_prepare_login2; | ||
GO | ||
|
||
DROP LOGIN sys_server_role_members_vu_prepare_login3; | ||
GO | ||
|
||
DROP LOGIN sys_server_role_members_vu_prepare_login4; | ||
GO | ||
|
||
DROP VIEW sys_server_role_members_vu_prepare_view; | ||
GO | ||
|
||
DROP FUNCTION sys_server_role_members_vu_prepare_func; | ||
GO | ||
|
||
DROP PROCEDURE sys_server_role_members_vu_prepare_proc; | ||
GO | ||
|
||
DROP USER sys_server_role_members_vu_prepare_without_sa; | ||
GO | ||
|
||
DROP LOGIN sys_server_role_members_vu_prepare_without_sa; | ||
GO |
58 changes: 58 additions & 0 deletions
58
test/JDBC/input/ownership/sys_server_role_members-vu-prepare.mix
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,58 @@ | ||
-- tsql | ||
CREATE LOGIN sys_server_role_members_vu_prepare_login1 WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE LOGIN sys_server_role_members_vu_prepare_login2 WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE LOGIN sys_server_role_members_vu_prepare_login3 WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE LOGIN sys_server_role_members_vu_prepare_login4 WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE LOGIN sys_server_role_members_vu_prepare_without_sa WITH PASSWORD = '123'; | ||
GO | ||
|
||
CREATE USER sys_server_role_members_vu_prepare_without_sa for login sys_server_role_members_vu_prepare_without_sa; | ||
GO | ||
|
||
CREATE VIEW sys_server_role_members_vu_prepare_view AS | ||
SELECT | ||
roles.name AS RolePrincipalName | ||
, members.name AS MemberPrincipalName | ||
FROM sys.server_role_members AS server_role_members | ||
INNER JOIN sys.server_principals AS roles | ||
ON server_role_members.role_principal_id = roles.principal_id | ||
INNER JOIN sys.server_principals AS members | ||
ON server_role_members.member_principal_id = members.principal_id order by MemberPrincipalName; | ||
GO | ||
|
||
CREATE FUNCTION sys_server_role_members_vu_prepare_func () | ||
RETURNS TABLE | ||
AS | ||
RETURN ( | ||
SELECT | ||
roles.name AS RolePrincipalName | ||
, members.name AS MemberPrincipalName | ||
FROM sys.server_role_members AS server_role_members | ||
INNER JOIN sys.server_principals AS roles | ||
ON server_role_members.role_principal_id = roles.principal_id | ||
INNER JOIN sys.server_principals AS members | ||
ON server_role_members.member_principal_id = members.principal_id order by MemberPrincipalName | ||
); | ||
GO | ||
|
||
CREATE PROCEDURE sys_server_role_members_vu_prepare_proc | ||
AS | ||
BEGIN | ||
SELECT | ||
roles.name AS RolePrincipalName | ||
, members.name AS MemberPrincipalName | ||
FROM sys.server_role_members AS server_role_members | ||
INNER JOIN sys.server_principals AS roles | ||
ON server_role_members.role_principal_id = roles.principal_id | ||
INNER JOIN sys.server_principals AS members | ||
ON server_role_members.member_principal_id = members.principal_id order by MemberPrincipalName; | ||
END; | ||
GO |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the permissions? Should all server membership should be visible by default? Please refer doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Babelfish, we only allow one server role
sysadmin
which is marked as "R" in the catalog.In SQL Server, the default server role
sysadmin
is visible to everyone. There is no behavioral difference.We don't support creating a new server role other that 'sysadmin' in Babelfish, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, In future when we support it at that time we may miss it. It will be better to add a condition to check that if it is fixed server role or showing membership's for current server principal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
Currently, we hardcode
is_fixed_role
to 0 always.I have suggested a change to Anju on how to update the
is_fixed_role
column inbabelfish_authid_login_ext
catalog which will be helpful for #1948 as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to update
sys.server_role_members
view once we supportcreate server role
syntax in Babelfish as tracked by https://jira.rds.a2z.com/browse/BABEL-113