mongo创建安全扫描账号手册

113 阅读2分钟

一、说明

配合安全团队,对每个DBA接管的数据库,提前埋入安全扫描账号。




二、操作

  1. 找到primary节点

http://172.20.171.9:8090/display/MON/ph.table.ordering

本次以 ph.table.ordering 的mongo为例,根据一个IP:172.21.25.155 找到primary节点

# 
172.22.90.207

# 连接节点的mongo服务
mongo -u admin -p '123456'  --port=27017  --authenticationDatabase admin --host=172.21.25.155


# 将从节点设置为可读
ssp:SECONDARY> db.getMongo().setSlaveOk()
WARNING: setSlaveOk() is deprecated and may be removed in the next major release. Please use setSecondaryOk() instead.
ssp:SECONDARY>


# 查找成员中primary节点
rs.status().members
# 如下显示为 primary节点
{
                "_id" : 2,
                "name" : "172.21.24.172:27017",
                "health" : 1,
                "state" : 1,
                "stateStr" : "PRIMARY",
                "uptime" : 9684775,
                "optime" : {
                        "ts" : Timestamp(1693287740, 29),
                        "t" : NumberLong(2)
                },
                "optimeDurable" : {
                        "ts" : Timestamp(1693287740, 29),
                        "t" : NumberLong(2)
                },

2. ## 连接primary

# 
mongo -u admin -p '123456'  --port=27017  --authenticationDatabase admin --host=172.21.24.172

3. ## 查看业务库名

# 找到业务库
ssp:SECONDARY> show dbs
admin      0.000GB
config     0.000GB
local      4.756GB
ssp_menu  24.788GB

4. ## 切换到业务库名


# 切换到业务库
use ssp_menu
  1. 查看该库下有哪些账号


# 在业务库中找用户名
db.getUsers()
  1. 创建安全扫描账号

# 安全扫描账号和密码都是统一固定,标黄的为业务库名字,需要根据实际库名决定
db.createUser({ user: "sec_db_scan", pwd: "y*RkI22H", roles: [ {role: "read", db: "ssp_menu"}]})

7. ## 验证

# 使用安全扫描账号登录mongo
[root@xfzcvmmw170550 ~]# mongo -u sec_db_scan -p 'y*RkI22H'  --port=27017  --authenticationDatabase ssp_menu --host=172.21.24.172
MongoDB shell version v4.4.17
connecting to: mongodb://172.21.24.172:27017/?authSource=ssp_menu&compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8af9b021-eb1c-488f-a45d-d6bbfa72f294") }
MongoDB server version: 4.4.17
ssp:PRIMARY>

8. ## 完成




三、补充

  1. 安全账号和密码统一固定,权限:只读

  1. 数据库交付出去的时候,默认都是带有该账号

  2. monogo exporter 的配置


MONGODB_EXPORTER_OPTS='--web.listen-address=":9216" --mongodb.uri="mongodb://monitor:Yum!monitor2China@127.0.0.1:27017/admin" --comp
atible-mode' 

图片.png