Salamek / gitlab-tools

Web application providing tools not avaiable in GitLab CE (Gitlab push/pull mirror and more)
GNU General Public License v3.0
99 stars 15 forks source link

fingerprint/new : We are sorry but request failed. Check console for more information #20

Closed rhinoceros closed 5 years ago

rhinoceros commented 5 years ago

I run development env using docker container. base image is: python:3.5-stretch

gitlab_tools/tools/crypto.py I add my_transport.banner_timeout = 300 to fix request-new-key error

def get_remote_server_key(ip: str, port: int=22) -> paramiko.pkey.PKey:
    """
    Returns PKey for given server
    :param ip: IP or Hostname
    :param port: Port
    :return: Returns PKey
    """
    print(ip)
    print(port)
    my_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    my_socket.settimeout(10)
    my_socket.connect((ip, port))

    my_transport = paramiko.Transport(my_socket)
    print(my_transport.banner_timeout)
    my_transport.banner_timeout = 300
    print(my_transport.banner_timeout)
    my_transport.start_client()
    ssh_key = my_transport.get_remote_server_key()

    my_transport.close()
    my_socket.close()
    return ssh_key

console output:

I0325 08:52:33.644 2606 gitlab_tools.py:136] Server is running at http://0.0.0.0:5000/
I0325 08:52:33.645 2606 gitlab_tools.py:137] Flask version: 1.0.2
I0325 08:52:33.645 2606 gitlab_tools.py:138] DEBUG: True
I0325 08:52:33.645 2606 gitlab_tools.py:139] STATIC_FOLDER: /var/app/gitlab-tools/gitlab_tools/static
W0325 08:52:33.692 2606 _internal.py:97]  * Debugger is active!
I0325 08:52:33.693 2606 _internal.py:97]  * Debugger PIN: 266-783-398
D0325 08:52:38.310 2606 transport.py:1746] starting thread (client mode): 0x44dacd68
D0325 08:52:38.311 2606 transport.py:1746] Local version/idstring: SSH-2.0-paramiko_2.4.2
D0325 08:52:38.315 2606 transport.py:1746] Banner: HTTP/1.1 400 Bad Request
D0325 08:52:38.315 2606 transport.py:1746] Banner: Server: nginx
D0325 08:52:38.316 2606 transport.py:1746] Banner: Date: Mon, 25 Mar 2019 08:52:38 GMT
D0325 08:52:38.316 2606 transport.py:1746] Banner: Content-Type: text/html
D0325 08:52:38.316 2606 transport.py:1746] Banner: Content-Length: 166
D0325 08:52:38.317 2606 transport.py:1746] Banner: Connection: close
D0325 08:52:38.317 2606 transport.py:1746] Banner: 
D0325 08:52:38.317 2606 transport.py:1746] Banner: <html>
D0325 08:52:38.318 2606 transport.py:1746] Banner: <head><title>400 Bad Request</title></head>
D0325 08:52:38.318 2606 transport.py:1746] Banner: <body bgcolor="white">
D0325 08:52:38.318 2606 transport.py:1746] Banner: <center><h1>400 Bad Request</h1></center>
D0325 08:52:38.319 2606 transport.py:1746] Banner: <hr><center>nginx</center>
D0325 08:52:38.319 2606 transport.py:1746] Banner: </body>
D0325 08:52:38.320 2606 transport.py:1746] Banner: </html>
E0325 08:52:38.321 2606 transport.py:1746] Exception: Error reading SSH protocol banner
E0325 08:52:38.322 2606 transport.py:1744] Traceback (most recent call last):
E0325 08:52:38.322 2606 transport.py:1744]   File "/usr/local/lib/python3.5/site-packages/paramiko/transport.py", line 2138, in _check_banner
E0325 08:52:38.323 2606 transport.py:1744]     buf = self.packetizer.readline(timeout)
E0325 08:52:38.323 2606 transport.py:1744]   File "/usr/local/lib/python3.5/site-packages/paramiko/packet.py", line 367, in readline
E0325 08:52:38.323 2606 transport.py:1744]     buf += self._read_timeout(timeout)
E0325 08:52:38.324 2606 transport.py:1744]   File "/usr/local/lib/python3.5/site-packages/paramiko/packet.py", line 563, in _read_timeout
E0325 08:52:38.324 2606 transport.py:1744]     raise EOFError()
E0325 08:52:38.324 2606 transport.py:1744] EOFError
E0325 08:52:38.325 2606 transport.py:1744] 
E0325 08:52:38.325 2606 transport.py:1744] During handling of the above exception, another exception occurred:
E0325 08:52:38.325 2606 transport.py:1744] 
E0325 08:52:38.326 2606 transport.py:1744] Traceback (most recent call last):
E0325 08:52:38.326 2606 transport.py:1744]   File "/usr/local/lib/python3.5/site-packages/paramiko/transport.py", line 1966, in run
E0325 08:52:38.326 2606 transport.py:1744]     self._check_banner()
E0325 08:52:38.326 2606 transport.py:1744]   File "/usr/local/lib/python3.5/site-packages/paramiko/transport.py", line 2143, in _check_banner
E0325 08:52:38.326 2606 transport.py:1744]     "Error reading SSH protocol banner" + str(e)
E0325 08:52:38.327 2606 transport.py:1744] paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
E0325 08:52:38.327 2606 transport.py:1744] 
I0325 08:52:38.341 2606 _internal.py:97] 172.21.0.1 - - [25/Mar/2019 08:52:38] "POST /fingerprint/fingerprint-check HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/paramiko/transport.py", line 2138, in _check_banner
    buf = self.packetizer.readline(timeout)
  File "/usr/local/lib/python3.5/site-packages/paramiko/packet.py", line 367, in readline
    buf += self._read_timeout(timeout)
  File "/usr/local/lib/python3.5/site-packages/paramiko/packet.py", line 563, in _read_timeout
    raise EOFError()
