open Gauss 数据库-06 openGauss数据库安全指导手册5.0.0

发文章是为了证明自己真的掌握了一个知识,同时给他人带来帮助,如有问题,欢迎指正,祝大家万事胜意!

目录

前言

openGauss数据库安全指导

1 用户权限控制

1.1 实验介绍

1.1.1 关于本实验

1.1.2 实验目的

1.2 用户

1.2.1 创建、修改、删除用户

1.3 角色

1.3.1 创建、修改、删除角色

1.4 Schema

1.4.1 创建、修改、删除 Schema

1.5 用户权限设置及回收

1.5.1 将系统权限授权给用户或者角色

1.5.2 将数据库对象授权给角色或用户

1.5.4 权限回收

1.6 安全策略设置

1.6.1 设置账户安全策略

1.6.2 设置账号有效期

1.6.3 设置密码安全策略

2 审计

2.1 实验介绍

2.1.1 关于本实验

2.1.2 实验目的

2.2 审计开、关

2.3 查看审计结果

2.4 维护审计日志


前言

本实验主要内容为操作系统参数检查、 openGauss 健康状态检查、数据库性能检查、日志检查

和清理、时间一致性检查、应用连接数检查、例行维护表等

我的环境:

设备名称设备型号软件版本
虚拟机VMwareVMware-workstation-full-17.5.1
操作系统openEuler   openEuler 22.3LTS
数据库openGauss  openGauss 5.0.0

需要的工具,大家不用现在下,后面用到了再下也可以,如果需要相关文件,可以评论,其实大多数都是可以去官网下的哈,因为我只能通过网盘给大家,文件又有点大,网盘的速度大家都是清楚的哈哈,所以还是推荐大家去官网,如果实在找不到可以找我

openGauss数据库安全指导

1 用户权限控制

1.1 实验介绍

1.1.1 关于本实验
本实验主要描述用户的创建管理、角色的创建管理、 Schema 的创建管理、用户权限设置、用
户安全策略设置。
1.1.2 实验目的
掌握用户、角色、 Schema 的创建及管理;
掌握用户权限的授予各回收;
掌握用户安全策略如何设置。

1.2 用户

通过 CREATE USER 创建的用户,默认具有 LOGIN 权限;
通过 CREATE USER 创建用户的同时系统会在执行该命令的数据库中,为该用户创建一个同名
SCHEMA ;其他数据库中,则不自动创建同名的 SCHEMA ;用户可使用 CREATE SCHEMA
命令,分别在其他数据库中,为该用户创建同名 SCHEMA
1.2.1 创建、修改、删除用户
步骤 1 启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号为
15400
[omm@node0 ~]$ gsql -d postgres -p 26000 -r
failed to connect /opt/huawei/tmp:26000.
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 2 连接数据库后,进入 SQL 命令界面。创建用户 jim ,登录密码为 Bigdata@123
openGauss=# CREATE USER jim PASSWORD 'Bigdata@123';
CREATE ROLE
openGauss=# 
说明:密码规则如下:
密码默认不少于 8 个字符;
不能与用户名及用户名倒序相同;
至少包含大写字母( A-Z ),小写字母( a-z ),数字( 0-9 ),非字母数字字符(限定为
~!@#$%^&*()-_=+\|[{}];:,<.>/? )四类字符中的三类字符;
创建用户时,应当使用双引号或单引号将用户密码括起来。
步骤 3 查看用户列表。
openGauss=#  SELECT * FROM pg_user;
 usename | usesysid | usecreatedb | usesuper | usecatupd | userepl |  passwd  | valbegin | valuntil |   respool    | parent | spacelimit | useconfig | nodegroup | tempspacelimit | 
spillspacelimit | usemonitoradmin | useoperatoradmin | usepolicyadmin 
---------+----------+-------------+----------+-----------+---------+----------+----------+----------+--------------+--------+------------+-----------+-----------+----------------+-
----------------+-----------------+------------------+----------------
 omm     |       10 | t           | t        | t         | t       | ******** |          |          | default_pool |      0 |            |           |           |                | 
                | t               | t                | t
 lucy    |    49478 | f           | f        | f         | f       | ******** |          |          | default_pool |      0 |            |           |           |                | 
                | f               | f                | f
 jim     |    82240 | f           | f        | f         | f       | ******** |          |          | default_pool |      0 |            |           |           |                | 
                | f               | f                | f
(3 rows)
步骤 4 创建有 创建数据库 权限的用户,则需要加 CREATEDB 关键字。
openGauss=# CREATE USER dim CREATEDB PASSWORD 'Bigdata@123';
CREATE ROLE
openGauss=# 
步骤 5 将用户 jim 的登录密码由 Bigdata@123 修改为 Abcd@123
openGauss=#  ALTER USER jim IDENTIFIED BY 'Abcd@123' REPLACE 'Bigdata@123';
ALTER ROLE
openGauss=# 
步骤 6 为用户 jim 追加有创建角色的 CREATEROLE 权限。
openGauss=#  ALTER USER jim CREATEROLE;
ALTER ROLE
openGauss=# 
步骤 7 锁定 jim 帐户。
openGauss=# ALTER USER jim ACCOUNT LOCK;
ALTER ROLE
openGauss=# 
步骤 8 解锁 jim 帐户。
openGauss=#  ALTER USER jim ACCOUNT UNLOCK;
ALTER ROLE
openGauss=# 
步骤 9 删除用户.
openGauss=# DROP USER jim CASCADE;
DROP ROLE
openGauss=# 

1.3 角色

角色是拥有数据库对象和权限的实体。在不同的环境中角色可以认为是一个用户,一个组或者
兼顾两者。
在数据库中添加一个新角色,角色无登录权限。
创建角色的用户必须具备 CREATE ROLE 的权限或者是系统管理员。
1.3.1 创建、修改、删除角色
步骤 1 启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号为
15400
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# 
步骤 2 创建一个角色,名为 manager ,密码为 Bigdata@123
openGauss=# CREATE ROLE manager IDENTIFIED BY 'Bigdata@123';
CREATE ROLE
openGauss=# 
步骤 3 创建一个角色,从 2020 7 1 日开始生效,到 2020 12 1 日失效。
openGauss=# CREATE ROLE miriam WITH LOGIN PASSWORD 'Bigdata@123' VALID BEGIN '2020-07-01' VALID UNTIL '2020-12-01';
CREATE ROLE
openGauss=# 
步骤 4 修改角色 manager 的密码为 abcd@123
openGauss=# ALTER ROLE manager IDENTIFIED BY 'abcd@123' REPLACE 'Bigdata@123';
ALTER ROLE
openGauss=# 
步骤 5 修改角色 manager 为系统管理员。
openGauss=#  ALTER ROLE manager SYSADMIN;
ALTER ROLE

步骤 6 删除角色 manager

openGauss=# DROP ROLE manager;
DROP ROLE
步骤 7 查看角色。
openGauss=#  SELECT * FROM PG_ROLES;
         rolname          | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcatupdate | rolcanlogin | rolreplication | rolauditadmin | rolsystemadmin | rolconnlimit | rolp
assword |     rolvalidbegin      |     rolvaliduntil      |  rolrespool  | rolparentid | roltabspace | rolconfig |  oid  | roluseft | rolkind | nodegroup | roltempspace | rolspills
pace | rolmonitoradmin | roloperatoradmin | rolpolicyadmin 
--------------------------+----------+------------+---------------+-------------+--------------+-------------+----------------+---------------+----------------+--------------+-----
--------+------------------------+------------------------+--------------+-------------+-------------+-----------+-------+----------+---------+-----------+--------------+----------
-----+-----------------+------------------+----------------
 dim                      | f        | t          | f             | t           | f            | t           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           | 82244 | f        | n       |           |              |          
     | f               | f                | f
 lucy                     | f        | t          | f             | f           | f            | t           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           | 49478 | f        | n       |           |              |          
     | f               | f                | f
 miriam                   | f        | t          | f             | f           | f            | t           | f              | f             | f              |           -1 | ****
****    | 2020-07-01 00:00:00+08 | 2020-12-01 00:00:00+08 | default_pool |           0 |             |           | 82252 | f        | n       |           |              |          
     | f               | f                | f
 omm                      | t        | t          | t             | t           | t            | t           | t              | t             | t              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           |    10 | t        | n       |           |              |          
     | t               | t                | t
 gs_role_directory_drop   | f        | t          | f             | f           | f            | f           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           |  1059 | f        | n       |           |              |          
     | f               | f                | f
 gs_role_directory_create | f        | t          | f             | f           | f            | f           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           |  1056 | f        | n       |           |              |          
     | f               | f                | f
 gs_role_pldebugger       | f        | t          | f             | f           | f            | f           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           |  1055 | f        | n       |           |              |          
     | f               | f                | f
 gs_role_account_lock     | f        | t          | f             | f           | f            | f           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           |  1048 | f        | n       |           |              |          
     | f               | f                | f
 gs_role_replication      | f        | t          | f             | f           | f            | f           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           |  1047 | f        | n       |           |              |          
     | f               | f                | f
 gs_role_tablespace       | f        | t          | f             | f           | f            | f           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           |  1046 | f        | n       |           |              |          
     | f               | f                | f
 gs_role_signal_backend   | f        | t          | f             | f           | f            | f           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           |  1045 | f        | n       |           |              |          
     | f               | f                | f
 gs_role_copy_files       | f        | t          | f             | f           | f            | f           | f              | f             | f              |           -1 | ****
****    |                        |                        | default_pool |           0 |             |           |  1044 | f        | n       |           |              |          
     | f               | f                | f
(12 rows)

1.4 Schema

Schema 又称作模式。通过管理 Schema ,允许多个用户使用同一数据库而不相互干扰。
每个数据库包含一个或多个 Schema
在数据库创建用户时,系统会自动帮助用户创建一个同名 Schema
1.4.1 创建、修改、删除 Schema
步骤 1 启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号为
15400
步骤 2 创建模式 ds
openGauss=# CREATE SCHEMA ds;
CREATE SCHEMA
openGauss=# 
步骤 3 将当前模式 ds 更名为 ds_new
openGauss=#  ALTER SCHEMA ds RENAME TO ds_new;
ALTER SCHEMA
openGauss=# 
步骤 4 创建用户 jack
步骤 5 将 DS_NEW 的所有者修改为 jack。

步骤 5 DS_NEW 的所有者修改为 jack

openGauss=# ALTER SCHEMA ds_new OWNER TO jack;
ALTER SCHEMA
步骤 6 查看 Schema 所有者。
openGauss=# SELECT s.nspname,u.usename AS nspowner FROM pg_namespace s, pg_user u WHERE s.nspowner = u.usesysid;
      nspname       | nspowner 
--------------------+----------
 pg_toast           | omm
 cstore             | omm
 pkg_service        | omm
 dbe_perf           | omm
 snapshot           | omm
 blockchain         | omm
 pg_catalog         | omm
 sqladvisor         | omm
 dbe_pldebugger     | omm
 dbe_pldeveloper    | omm
 dbe_sql_util       | omm
 information_schema | omm
 db4ai              | omm
 public             | omm
 tpcds              | omm
 pmk                | omm
 lucy               | lucy
 dim                | dim
 jack               | jack
 ds_new             | jack
步骤 7 删除用户 jack 和模式 ds_new
openGauss=# DROP SCHEMA ds_new;
DROP SCHEMA
openGauss=#  DROP USER jack;
DROP ROLE

1.5 用户权限设置及回收

使用 GRANT 命令进行用户授权包括以下三种场景:
  将系统权限授权给角色或用户。
  将数据库对象授权给角色或用户。
 将角色或用户的权限授权给其他角色或用户。
1.5.1 将系统权限授权给用户或者角色
步骤 1 启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号
15400
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

步骤 2 创建名为 joe 的用户,并将 sysadmin 权限授权给 joe
openGauss=# CREATE USER joe PASSWORD 'Bigdata@123';
CREATE ROLE
openGauss=# GRANT ALL PRIVILEGES TO joe;
ALTER ROLE
1.5.2 将数据库对象授权给角色或用户
步骤 1 撤销 joe 用户的 sysadmin 权限,然后创建 tpcds 模式,并给 tpcds 模式下创建一张 reason
表。
openGauss=# REVOKE ALL PRIVILEGES FROM joe;
ALTER ROLE
openGauss=# CREATE SCHEMA tpcds;
CREATE SCHEMA
openGauss=#  CREATE TABLE tpcds.reason 
openGauss-# ( 
openGauss(#  r_reason_sk INTEGER NOT NULL, 
openGauss(#  r_reason_id CHAR(16) NOT NULL, 
openGauss(#  r_reason_desc VARCHAR(20) 
openGauss(# );
CREATE TABLE
openGauss=# 
步骤 2 将模式 tpcds 的使用权限和表 tpcds.reason 的所有权限授权给用户 joe
openGauss=# GRANT USAGE ON SCHEMA tpcds TO joe;
GRANT
openGauss=# GRANT ALL PRIVILEGES ON tpcds.reason TO joe;
GRANT
openGauss=# 
授权成功后, joe 用户就拥有了 tpcds.reason 表的所有权限,包括增删改查等权限。
步骤 3 tpcds.reason 表中 r_reason_sk r_reason_id r_reason_desc 列的查询权限,
r_reason_desc 的更新权限授权给 joe
openGauss=# GRANT select (r_reason_sk,r_reason_id,r_reason_desc),update (r_reason_desc) ON tpcds.reason TO joe;
GRANT
openGauss=# 
步骤 4 将数据库 postgres 的连接权限授权给用户 joe ,并给予其在 postgres 中创建 schema 的权限, 而且允许 joe 将此权限授权给其他用户。
openGauss=# GRANT create,connect on database postgres TO joe WITH GRANT OPTION;
GRANT
openGauss=# 
步骤 5 创建角色 tpcds_manager ,将模式 tpcds 的访问权限授权给角色 tpcds_manager ,并授予
该角色在 tpcds 下创建对象的权限,不允许该角色中的用户将权限授权给其人。
openGauss=# CREATE ROLE tpcds_manager PASSWORD 'Bigdata@123';
CREATE ROLE
openGauss=#  GRANT USAGE,CREATE ON SCHEMA tpcds TO tpcds_manager;
GRANT
openGauss=# 
1.5.3 将用户或者角色的权限授权给其他用户或角色
步骤 1 创建角色 manager ,将 joe 的权限授权给 manager ,并允许该角色将权限授权给其他人。
openGauss=# CREATE ROLE manager PASSWORD 'Bigdata@123';
CREATE ROLE
openGauss=#  GRANT joe TO manager WITH ADMIN OPTION;
GRANT ROLE
openGauss=# 
步骤 2 创建用户 senior_manager ,将用户 manager 的权限授权给该用户。
openGauss=#  CREATE ROLE senior_manager PASSWORD 'Bigdata@123';
CREATE ROLE
openGauss=# 
1.5.4 权限回收
步骤 1 撤销权限,并清理用户。
openGauss=# REVOKE joe FROM manager;
REVOKE ROLE
openGauss=# REVOKE manager FROM senior_manager;
WARNING:  role "senior_manager" is not a member of role "manager"
REVOKE ROLE
openGauss=# DROP USER manager;
DROP ROLE
openGauss=# REVOKE ALL PRIVILEGES ON tpcds.reason FROM joe;
REVOKE
openGauss=# REVOKE ALL PRIVILEGES ON SCHEMA tpcds FROM joe;
REVOKE
openGauss=# REVOKE USAGE,CREATE ON SCHEMA tpcds FROM tpcds_manager;
REVOKE
openGauss=# DROP ROLE tpcds_manager;
DROP ROLE
openGauss=# DROP ROLE senior_manager;
DROP ROLE
openGauss=# DROP USER joe CASCADE;
DROP ROLE
注意:实验完成后请尽量清理本实验的对象,以免影响与其它实验产生冲突。

1.6 安全策略设置

为了保证帐户安全,如果用户输入密码次数超过一定次数( failed_login_attempts ),系统将
自动锁定该帐户,默认值为 10 。次数设置越小越安全,但是在使用过程中会带来不便。
当帐户被锁定时间超过设定值( password_lock_time ),则当前帐户自动解锁,默认值为 1 天。
时间设置越长越安全,但是在使用过程中会带来不便。
1.6.1 设置账户安全策略
步骤 1 启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号为
15400
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 2 配置 failed_login_attempts 参数。
查看已配置的参数。
openGauss=# SHOW failed_login_attempts;
 failed_login_attempts 
-----------------------
 10
(1 row)

如果显示结果不为 10 ,执行 \q 命令退出数据库。
然后在操作系统 omm 用户下执行如下命令设置成默认值 10
gs_guc reload -D /gaussdb/data/dbnode -c "failed_login_attempts=10"
注意: /gaussdb/data/dbnode 指的是数据目录,要根据自己实际情况调整。
(在omm用户下使用 gs_om -t status --detail 可以查询到数据目录)
比如数据目录 /opt/huawei/install/data/dn ,执行结果如下。
openGauss=# SHOW failed_login_attempts;
 failed_login_attempts 
-----------------------
 10
(1 row)

openGauss=# \q
[omm@node0 ~]$ gs_om -t status --detail;
[   Cluster State   ]

cluster_state   : Normal
redistributing  : No
current_az      : AZ_ALL

[  Datanode State   ]

    node node_ip         port      instance                            state
--------------------------------------------------------------------------------------------
1  node0 192.168.28.131  15400      6001 /opt/huawei/install/data/dn   P Primary Normal
[omm@node0 ~]$ gs_guc reload -D /opt/huawei/install/data/dn -c "failed_login_attempts=10" ;
The gs_guc run with the following arguments: [gs_guc -D /opt/huawei/install/data/dn -c failed_login_attempts=10 reload ].
expected instance path: [/opt/huawei/install/data/dn/postgresql.conf]
gs_guc reload: failed_login_attempts=10: [/opt/huawei/install/data/dn/postgresql.conf]
server signaled

Total instances: 1. Failed instances: 0.
Success to perform gs_guc!
步骤 3 配置 password_lock_time 参数。
查看已配置的参数。
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# SHOW password_lock_time;
 password_lock_time 
--------------------
 1d
(1 row)
如果显示结果不为 1 ,执行 \q 命令退出数据库。
然后在操作系统 omm 用户下执行如下命令设置成默认值 1
openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "password_lock_time=1"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c password_lock_time=1 reload ].
NOTICE: password_lock_time and failed_login_attempts must have positive for lock and unlock functions to work as.
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!
1.6.2 设置账号有效期
创建新用户时,需要限制用户的操作期限(有效开始时间和有效结束时间)。
不在有效操作期内的用户需要重新设定帐号的有效操作期。
步骤 1 启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号为
15400
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 2 创建用户并制定用户的有效开始时间和有效结束时间。
openGauss=#  CREATE USER joe WITH PASSWORD 'Bigdata@123' VALID BEGIN '2020-07-10 08:00:00' VALID UNTIL '2022-10-10 08:00:00';
CREATE ROLE
步骤 3 重新设定帐号的有效期。
openGauss=# ALTER USER joe WITH VALID BEGIN '2020-11-10 08:00:00' VALID UNTIL '2021-11-10 08:00:00';
ALTER ROLE
1.6.3 设置密码安全策略
用户密码存储在系统表 pg_authid 中,为防止用户密码泄露, openGauss 对用户密码可进行加
密存储、密码复杂度设置、密码重用天数设置、密码有效期限设置等。
步骤 1 启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号为
15400
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 2 配置的加密算法。
查看已配置的参数。
openGauss=#  SHOW password_encryption_type;
 password_encryption_type 
--------------------------
 2
(1 row)
如果显示结果为 0 1 ,执行 \q 命令退出数据库。
然后在操作系统 omm 用户下执行如下命令将其设置为安全的加密算法。
openGauss=#  SHOW password_encryption_type;
 password_encryption_type 
--------------------------
 2
(1 row)

openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "password_encryption_type=2"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c password_encryption_type=2 reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!

注意说明:
  当参数 password_encryption_type 设置为 0 时,表示采用 md5 方式对密码加密。 md5
不安全的加密算法,不建议使用。
  当参数 password_encryption_type 设置为 1 时,表示采用 sha256 md5 方式对密码加
密。其中包含 md5 为不安全的加密算法,不建议使用。
  当参数 password_encryption_type 设置为 2 时,表示采用 sha256 方式对密码加密,为默
认配置。
步骤 3 配置密码安全参数。
查看已配置的参数。
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=#  SHOW password_policy;
 password_policy 
-----------------
 1
(1 row)
如果显示结果不为 1 ,执行 \q 命令退出数据库。
然后在操作系统 omm 下执行如下命令设置成默认值 1

openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "password_policy=1"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c password_policy=1 reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!

注意说明:
  参数 password_policy 设置为 1 时表示采用密码复杂度校验,默认值;
  参数 password_policy 设置为 0 时表示不采用任何密码复杂度校验,设置为 0 会存在安全
风险,不建议设置为 0 ,即使需要设置也要将所有 openGauss 节点中的 password_policy
都设置为 0 才能生效。
步骤 4 配置密码重用。
查看不可重用天数已配置的参数。
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# SHOW password_reuse_time;
 password_reuse_time 
---------------------
 60
(1 row)

如果显示结果不为 60 ,执行 \q 命令退出数据库。
然后在操作系统 omm 下执行如下命令设置成默认值 60
openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "password_reuse_time=60"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c password_reuse_time=60 reload ].
NOTICE: Checks the configuration parameters password_reuse_time and password_reuse_max when modifying password, as long as either one, can be considered the password can be reused.
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!

查看不可重用次数已配置的参数。
[omm@node0 ~]$ gsql -d postgres -p 15400 -r;
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# SHOW password_reuse_max;
 password_reuse_max 
--------------------
 0
(1 row)
如果显示结果不为 0 ,执行 \q 命令退出数据库。
然后在操作系统 omm 下执行如下命令设置成默认值 0
openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "password_reuse_max = 0"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c password_reuse_max = 0 reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!


注意说明:
  不可重用天数默认值为 60 天,不可重用次数默认值是 0
  这两个参数值越大越安全,但是在使用过程中会带来不便,其默认值符合安全标准,用户
可以根据需要重新设置参数,提高安全等级。
步骤 5 配置密码有效期限。
数据库用户的密码都有密码有效期( password_effect_time ),当达到密码到期提醒天数
password_notify_time )时,系统会在用户登录数据库时提示用户修改密码。
配置 password_effect_time 参数。
查看已配置的参数。
openGauss=# SHOW password_effect_time;
 password_effect_time 
----------------------
 90
(1 row)

openGauss=# 
如果显示结果不为 90 ,执行 \q 命令退出数据库。
然后在操作系统 omm 下执行如下命令设置成默认值 90 (不建议设置为 0 )。
openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "password_effect_time = 90"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c password_effect_time = 90 reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!
步骤 6 配置 password_notify_time 参数。
查看已配置的参数。

[omm@node0 ~]$ gsql -d postgres -p 15400 -r;
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# SHOW password_notify_time;
 password_notify_time 
----------------------
 7
(1 row)
如果显示结果不为 7 ,执行 \q 命令退出数据库。
然后在操作系统 omm 下执行如下命令设置成默认值 7 (不建议设置为 0 )。
openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "password_notify_time = 7"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c password_notify_time = 7 reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!

用户权限控制实验结束。

2 审计

2.1 实验介绍

2.1.1 关于本实验
数据库安全对数据库系统来说至关重要, openGauss 将用户对数据库的所有操作写入审计日志,
数据库安全管理员可以利用这些日志信息,重现导致数据库现状的一系列事件,找出非法操作
的用户、时间和内容等。
本实验主要描述如何来设置数据库审计,主要包括审计开关、查看审计结果、维护审计日志。
2.1.2 实验目的
掌握如何设置数据库审计及审计日志的查看。

2.2 审计开、关

审计总开关 audit_enabled 支持动态加载。在数据库运行期间修改该配置项的值会立即生效,
无需重启数据库。默认值为 on ,表示开启审计功能。
除了审计总开关,各个审计项也有对应的开关。只有开关开启,对应的审计功能才能生效。
各审计项的开关支持动态加载。在数据库运行期间修改审计开关的值,不需要重启数据库便可
生效。
步骤 1 审计总开关设置。
启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号为 15400
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
查看已配置审计总开关参数。
openGauss=# show audit_enabled;
 audit_enabled 
---------------
 on
(1 row)
如果显示结果不为 on ,执行 “\q” 命令退出数据库。
然后在操作系统 omm 下执行如下命令设置成默认值 on (不建议设置为 off )。
openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "audit_enabled = on"The gs_guc run with the following arguments: [gs_guc -N all -I all -c audit_enabled = on reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!
步骤 2 审计项开关设置。
查看已配置审计项参数。
以下以数据库启动、停止、恢复和切换审计项为例。

openGauss=# show audit_database_process;
 audit_database_process 
------------------------
 1
(1 row)

如果显示结果不为 1 ,执行 “\q” 命令退出数据库。
然后在操作系统 omm 下执行如下命令设置成默认值 1
openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c " audit_database_process = 1"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c  audit_database_process = 1 reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!

注意说明:
 用户登录、注销审计。
参数:audit_login_logout。
默认值为 7,表示开启用户登录、退出的审计功能。设置为 0 表示关闭用户登录、退出的审计
功能。不推荐设置除 0 和 7 之外的值。
 数据库启动、停止、恢复和切换审计。
参数:audit_database_process。
默认值为 1,表示开启数据库启动、停止、恢复和切换的审计功能。
 用户锁定和解锁审计。
参数:audit_user_locked。
默认值为 1,表示开启审计用户锁定和解锁功能。
 用户访问越权审计。
参数:audit_user_violation。
默认值为 0,表示关闭用户越权操作审计功能。
 授权和回收权限审计。
参数:audit_grant_revoke。
默认值为 1,表示开启审计用户权限授予和回收功能。
 数据库对象的 CREATE,ALTER,DROP 操作审计。
参数:audit_system_object。
默认值为 12295,表示只对 DATABASE、SCHEMA、USER、DATA SOURCE 这四类数据库对
象的 CREATE、ALTER、DROP 操作进行审计。
 具体表的 INSERT、UPDATE 和 DELETE 操作审计。
参数:audit_dml_state。
默认值为 0,表示关闭具体表的 DML 操作(SELECT 除外)审计功能。
 SELECT 操作审计。
参数:audit_dml_state_select。
默认值为 0,表示关闭 SELECT 操作审计功能。
 COPY 审计。
参数:audit_copy_exec。
默认值为 0,表示关闭 copy 操作审计功能。
 存储过程和自定义函数的执行审计。
参数:audit_function_exec。
默认值为 0,表示不记录存储过程和自定义函数的执行审计日志。
 SET 审计 参数:audit_set_parameter。
默认值为 1,表示记录 set 操作审计日志。

2.3 查看审计结果

步骤 1 启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号为15400。


[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 2 查询审计记录
openGauss=# SELECT time,type,result,username,object_name FROM pg_query_audit('2020-07-10 10:00:00','2020-08-15 09:47:33');
 time | type | result | username | object_name 
------+------+--------+----------+-------------
(0 rows)

openGauss=# 

2.4 维护审计日志

设置自动删除审计日志。
步骤 1 启动服务器,再使用 gsql 客户端以管理员用户身份连接 postgres 数据库,假设端口号为
15400
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
步骤 2 配置审计文件占用磁盘空间的大小( audit_space_limit )。
查看已配置的参数。
openGauss=# SHOW audit_space_limit;
 audit_space_limit 
-------------------
 1GB
(1 row)
如果显示结果不为 1GB 1024MB ),执行 “\q” 命令退出数据库。
然后在操作系统 omm 用户下执行如下命令设置成默认值 1024MB
openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "audit_space_limit=1024MB"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c audit_space_limit=1024MB reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!
步骤 3 配置审计文件个数的最大值( audit_file_remain_threshold )。
查看已配置的参数。
openGauss=# SHOW audit_file_remain_threshold;
 audit_file_remain_threshold 
-----------------------------
 1048576
(1 row)

如果显示结果不为 1048576,执行“\q”命令退出数据库。

然后在操作系统 omm 用户执行如下命令设置成默认值 1048576
openGauss=# \q
[omm@node0 ~]$ gs_guc reload -N all -I all -c "audit_file_remain_threshold=1048576"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c audit_file_remain_threshold=1048576 reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!
步骤 4 手动删除审计日志。
当不再需要某时段的审计记录时,可以使用审计接口命令 pg_delete_audit 进行手动删除。
以删除 2020/7/10 2020/7/20 之间的审计记录为例:
[omm@node0 ~]$ gsql -d postgres -p 15400 -r
gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# ^C
openGauss=# SELECT pg_delete_audit('2020-07-10 ','2020-07-20');
 pg_delete_audit 
-----------------
 
(1 row)
审计实验结束。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/562387.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

ACE框架学习2

目录 ACE Service Configurator框架 ACE_Server_Object类 ACE_Server_Repository类 ACE_Server_Config类 ACE Task框架 ACE_Message_Queue类 ACE_TASK类 在开始之前&#xff0c;首先介绍一下模板类的实例化和使用。给出以下代码 //ACCEPTOR代表模板的方法 template <…

CAS Client使用以及执行原理

CAS Client使用以及执行原理 流程介绍 CAS Client是利用Java Web中的Filter进行实现认证功能&#xff0c;客户端对CAS Server的认证流程分为以下步骤&#xff1a; 访问CAS Client服务 由于当前session中未检测到认证信息&#xff0c;会重定向到CAS Server地址进行认证 在CA…

【深度学习】Dropout、DropPath

一、Dropout 1. 概念 Dropout 在训练阶段会让当前层每个神经元以drop_prob&#xff08; 0 ≤ drop_prob ≤ 1 0\leq\text{drop\_prob}\leq1 0≤drop_prob≤1&#xff09;的概率失活并停止工作&#xff0c;效果如下图。 在测试阶段不会进行Dropout。由于不同批次、不同样本的神…

IMUGNSS的误差状态卡尔曼滤波器(ESKF)---更新过程

IMU&GNSS的误差状态卡尔曼滤波器&#xff08;ESKF&#xff09;---更新过程 ESKF的更新过程 ESKF的更新过程 前面介绍的是ESKF的运动过程&#xff0c;现在考虑更新过程。假设一个抽象的传感器能够对状态变量产生观测&#xff0c;其观测方程为抽象的h,那么可以写为 其中z为…

创新指南|节日期间提高销量的 10 个最佳技巧

许多网上购物者在感恩节前开始假日购物。假期是在线企业销售产品和增加销售额的最佳时机。根据万事达卡的数据&#xff0c;去年在线假日销售额增长了 10.6%&#xff0c;而店内销售额增长了 6.8%。此外&#xff0c;2023年美国消费者平均计划在假日旺季花费约1,530美元。在线企业…

存储过程的查询

Oracle从入门到总裁:​​​​​​https://blog.csdn.net/weixin_67859959/article/details/135209645 在实际使用中&#xff0c;经常会需要查询数据库中已有的存储过程或者某一个存储过程的内容&#xff0c; 下面就介绍-下如何查询存储过程。 这需要使用到数据字典 user_sou…

vscode 配置verilog环境

一、常用的设置 1、语言设置 安装如下插件&#xff0c;然后在config 2、编码格式设置 解决中文注释乱码问题。vivado 默认是这个格式&#xff0c;这里也设置一样。 ctrl shift p 打开设置项 3、插件信任区设 打开一个verilog 文件&#xff0c;显示是纯本文&#xff0c;没…

B树和B+树试题解析

一、单项选择题 01&#xff0e;下图所示是一棵&#xff08;A ). A.4阶B树 B.3阶B树 C.4阶B树 D.无法确定 02.下列关于m阶B树的说法中&#xff0c;错误的是( C ). A.根结点至多有m棵子树 B.所有叶结点都在同一层次上 C.非叶结点至…

算法入门——二分查找

目录 1、二分模板 2、习题 1.704.二分查找 2.35.搜索插入位置 3.744. 寻找比目标字母大的最小字母 4.69. x 的平方根 5.1351. 统计有序矩阵中的负数 6.74. 搜索二维矩阵 7.34. 在排序数组中查找元素的第一个和最后一个位置 8.33. 搜索旋转排序数组 9.153. 寻找旋转排…

【GoWeb框架初探————XORM篇】

1. XORM xorm 是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作非常简便。 1.1 特性 支持 Struct 和数据库表之间的灵活映射&#xff0c;并支持自动同步事务支持同时支持原始SQL语句和ORM操作的混合执行使用连写来简化调用支持使用ID, In, Where, Limit, Join, Havi…

java学习笔记2

3 选择结构 3.1 if选择结构 3.1.1 基本if结构 语法if(条件){// 代码块 }执行流程 当if条件为真,执行代码块,否则不执行代码块。 代码 public class Demo1 {public static void main(String[] args) {// 需求: 张浩的考试成绩>90分,奖励一部Iphone6sScanner sc = new S…

mapreduce中的ReduceTask工作机制(Hadoop)

ReduceTask 是 Hadoop 中的一个重要组件&#xff0c;负责对 MapTask 的输出进行合并、排序和归并&#xff0c;最终生成最终的输出结果。 ReduceTask 的工作机制 1. 分组&#xff08;Shuffle&#xff09;阶段&#xff1a; 在分组阶段&#xff0c;ReduceTask 会从多个 Mapper …

第二届 Oceanbase 开发者大会 实录

第二届 Oceanbase 开发者大会 实录 今天很有幸参加了Oceanbase 开发者大会&#xff0c;我是真的我一开始还不知道什么是Oceanbase &#xff0c;直到我开了会才知道。看来真的需要多参加一些这样活动。 会议议程 我们科普一下什么是Oceanbase OceanBase 是阿里巴巴集团推出…

FastChat启动与部署通义千问大模型

FastChat简介 FastChat is an open platform for training, serving, and evaluating large language model based chatbots. FastChat powers Chatbot Arena, serving over 10 million chat requests for 70 LLMs.Chatbot Arena has collected over 500K human votes from sid…

Llama 3 实测效果炸裂,一秒写数百字(附镜像站)

这几天大火的llama 3刚刚在https://askmanyai.cn上线了&#xff01; 玩了一会儿&#xff0c;这个生成速度是真的亚麻呆住。文案写作和代码生成直接爽到起飞&#xff0c;以往gpt要写一两分钟的千字文&#xff0c;llama 3几秒钟就写完了。而且效果甚至感觉更好&#xff1f; 效果惊…

日期相关的题目

日期相关的题目 1. 计算日期到天数转换2. 日期累加3. 打印日期4. 日期差值 1. 计算日期到天数转换 输出示例: 思路&#xff1a;计算前n-1个月的天数在加上这个月的天数。 #include <iostream> using namespace std;int main() {int year, month, day;cin >> yea…

数据结构练习-数据结构概述

----------------------------------------------------------------------------------------------------------------------------- 1. 在数据结构中&#xff0c;从逻辑上可以把数据结构分成( )。 A. 动态结构和静态结构 B. 紧凑结构和非紧凑结构 C. 线性结…

Spring AI Summary

版权声明 本文原创作者&#xff1a;谷哥的小弟作者博客地址&#xff1a;http://blog.csdn.net/lfdfhl Spring AI is a project that aims to streamline the development of AI applications by providing abstractions and reusable components that can be easily integrate…

梯度消失/梯度爆炸

梯度消失/梯度爆炸&#xff08;Vanishing / Exploding gradients&#xff09; 梯度消失或梯度爆炸&#xff1a;训练神经网络的时候&#xff0c;导数或坡度有时会变得非常大&#xff0c;或者非常小&#xff0c;甚至于以指数方式变小&#xff0c;这加大了训练的难度。 g ( z ) …

Java学习Go(入门)

下载Go 《官网下载golang》 直接点Download&#xff0c;然后根据你自己的操作系统进行下载&#xff0c;我这里以win10为例 安装go 默认安装到C:\Program Files\Go&#xff0c;这里我们可以选择安装到其他盘&#xff0c;也可以选择默认安装。初学者建议直接一路next。 安装完…