暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第4天 |学习openGauss创建角色、修改角色属性、更改角色权限和删除角色-学习笔记

原创 cxb 2021-12-04
409

课程学习
角色是用来管理权限的,从数据库安全的角度考虑,可以把所有的管理和操作权限划分到不同的角色上
连接openGauss
root@modb:~# su - omm
omm@modb:~$ gsql -r
gsql ((openGauss 2.0.0 build 78689da9) compiled at 2021-03-31 21:03:52 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

omm=#
1.创建角色
–列出所有数据库角色
\du
–创建角色manager1,密码test_123
omm=# CREATE ROLE manager1 IDENTIFIED BY 'test_123';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
–创建角色manager2,密码test_456,具有LOGIN属性且为系统管理员
omm=# CREATE ROLE manager2 LOGIN SYSADMIN IDENTIFIED BY 'test_456';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE

–创建角色manager3,密码test_789,从2021年12月10日生效,2021年12月30日失效
omm=# CREATE ROLE manager3 WITH LOGIN PASSWORD 'test_789' VALID BEGIN '2021-12-10' VALID
omm-# UNTIL '2021-12-30';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.

–再次查看所有数据库角色
omm=# \du+
List of roles
Role name | Attributes
| Member of | Description
-----------+-------------------------------------------------------------------------------------------------------
-----------+-----------+-------------
gaussdb | Sysadmin
| {} |
manager1 | Cannot login
| {} |
manager2 | Sysadmin
| {} |
manager3 | Role valid begin 2021-12-10 00:00:00+08
+| {} |
| Role valid until 2021-12-30 00:00:00+08
| |
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyad
min, UseFT | {} |


2.修改角色属性
–修改角色manage1具有LOGIN属性且为系统管理员
omm=# ALTER ROLE manager1 SYSADMIN LOGIN;
ALTER ROLE
–查看manager1
omm=# \du+ manager1
List of roles
Role name | Attributes | Member of | Description
-----------+------------+-----------+-------------
manager1 | Sysadmin | {} |
–修改角色manager2密码
omm=# ALTER ROLE manager2 IDENTIFIED BY 'abcd@123' replace 'test_456';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
ALTER ROLE
–重命名manager2
omm=# ALTER ROLE manager2 RENAME TO manager20;
NOTICE: MD5 password cleared because of role rename
ALTER ROLE
3.授权
–将omm的权限授权给manager1
omm=# GRANT omm to manager1 with admin option;
GRANT ROLE
4.回收权限
omm=# revoke all privilege from manager1;
ALTER ROLE
5.删除角色
omm=# drop role manager1;
DROP ROLE
omm=# drop role manager20;
DROP ROLE
omm=# drop role manager3;
DROP ROLE

课后作业
1.创建角色role1为系统管理员, role2指定生效日期, role3具有LOGIN属性
create role role1 identified by 'test_role1' sysadmin ;
create role role2 identified by 'test_role2' VALID BEGIN '2021-12-10' VALID UNTIL '2021-12-30';
create role role3 with login password 'test_role3';
omm=# create role role1 identified by 'test_role1' sysadmin ;
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# create role role2 identified by 'test_role2' VALID BEGIN '2021-12-10' VALID UNTIL '2021-12-30';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# create role role3 with login password 'test_role3';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
2.重命名role1
alter role role1 rename to role11;
omm=# alter role role1 rename to role11;
NOTICE: MD5 password cleared because of role rename
ALTER ROLE
3.修改role2密码
alter role role2 identified by 'abcd@123' replace 'test_role2';
omm=# alter role role2 identified by 'abcd@123' replace 'test_role2';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
ALTER ROLE
4.将omm权限授权给role3,再回收role3的权限
grant omm to role3 with admin option;
revoke all privileges from role3;
omm=# grant omm to role3 with admin option;
GRANT ROLE
omm=# revoke all privileges from role3;
ALTER ROLE
5.删除所有创建角色
drop role role11;
drop role role2;
drop role role3;
omm=# drop role role11;
DROP ROLE
omm=# drop role role2;
DROP ROLE
omm=# drop role role3;
omm=# DROP ROLE
过程中使用\du或\du+查看角色信息
\du
\du+
omm=# \du
List of roles
Role name | Attributes
| Member of
-----------+-------------------------------------------------------------------------------------------------------
-----------+-----------
gaussdb | Sysadmin
| {}
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyad
min, UseFT | {}

omm=# \du+
List of roles
Role name | Attributes
| Member of | Description
-----------+-------------------------------------------------------------------------------------------------------
-----------+-----------+-------------
gaussdb | Sysadmin
| {} |
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyad
min, UseFT | {} |

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论