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

news2024/9/17 8:32:12

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

目录

前言

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.coloradmin.cn/o/1613088.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

springboot+vue全栈开发【4.前端篇之Vue组件化开发】

目录 前言NPM使用NPM简介nodejs安装npm命令 Vue CLI使用用vue CLI创建一个vue项目 组件化开发组件的构成组件怎么用1.创建一个组件2.在父组件中使用子组件3. 传递数据给子组件4. 监听子组件事件 前言 hi&#xff0c;这个系列是我自学开发的笔记&#xff0c;适合具有一定编程基…

配置 rust国内源

rust crate.io 配置国内源&#xff08;cargo 国内源&#xff09; warning: spurious network error (2 tries remainin..._warning: spurious network error (3 tries remaining-CSDN博客

Boximator: Generating Rich and Controllable Motions for Video Synthesis

模型添加控制的方式是利用bbox和move path&#xff0c;在训练的时候冻结原始视频生成模型的参数&#xff0c;只是训练新添加的control module&#xff0c;修改的位置是在spatial attetion里面&#xff0c;新添加了一个self attention v v S e l f A t t n ( v ) v v T S (…

node的事件循环

异步同步啥的就不多说了&#xff0c;直接看node中有哪些是异步 其中灰色部分和操作系统有很大的关系&#xff0c;就不多说了&#xff0c;其中定时器属于timers队列&#xff0c;I/O操作属于poll队列&#xff0c;setImmediate属于check队列&#xff0c;其中nextTick和promise不属…

补档 -- 测试的分类(1)

最近有很多人私信我说: 灰灰你什么时候写测试分类阿, 本来我要开始肝性能测试的, 我一看, 奥, 之前摸鱼忘写了, 所以这里补档(叶问指着一边笑.jpg). 总览 标红的需要注意一下. 为什么要对软件测试进行分类? 软件测试是软件生命周期的一个重要环节, 具有较高的复杂性, 对于软…

【JAVA】实现只有一个窗口弹出的底层逻辑——单身模式

目录 背景说明 代码实现 手写笔记 背景说明 有的时候&#xff0c;当你点击一个选项时会弹出来多个窗口&#xff0c;而有的时候只会弹出一个。 实际上&#xff0c;弹出多个窗口就是创建了多个相同的对象&#xff0c;而只弹出一个就是我们今天即将分享的单身模式——一个类只产生…

java:基于javase上实现的图书管理系统

目录 大概功能&#xff1a; 主要步骤&#xff1a; Main类 book包 Book类 BookList类 operation包 AddOperation类 BorrowedOperation类 DelOperatoion类 ExitOpration类 FindOperation类 IoPeration接口 ReturnOperation类 ShowOperation类 user包 AdminUser类 大概功…

【高校科研前沿】东北地理所孙敬轩博士为一作在《中国科学:地球科学(中英文版)》发文:气候变化下东北地区农业绿水安全风险评估

目录 01 文章简介 02 研究内容 03 文章引用 04 期刊简介 01 文章简介 论文名称&#xff1a;Risk assessment of agricultural green water security in Northeast China under climate change&#xff08;气候变化下东北地区农业绿水安全风险评估&#xff09; 第一作者及…

CSS显示模式

目录 CSS显示模式简介 CSS显示模式的分类 块元素 行元素 行内块元素 元素显示模式的转换 使块内文字垂直居中的方法 设计简单小米侧边栏&#xff08;实践&#xff09; CSS显示模式简介 元素显示模式就是元素&#xff08;标签&#xff09;以什么方式进行显示&#xff0…

在 Linux 中复制文件和目录

目录 ⛳️推荐 前言 在 Linux 命令行中复制文件 将文件复制到另一个目录 复制文件但重命名 将多个文件复制到另一个位置 复制时处理重复文件 交互式复制文件 在 Linux 命令行中复制目录 仅复制目录的内容&#xff08;不是目录&#xff09; 复制多个目录 测试你的知…

顺序表leetcode刷题(C语言版)

一.移除元素 对于本题&#xff0c;共有两种解法&#xff1a; 思路一&#xff1a;创建新的数组&#xff0c;遍历原数组&#xff0c;将不为value的值放到新数组中&#xff0c;但本题不允许使用新的数组&#xff0c;因此该方法不行 思路二&#xff1a;使用快慢指针&#xff0c;原数…

用Cmake编译程序时,链接到FFmpeg库

用Cmake编译程序时&#xff0c;链接到FFmpeg库 一、前言 可喜可贺&#xff0c;折腾了一晚上终于把这个勾八链接成功了&#xff0c;已经要吐了。看到下面控制台的输出&#xff0c;吾心甚慰呀&#x1f62d; [100%] Linking CXX executable rknn_yolov5_demo [100%] Built targe…

[数据结构]——排序——插入排序

目录 ​编辑 1 .插入排序 1.基本思想&#xff1a; 2.直接插入排序&#xff1a; ​编辑 1.代码实现 2.直接插入排序的特性总结&#xff1a; 3.希尔排序( 缩小增量排序 ) 1.预排序 2.预排序代码 3.希尔排序代码 4.希尔排序的特性总结&#xff1a; 1 .插入排序 1.基本思…

C语言联合体详解

下午好诶&#xff0c;今天小眼神给大家带来一篇C语言联合体详解的文章~ 目录 联合体 1. 联合体类型的声明 2. 联合体的特点 代码一&#xff1a; 代码二&#xff1a; 3. 相同成员的结构体和联合体对比 ​编辑4. 联合体大小的计算 5. 联合体的优点 联合体 1. 联合体…

电脑显示缺失d3dx9_43.dll文件如何修复?分享5种详细的修复方法

在日常使用计算机的过程中&#xff0c;当我们尝试启动某个软件或运行一款游戏时&#xff0c;系统可能会弹出一个错误提示信息&#xff0c;明确指出“d3dx9_43.dll文件缺失”。这个情况表明&#xff0c;作为Windows操作系统中不可或缺的一部分&#xff0c;DirectX 9.0c的一个关键…

数电期末复习(二)逻辑代数基础

这里写目录标题 2.1 二值逻辑变量与基本逻辑运算2.1.1 与运算2.1.2 或运算2.1.3 非运算2.1.4 常用复合逻辑运算 2.2 逻辑函数的建立及其表示方法2.2.1 真值表表示2.2.2 逻辑函数表达式表示2.2.3 逻辑图表示方法2.2.4 波形图表示方法 2.3 逻辑代数2.3.1 逻辑代数的基本定律和恒等…

MySQL数据库基础知识(数据库/表的基础操作 + 基本类型)

文章目录 数据库的操作显示当前数据库服务器上有哪些数据库创建数据库使用数据库删除数据库 常用数据类型数值类型字符串类型日期类型小结(主要使用) 表的操作创建表查看表结构列出当前数据库的表删除表 注释MySQL创建的数据库/表存储在系统的位置 数据库的操作 输入的单词之间…

算法入门——二分查找

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

政企版 WPS Pro 专业版注册安装教程

政企版 WPS Pro 专业版安装及激活步骤 第 1 步&#xff1a;下载压缩包&#xff08;内含注册码&#xff09;【无解压密码】。 第 2 步&#xff1a;解压缩后&#xff0c;运行 exe 文件&#xff0c;默认步骤安装即可。 第 3 步&#xff1a;安装完成后&#xff0c;新建一个 Word …

【ThinkPHP框架教程·Part-04】URL访问模式

文章目录 一、URL解析1、URL解析格式2、URL解析示例说明3、设置URL重写 二&#xff0e;URL 兼容模式 本章节我们来简单了解一下 ThinkPHP6.0 的 URL 访问模式&#xff0c;解析它的访问方法。 一、URL解析 ThinkPHP 框架非常多的操作都是通过 URL 来实现的。 1、URL解析格式 由…