EOFError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.5/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.5/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.5/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.5/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.5/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.5/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.5/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.5/site-packages/flask_login/utils.py", line 261, in decorated_view
    return func(*args, **kwargs)
  File "/var/app/gitlab-tools/gitlab_tools/views/fingerprint/index.py", line 176, in check_hostname_fingerprint
    return check_fingerprint_hostname(hostname_string)
  File "/var/app/gitlab-tools/gitlab_tools/views/fingerprint/index.py", line 40, in check_fingerprint_hostname
    found, remote_server_key = check_hostname(hostname, known_hosts_path)
  File "/var/app/gitlab-tools/gitlab_tools/tools/fingerprint.py", line 22, in check_hostname
    remote_server_key = get_remote_server_key(hostname)
  File "/var/app/gitlab-tools/gitlab_tools/tools/crypto.py", line 75, in get_remote_server_key
    my_transport.start_client()
  File "/usr/local/lib/python3.5/site-packages/paramiko/transport.py", line 587, in start_client
    raise e
  File "/usr/local/lib/python3.5/site-packages/paramiko/transport.py", line 1966, in run
    self._check_banner()
  File "/usr/local/lib/python3.5/site-packages/paramiko/transport.py", line 2143, in _check_banner
    "Error reading SSH protocol banner" + str(e)
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
Salamek commented 5 years ago

@rhinoceros

This is webserver response, not a SSH

 HTTP/1.1 400 Bad Request
D0325 08:52:38.315 2606 transport.py:1746] Banner: Server: nginx
D0325 08:52:38.316 2606 transport.py:1746] Banner: Date: Mon, 25 Mar 2019 08:52:38 GMT
D0325 08:52:38.316 2606 transport.py:1746] Banner: Content-Type: text/html
D0325 08:52:38.316 2606 transport.py:1746] Banner: Content-Length: 166
D0325 08:52:38.317 2606 transport.py:1746] Banner: Connection: close
D0325 08:52:38.317 2606 transport.py:1746] Banner: 
D0325 08:52:38.317 2606 transport.py:1746] Banner: <html>
D0325 08:52:38.318 2606 transport.py:1746] Banner: <head><title>400 Bad Request</title></head>
D0325 08:52:38.318 2606 transport.py:1746] Banner: <body bgcolor="white">
D0325 08:52:38.318 2606 transport.py:1746] Banner: <center><h1>400 Bad Request</h1></center>
D0325 08:52:38.319 2606 transport.py:1746] Banner: <hr><center>nginx</center>
D0325 08:52:38.319 2606 transport.py:1746] Banner: </body>
D0325 08:52:38.320 2606 transport.py:1746] Banner: </html>
rhinoceros commented 5 years ago

I see. Maybe it's an problem of "aliyun SLB". I will try to figure out it. Thanks. gitlab-tools-server --> aliyun SLB( LoadBalance) --> gitlab-server (aliyun ECS)