Check roles assigned to user - db2

In a DB2 database, I have created a few roles and granted a user to some roles like:
GRANT ROLE "Role1" TO USER "User1"
GRANT ROLE "Role2" TO USER "User1"
How do I check in SYSCAT or SYSIBMADM tables which user (User1) has access to which roles (Role1 , Role2)?

I would recommend to use SYSIBMADM.PRIVILEGES. AUTHIDTYPE would be R for role.
Or query SYSCAT.ROLEAUTH to retrieve only the role information, e.g., who granted which role to which user.

SELECT GRANTEE, ROLENAME, ROLEID FROM SYSIBM.SYSROLEAUTH
solved for me

Related

how to check current_user's roles and permission in postgresSQL

I have created a user in PostgreSQL.
then I have created a role
and granted the role to the user.
now I want to write row level policy for the current user with some role permission
sql:--
create user martin;
create role role_manager;
grant role_manager to martin;
CREATE POLICY student_rls_policy
student
FOR ALL
TO role_manager
USING (name = **?**);
Now I want to pass current_user role at?

Access denied when table is recreated in Redshift

I created a new user and gave read-only access to the user for all the schemas with:
alter default privileges grant select on tables to the user;
Initially, the user had access but when the table was recreated the access automatically declined.
Why is this happening?
How you are giving permission? Group level or User level.
Try below GRANT USAGE
For Group level
GRANT USAGE ON SCHEMA 'SCHEMA_NAMES' TO GROUP Group_name;
For User level
GRANT USAGE ON SCHEMA 'SCHEMA_NAMES' TO USER User_name;

After creating Role with password in PostgreSQL, by default I am able to access some of the tables without granting select permission?

Ex: I have tables Table_A, Table_B, Table_C
I have created Role(user) called Username
Create User username with password 'pwd'
Without granting select permission to username able to access some of the tables.
The tables (Table_A, Table_B, Table_C) which have created are in public schema, so without granting select permission we can able to access the tables.

Remove ability view/list all table from schema

Using a Amazon Redshift database. I have a schema called 'Public', and another schema called 'SchemaX'. I have created a user called 'User1'; and give him access to 'SchemaX'. I want to stop 'User1' from viewing or listing the available tables in my 'Public' schema. How does one go about doing this?
To disallow users from creating objects in the PUBLIC schema of a database, use the REVOKE command to remove that privilege.
REVOKE [ GRANT OPTION FOR ]
{ { SELECT | INSERT | UPDATE | DELETE | REFERENCES } [,...] | ALL [ PRIVILEGES ] }
ON { [ TABLE ] table_name [, ...] | ALL TABLES IN SCHEMA schema_name [, ...] }
FROM { username | GROUP group_name | PUBLIC } [, ...]
[ CASCADE | RESTRICT ]
SELECT
Revokes the privilege to select data from a table or a view using a SELECT statement.
INSERT
Revokes the privilege to load data into a table using an INSERT statement or a COPY statement.
UPDATE
Revokes the privilege to update a table column using an UPDATE statement.
DELETE
Revokes the privilege to delete a data row from a table.
REFERENCES
Revokes the privilege to create a foreign key constraint. You should revoke this privilege on both the referenced table and the referencing table.
ALL [ PRIVILEGES ]
Revokes all available privileges at once from the specified user or group. The PRIVILEGES keyword is optional.
ON [ TABLE ] table_name
Revokes the specified privileges on a table or a view. The TABLE keyword is optional.
ON ALL TABLES IN SCHEMA schema_name
Revokes the specified privileges on all tables in the referenced schema.
GROUP group_name
Revokes the privileges from the specified user group.
PUBLIC
Revokes the specified privileges from all users. PUBLIC represents a group that always includes all users. An individual user's privileges consist of the sum of privileges granted to PUBLIC, privileges granted to any groups that the user belongs to, and any privileges granted to the user individually.
CASCADE
If a user holds a privilege with grant option and has granted the privilege to other users, the privileges held by those other users are dependent privileges. If the privilege or the grant option held by the first user is being revoked and dependent privileges exist, those dependent privileges are also revoked if CASCADE is specified; otherwise, the revoke action fails.
For example, if user A has granted a privilege with grant option to user B, and user B has granted the privilege to user C, user A can revoke the grant option from user B and use the CASCADE option to in turn revoke the privilege from user C.
RESTRICT
Revokes only those privileges that the user directly granted. This behavior is the default.

How to maintain access restrictions in PostgreSQL?

I need to achieve the below goal in postgresql. There is a database "textdb" with 4 schema's that are public, ds, fin, viz.
We need to create a script that can be used to provide access to the role. So, I need to create 3 roles, one for analyst, another for data scientist, and last one for visualization people.
CREATE ROLE analyst WITH LOGIN;
CREATE ROLE ds WITH LOGIN;
CREATE ROLE vi WITH LOGIN;
The respective team members will be added to their respective roles so that we need not to get access to individual users. Analyst is required to get complete access of the database "testdb", ds role will have access to all the data in the schema "ds" and "fin" and vi role will have access to schema "viz".
Also, whenever new table/view/procedure/function is added, then automatically users should have the required access.
If you plan to grant those roles to users they don't need login I believe. This is exact difference between "USER that can connect" and "just ROLE"
for new relations grants use ALTER DEFAULT PRIVILEGES
to grant role to user just grant ds to user_mike; if you \du+ user_mike you will see roles granted in "Menber of" section