Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增选择本地文件上传密钥,上传后将密钥信息保存到数据库,连接时从数据库读取 #1303

Merged
merged 27 commits into from
Jan 13, 2022

Conversation

issacmark
Copy link
Contributor

@issacmark issacmark commented Dec 28, 2021

新增选择本地文件上传密钥,上传后将密钥信息保存到数据库,连接时从数据库读取

@codecov
Copy link

codecov bot commented Dec 28, 2021

Codecov Report

Merging #1303 (fe7fe9c) into master (c996a87) will decrease coverage by 0.06%.
The diff coverage is 51.51%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1303      +/-   ##
==========================================
- Coverage   78.00%   77.94%   -0.07%     
==========================================
  Files          79       80       +1     
  Lines       12236    12265      +29     
==========================================
+ Hits         9545     9560      +15     
- Misses       2691     2705      +14     
Impacted Files Coverage Δ
sql/engines/__init__.py 71.23% <ø> (ø)
sql/utils/ssh_tunnel.py 33.33% <28.57%> (-1.67%) ⬇️
sql/models.py 95.63% <50.00%> (-0.48%) ⬇️
sql/form.py 55.55% <55.55%> (ø)
sql/admin.py 92.64% <100.00%> (+0.10%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c996a87...fe7fe9c. Read the comment docs.

@LeoQuote
Copy link
Collaborator

这个好像只适用于单机部署, 多实例的时候怎么办?

@issacmark issacmark changed the title New pr 增加一个存放 ssh 隧道秘钥的专用目录,用户在配置 ssh 隧道时填秘钥名称即可 Dec 29, 2021
@issacmark
Copy link
Contributor Author

这个好像只适用于单机部署, 多实例的时候怎么办?

有道理,我再改改

@issacmark issacmark changed the title 增加一个存放 ssh 隧道秘钥的专用目录,用户在配置 ssh 隧道时填秘钥名称即可 新增选择本地文件上传密钥,上传后将密钥信息保存到数据库,连接时从数据库读取 Dec 31, 2021
Copy link
Owner

@hhyo hhyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢贡献,这个还需要补充下变更sql,以及如何做到平滑升级的说明

顺便问下这个pr主要解决的问题是什么,因为这块我个人没有使用,可能不了解痛点,再次感谢

sql/models.py Outdated
@@ -853,28 +864,3 @@ class Meta:
index_together = ('hostname_max', 'ts_min')
verbose_name = u'慢日志明细'
verbose_name_plural = u'慢日志明细'


class AuditEntry(models.Model):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块应该是其他pr合并到主干的,注意冲突处理

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来的方式:将密钥上传至 archery 部署的服务器目录,如果是docker部署的还需要传到容器卷挂载的目录下,如 downloads logs这种目录里,然后在后台天上这个目录的绝对路径,当部署多实例的时候就无法使用了,而且使用起来也不是特别便捷
修改后:由后台页面的上传按钮直接上传到keys目录,然后读取pkey的内容写入数据库的pkey字段,实际上每次连接都是从数据库获取pkey来连接

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前使用这个功能的用户应该都是把密钥上传到了部署 archery 服务的服务器上,升级时需要把密钥下载到本地,更新版本后编辑对应条目,重新选择文件上传即可。
变更sql:
ALTER TABLE archery.ssh_tunnel
ADD COLUMN pkey longtext NULL AFTER password;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前使用这个功能的用户应该都是把密钥上传到了部署 archery 服务的服务器上,升级时需要把密钥下载到本地,更新版本后编辑对应条目,重新选择文件上传即可。 变更sql: ALTER TABLE archery.ssh_tunnel ADD COLUMN pkey longtext NULL AFTER password;

辛苦增加到1.8.3的sql文件中

sql/models.py Outdated
@@ -99,14 +103,21 @@ class Tunnel(models.Model):
port = models.IntegerField('端口', default=0)
user = fields.EncryptedCharField(verbose_name='用户名', max_length=200, default='', blank=True, null=True)
password = fields.EncryptedCharField(verbose_name='密码', max_length=300, default='', blank=True, null=True)
pkey_path = fields.EncryptedCharField(verbose_name='密钥地址', max_length=300, default='', blank=True, null=True)
pkey = models.TextField(verbose_name="密钥", blank=True, null=True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否也采取加密存储的形式

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

密钥长度太长了,所以用了这个

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加密组件也支持text,可以调整下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯嗯 改成 EncryptedTextField 了

@issacmark issacmark requested a review from hhyo January 6, 2022 01:53
@hhyo hhyo merged commit d9763eb into hhyo:master Jan 13, 2022
@@ -13,3 +13,6 @@ CREATE TABLE `audit_log` (
-- 新增my2sql菜单权限
set @content_type_id=(select id from django_content_type where app_label='sql' and model='permission');
INSERT INTO auth_permission (name, content_type_id, codename) VALUES ('菜单 My2SQL', @content_type_id, 'menu_my2sql');

-- ssh 隧道功能修改
ALTER TABLE `ssh_tunnel` ADD COLUMN pkey longtext NULL AFTER password DEFAULT CHARSET=utf8mb4 COMMENT='密钥信息';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个语句存在语法错误,还有pkey_path变成了filefield,确认下是否需要调整字段格式

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants