Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
47397d23
Commit
47397d23
authored
May 28, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 修复网关测试连接需要ssh信任key的问题
parent
7b57d24d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
19 deletions
+16
-19
utils.py
apps/assets/utils.py
+15
-13
api.py
apps/perms/api.py
+1
-6
No files found.
apps/assets/utils.py
View file @
47397d23
# ~*~ coding: utf-8 ~*~
#
import
os
import
paramiko
from
paramiko.ssh_exception
import
SSHException
from
common.utils
import
get_object_or_none
from
.models
import
Asset
,
SystemUser
,
Label
...
...
@@ -49,22 +50,23 @@ def test_gateway_connectability(gateway):
"""
client
=
paramiko
.
SSHClient
()
client
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
proxy_command
=
[
"ssh"
,
"{}@{}"
.
format
(
gateway
.
username
,
gateway
.
ip
),
"-p"
,
str
(
gateway
.
port
),
"-W"
,
"127.0.0.1:{}"
.
format
(
gateway
.
port
),
]
if
gateway
.
password
:
proxy_command
.
insert
(
0
,
"sshpass -p '{}'"
.
format
(
gateway
.
password
))
if
gateway
.
private_key
:
proxy_command
.
append
(
"-i {}"
.
format
(
gateway
.
private_key_file
))
proxy
=
paramiko
.
SSHClient
()
proxy
.
load_host_keys
(
os
.
path
.
expanduser
(
'~/.ssh/known_hosts'
))
proxy
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
try
:
sock
=
paramiko
.
ProxyCommand
(
" "
.
join
(
proxy_command
))
except
paramiko
.
ProxyCommandFailure
as
e
:
proxy
.
connect
(
gateway
.
ip
,
username
=
gateway
.
username
,
password
=
gateway
.
password
,
pkey
=
gateway
.
private_key_obj
)
except
(
paramiko
.
AuthenticationException
,
paramiko
.
BadAuthenticationType
,
SSHException
)
as
e
:
return
False
,
str
(
e
)
sock
=
proxy
.
get_transport
()
.
open_channel
(
'direct-tcpip'
,
(
'127.0.0.1'
,
gateway
.
port
),
(
'127.0.0.1'
,
0
)
)
try
:
client
.
connect
(
"127.0.0.1"
,
port
=
gateway
.
port
,
username
=
gateway
.
username
,
...
...
apps/perms/api.py
View file @
47397d23
...
...
@@ -147,13 +147,8 @@ class UserGrantedNodeAssetsApi(ListAPIView):
user
=
get_object_or_404
(
User
,
id
=
user_id
)
else
:
user
=
self
.
request
.
user
node
=
get_object_or_404
(
Node
,
id
=
node_id
)
nodes
=
AssetPermissionUtil
.
get_user_nodes_with_assets
(
user
)
node
=
get_object_or_none
(
Node
,
id
=
node_id
)
if
not
node
:
unnode
=
[
node
for
node
in
nodes
if
node
.
name
==
'Unnode'
]
node
=
unnode
[
0
]
if
unnode
else
None
assets
=
nodes
.
get
(
node
,
[])
for
asset
,
system_users
in
assets
.
items
():
asset
.
system_users_granted
=
system_users
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment