赞
踩
最近公司有个需求,就是上线时需要执行sql语句,但是直接将sql语句写在上线文档里或者上线时再发给运维去执行容易出现事故,而且我们数据库是云上的,开发想要本地去连数据库查询的话还得通过跳板机去连接,要么就得开放数据库外网,但是数据库开外网肯定是不行的;
于是经过几次讨论决定使用这个Yearning MySQL SQL审核平台;这个sql审核平台可以将上线执行sql更加流程化,开发将要上线的sql提交申请单,经过dba或者审批人的审批后方可让运维执行上线;而且执行完的sql会及时生成回滚语句,如果执行后发生问题,那么可以很方便的进行回滚;
关于Yearning SQL审核平台介绍和其它特点大家可以去看“Yearning原作者大大”的项目地址(链接在文章最后),这里我们主要以用起来为主:
现在Yearning审核平台最新的版本是v3.0.1
因为我们这里是单开一台云主机在生产环境部署的,所以暂且先不用最新版的,因为这两天调研了下 最新版的还存在一定的bug,例如“添加新用户时会出现添加不上 报用户已存在的bug”,不过这个bug今天已经被作者大大给解决了,但是还没有出新的tag,需要更新本地代码再编译才能使用;所以我们这里还是选择用老版本v2.3.5进行部署使用;
mysql | v5.7.38 |
---|---|
Yearning | v2.3.5 |
mysql 版本必须为5.7及以上版本(8.0及以上请将sql_mode 设置为空)并已事先自行安装完毕且创建 Yearning 库,字符集应为 UTF8mb4 (仅 Yearning 所需 mysql 版本)
[root@iZbp10iedgidvz3jgf4b27Z ~]# yum list installed | grep mysql
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
[root@iZbp10iedgidvz3jgf4b27Z ~]# yum list installed | grep mariadb
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
mariadb-libs.x86_64 1:5.5.68-1.el7 @anaconda
[root@iZbp10iedgidvz3jgf4b27Z ~]# yum -y remove mariadb-libs.x86_64
[root@iZbp10iedgidvz3jgf4b27Z ~]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib64/mysql
/root/.m2/repository/mysql
[root@iZbp10iedgidvz3jgf4b27Z ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql
[root@iZbp10iedgidvz3jgf4b27Z ~]# rm -rf /usr/lib64/mysql
下载5.7的mysql yum源
http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@iZbp10iedgidvz3jgf4b27Z ~]# wget -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm%E2%80%8B
[root@iZbp10iedgidvz3jgf4b27Z ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
[root@iZbp10iedgidvz3jgf4b27Z ~]# yum -y install mysql-community-server --nogpgcheck
[root@iZbp10iedgidvz3jgf4b27Z ~]# systemctl start mysqld
[root@iZbp10iedgidvz3jgf4b27Z ~]# systemctl enable mysqld
...
[root@iZbp10iedgidvz3jgf4b27Z ~]# grep 'temporary password' /var/log/mysqld.log #查看数据库初始密码
2022-07-07T06:02:13.403227Z 1 [Note] A temporary password is generated for root@localhost: !qNq:K.ZW6Z(
[root@iZbp10iedgidvz3jgf4b27Z ~]# mysql -uroot -p!qNq:K.ZW6Z(
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Kp^zxxxxxxxx';
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE DATABASE `Yearning` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| Yearning |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
https://github.com/cookieY/Yearning/releases/download/2.3.5/Yearning-2.3.5-linux-amd64.zip
[root@iZbp10iedgidvz3jgf4b27Z Yearning_workspace]# wget -c https://github.com/cookieY/Yearning/releases/download/2.3.5/Yearning-2.3.5-linux-amd64.zip
[root@iZbp10iedgidvz3jgf4b27Z Yearning_workspace]# unzip Yearning-2.3.5-linux-amd64.zip
[root@iZbp10iedgidvz3jgf4b27Z Yearning_workspace]# ll
total 42988
-rw-r--r-- 1 root root 137 Dec 17 2020 conf.toml #连接数据库的配置文件
-rw-r--r-- 1 root root 793 Sep 10 2020 docker-compose.yml
-rw-r--r-- 1 root root 535 May 26 2021 Dockerfile
-rw-r--r-- 1 root root 187 Mar 22 2021 # README
-rwxr-xr-x 1 root root 22467912 Aug 12 2021 Yearning
-rw-r--r-- 1 root root 21531105 Jul 6 16:09 Yearning-2.3.5-linux-amd64.zip
Yearning的配置文件为conf.toml,主要是用来连接刚刚创建的Yearning的数据库
[root@iZbp10iedgidvz3jgf4b27Z Yearning_workspace]# vim conf.toml
[Mysql]
Db = "Yearning"
Host = "127.0.0.1"
Port = "3306"
Password = "xxxxxxx"
User = "xxxx"
[General]
SecretKey = "dbcjqheupqjsuwsm"
Hours = 4
关于 SecretKey SecretKey 是 token/数据库密码加密/解密的 salt。
建议所有用户在初次安装 Yearning 之前将 SecretKey 更改(不更改将存在安全风险)
格式: 大小写字母均可, 长度必须为 16 位 如长度不是16位将会导致无法新建数据源
特别注意:
此 key 仅可在初次安装时更改!之后不可再次更改!如再次更改会导致之前已存放的数据源密码无法解密,最终导致无法获取相关数据源信息
[root@iZbp10iedgidvz3jgf4b27Z Yearning_workspace]# ./Yearning --help Yearning Mysql数据审核平台 (Version: 2.3.4 Neptune) Usage: ./Yearning [Global Options...] {command} [--option ...] [argument ...] Global Options: -h, --help Display the help information --no-color Disable color when outputting message --no-interactive Disable interactive confirmation operations --no-progress Disable display progress message --verbose Set error reporting level(quiet 0 - 4 debug) (default 1) -V, --version Display app version information Available Commands: genac Generate auto complete scripts for current application (alias: gen-ac) install Yearning安装及数据初始化 migrate 破坏性版本升级修复 reset_super 重置超级管理员密码 run 启动Yearning help Display help information Use "./Yearning {COMMAND} -h" for more information about a command [root@iZbp10iedgidvz3jgf4b27Z Yearning_workspace]# ./Yearning install 初始化成功! 用户名: admin 密码:Yearning_admin
也可以nohup ./Yearning run &后台来启动
[root@iZbp10iedgidvz3jgf4b27Z Yearning_workspace]# ./Yearning run
检查更新.......
数据已更新!
__ __
_ \/ /_________
__ /_ _ \ _ \
_ / / __/ __/
/_/ \___/\___/ yee v0.2.3
-----Easier and Faster-----
Creator: Henry Yee
到这里Yearning sql审核平台就部署完成了,我们可以通过http://ip:8000去访问Yearning平台(8000是默认端口)
下面开始使用Yearning sql平台,接入数据库、创建用户、流程模板 设置权限、并使用创建的用户提交要执行的sql语句,审批通过之后,再由运维执行sql;
在添加数据源时可以选择数据源的读写类型,这个读写类型可以定义后面用户是否可以提交sql查询或者sql写入;
一般流程都是先通过审核然后再进行执行的,所以必须要由“审核类型”阶段,否则后面执行完的sql不会生成回滚语句!!
这里是设置执行sql的权限
这里角色有两个,一个是提交人,一个操作人(负责审批);
加入develop权限组
点击提交工单;
我这里的审批和执行人都是admin,所以审批和执行操作都在admin账号上执行;
审核人:
点击"详情"即可看到工单的详细信息以及要执行的sql语句
执行人:
点击工单的"详情"即可看到工单的审批流以及要执行的sql语句
执行sql之后工单的状态就会变成已执行,相同,提交人的工单状态也会变;
在执行完成的sql工单里,会自动给我们生成回滚语句(提交人,审核人,执行人都能看到),当新添加的sql执行完有问题,需要立马回滚时,执行人可直接立即提单回滚,相同,审核人和提交人也可以提回滚单;
提完工单后,将会在审批人这里看到,审批人的操作就跟上面的操作一样检测sql转给执行人,执行人再执行回滚sql;
最后在管理账号下可以设置sql语句的审批规则,大家按照需求来设置即可;
yearning项目代码地址:
https://github.com/cookieY/Yearning
yearning安装手册:
https://guide.yearning.io/install.html
yearning官网:
https://yearning.io
https://pan.baidu.com/s/1Kx7gXFEB7g51rnOyNCfr3w?pwd=7777
提取码:7777
以上就是Yearning SQL审计平台的部署和使用了,这个平台真的是蛮好用的,版本也在一直升级中,期待未来的版本;
后面有时间了我会把最新版的v3.0.1部署方式和使用单开一篇帖子写出来,其实两种版本的使用方法差不了多少,只是新版本得去拉取前后端代码然后编译后再运行,还有一点就是源码编译部署的话需要将Juno服务单独运行(主要负责审核sql语句);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。