版本0.3.2
问题描述: jumpserver普通用户下载key后变成NoKey
问题解决:
(1) 查看templates/juser/user_detail.html源码,找到链接生成的代码如下
{% if user.username|key_exist %}
<td><a href="{% url 'key_down' %}?id={{ user.id }}" >下载</a></td>
{% else %}
<td><span style="color: #586b7d">NoKey</span></td>
{% endif %}
(2) 查看juser/urls.py
url(r'^key/down/$', 'down_key', name='key_down'),
(3) 查看juser/views.py
def down_key(request): if is_role_request(request, 'super'): uuid_r = request.GET.get('uuid', '') else: uuid_r = request.user.uuid if uuid_r: user = get_object(User, uuid=uuid_r) if user: username = user.username private_key_file = os.path.join(KEY_DIR, 'user', username+'.pem') print private_key_file if os.path.isfile(private_key_file): f = open(private_key_file) data = f.read() f.close() response = HttpResponse(data, content_type='application/octet-stream') response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(private_key_file) if request.user.role == 'CU': os.unlink(private_key_file) return response return HttpResponse('No Key File. Contact Admin. uuid: %s' % uuid_r)
也就是说,当用户的角色为CU(普通用户)时,下载后就会删掉key,所以注释以下两行后重启jumpserver即可解决
if request.user.role == 'CU':
os.unlink(private_key_file)