Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
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
coco
Commits
7a3ef527
Commit
7a3ef527
authored
Mar 25, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] Using gateway
parent
c0a47c33
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
6 deletions
+36
-6
interface.py
coco/interface.py
+1
-1
proxy.py
coco/proxy.py
+35
-5
No files found.
coco/interface.py
View file @
7a3ef527
...
...
@@ -114,7 +114,7 @@ class SSHInterface(paramiko.ServerInterface):
def
check_channel_forward_agent_request
(
self
,
channel
):
logger
.
debug
(
"Check channel forward agent request:
%
s"
%
channel
)
self
.
request
.
type
=
"forward-agent"
self
.
request
.
meta
=
{
'channel'
:
channel
}
self
.
request
.
meta
[
'channel'
]
=
channel
.
get_id
()
self
.
event
.
set
()
return
False
...
...
coco/proxy.py
View file @
7a3ef527
...
...
@@ -6,6 +6,8 @@ import socket
import
threading
import
time
import
weakref
import
os
import
paramiko
from
paramiko.ssh_exception
import
SSHException
...
...
@@ -16,7 +18,7 @@ from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning, \
logger
=
get_logger
(
__file__
)
TIMEOUT
=
8
TIMEOUT
=
10
BUF_SIZE
=
4096
...
...
@@ -84,17 +86,45 @@ class ProxyServer:
def
get_telnet_server_conn
(
self
,
asset
,
system_user
):
pass
def
make_proxy_command
(
self
,
asset
):
gateway
=
asset
.
domain
.
random_gateway
()
proxy_command
=
[
"ssh"
,
"-p"
,
str
(
gateway
.
port
),
"{}@{}"
.
format
(
gateway
.
username
,
gateway
.
ip
),
"-W"
,
"{}:{}"
.
format
(
asset
.
ip
,
asset
.
port
),
"-q"
,
]
if
gateway
.
password
:
proxy_command
.
insert
(
0
,
"sshpass -p {}"
.
format
(
gateway
.
password
))
if
gateway
.
private_key
:
gateway
.
set_key_dir
(
os
.
path
.
join
(
self
.
app
.
root_path
,
'keys'
))
proxy_command
.
append
(
"-i {}"
.
format
(
gateway
.
private_key_file
))
proxy_command
=
' '
.
join
(
proxy_command
)
return
proxy_command
def
get_ssh_server_conn
(
self
,
asset
,
system_user
):
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
sock
=
None
if
asset
.
domain
:
asset
.
domain
=
self
.
app
.
service
.
get_domain_detail_with_gateway
(
asset
.
domain
)
try
:
proxy_command
=
self
.
make_proxy_command
(
asset
)
sock
=
paramiko
.
ProxyCommand
(
proxy_command
)
except
(
paramiko
.
AuthenticationException
,
paramiko
.
BadAuthenticationType
,
SSHException
,
TimeoutError
)
as
e
:
logger
.
error
(
e
)
try
:
ssh
.
connect
(
asset
.
ip
,
port
=
asset
.
port
,
username
=
system_user
.
username
,
password
=
system_user
.
password
,
pkey
=
system_user
.
private_key
,
timeout
=
TIMEOUT
,
compress
=
True
,
auth_timeout
=
10
,
look_for_keys
=
False
timeout
=
TIMEOUT
,
compress
=
True
,
auth_timeout
=
TIMEOUT
,
look_for_keys
=
False
,
sock
=
sock
)
except
(
paramiko
.
AuthenticationException
,
paramiko
.
BadAuthenticationType
,
SSHException
,
TimeoutError
):
except
(
paramiko
.
AuthenticationException
,
paramiko
.
BadAuthenticationType
,
SSHException
):
admins
=
self
.
app
.
config
[
'ADMINS'
]
or
'administrator'
self
.
client
.
send
(
warning
(
wr
(
"Authenticate with server failed, contact {}"
.
format
(
admins
),
...
...
@@ -112,7 +142,7 @@ class ProxyServer:
password_short
,
key_fingerprint
,
))
return
None
except
socket
.
error
as
e
:
except
(
socket
.
error
,
TimeoutError
)
as
e
:
self
.
client
.
send
(
wr
(
" {}"
.
format
(
e
)))
return
None
finally
:
...
...
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