aker-gateway / Aker

SSH bastion/jump host/jumpserver
Other
567 stars 81 forks source link

AttributeError: 'NoneType' object has no attribute 'write' #40

Closed kaushalshriyan closed 6 years ago

kaushalshriyan commented 7 years ago

Hi Ahmed,

I am running Aker SSH bastion/jump host application on CentOS release 6.9 (Final) having Python 2.6.6 version. I am encountering the below issue when i select the specific hostname from the Aker tui console. I have attached the screenshot for your reference.

screen shot 2017-05-30 at 4 41 16 pm

ssh 172.16.0.23 /usr/bin/aker/aker.py:52: DeprecationWarning: You passed a bytestring as filenames. This will not work on Python 3. Use cp.read_file() or switch to using Unicode strings across the board. self.configparser.read(filename) /usr/bin/aker/hosts.py:70: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 logging.error("Hosts: all subsequent calls will fallback to backened idp, cache error: {0}".format(e.message)) /usr/bin/aker/pyte/streams.py:353: DeprecationWarning: As of version 0.6.0 pyte.streams.ByteStream is an alias for pyte.streams.Stream. The former will be removed in pyte 0.6.1. "removed in pyte 0.6.1.", DeprecationWarning) /usr/bin/aker/snoop.py:159: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 logging.error("Sniffer: close session files error {0} ".format(e.message)) Traceback (most recent call last): File "/usr/bin/aker/aker.py", line 152, in Aker().build_tui() File "/usr/bin/aker/aker.py", line 124, in build_tui self.tui.start() File "/usr/bin/aker/tui.py", line 168, in start self.loop.run() File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 278, in run self._run() File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 376, in _run self.event_loop.run() File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 682, in run self._loop() File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 719, in _loop self._watch_files[fd]() File "/usr/lib/python2.6/site-packages/urwid/raw_display.py", line 393, in event_loop, callback, self.get_available_raw_input()) File "/usr/lib/python2.6/site-packages/urwid/raw_display.py", line 493, in parse_input callback(processed, processed_codes) File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 403, in _update self.process_input(keys) File "/usr/lib/python2.6/site-packages/urwid/main_loop.py", line 503, in process_input k = self._topmost_widget.keypress(self.screen_size, k) File "/usr/lib/python2.6/site-packages/urwid/wimp.py", line 643, in keypress return self._current_widget.keypress(size, key) File "/usr/lib/python2.6/site-packages/urwid/container.py", line 1128, in keypress return self.body.keypress( (maxcol, remaining), key ) File "/usr/lib/python2.6/site-packages/urwid/container.py", line 1128, in keypress return self.body.keypress( (maxcol, remaining), key ) File "/usr/lib/python2.6/site-packages/urwid/listbox.py", line 987, in keypress key = focus_widget.keypress((maxcol,),key) File "/usr/bin/aker/tui.py", line 27, in keypress urwid.emit_signal(self, 'connect') File "/usr/lib/python2.6/site-packages/urwid/signals.py", line 264, in emit result |= self._call_callback(callback, user_arg, user_args, args) File "/usr/lib/python2.6/site-packages/urwid/signals.py", line 294, in _call_callback return bool(callback(*args_to_pass)) File "/usr/bin/aker/tui.py", line 60, in host_chosen self.aker.init_connection(choice) File "/usr/bin/aker/aker.py", line 142, in init_connection session.stop_sniffer() File "/usr/bin/aker/session.py", line 36, in stop_sniffer self._client.stop_sniffer() File "/usr/bin/aker/SSHClient.py", line 36, in stop_sniffer sniffer.stop() File "/usr/bin/aker/snoop.py", line 161, in stop self.log_file.write('Session End %s' % session_end) AttributeError: 'NoneType' object has no attribute 'write' Connection to 172.16.0.23 closed.

anazmy commented 7 years ago

Hi @kaushalshriyan

Which version are you running ?

Whats in /var/log/aker/aker.log at that time ?

kaushalshriyan commented 7 years ago

@anazmy I have the below files and directories

[root@aker aker]# pwd /usr/bin/aker [root@aker aker]# ll total 256 -rwxr-xr-x. 1 root root 2394 May 30 15:24 akerctl.py -rw-r--r--. 1 root root 318 May 30 15:24 aker.ini -rw-r--r--. 1 root root 76910 May 30 15:24 aker_logo.png -rwxr-xr-x. 1 root root 4294 May 30 15:24 aker.py -rw-r--r--. 1 root root 5711 May 30 19:41 aker.pyc -rw-r--r--. 1 root root 4208 May 30 15:24 CONTRIBUTING.md -rw-r--r--. 1 root root 903 May 30 15:24 hosts.json -rw-r--r--. 1 root root 3875 May 30 15:24 hosts.py -rw-r--r--. 1 root root 4720 May 30 19:41 hosts.pyc drwxr-xr-x. 2 root root 4096 May 30 19:41 idp -rw-r--r--. 1 root root 1026 May 30 15:24 IdPFactory.py -rw-r--r--. 1 root root 1826 May 30 19:41 IdPFactory.pyc -rw-r--r--. 1 root root 35779 May 30 15:24 LICENSE.txt -rw-r--r--. 1 root root 1278 May 30 15:24 popup.py -rw-r--r--. 1 root root 2652 May 30 19:41 popup.pyc drwxr-xr-x. 2 root root 4096 May 30 19:41 pyte -rw-r--r--. 1 root root 4871 May 30 15:24 README.md -rw-r--r--. 1 root root 42 May 30 15:24 requirements.txt -rw-r--r--. 1 root root 1444 May 30 15:24 session.py -rw-r--r--. 1 root root 2793 May 30 19:41 session.pyc -rw-r--r--. 1 root root 7103 May 30 15:24 snoop.py -rw-r--r--. 1 root root 8022 May 30 19:41 snoop.pyc -rw-r--r--. 1 root root 4255 May 30 15:24 SSHClient.py -rw-r--r--. 1 root root 6047 May 30 19:41 SSHClient.pyc -rw-r--r--. 1 root root 0 May 30 15:24 test-requirements.txt -rw-r--r--. 1 root root 461 May 30 15:24 tox.ini -rw-r--r--. 1 root root 5316 May 30 15:24 tui.py -rw-r--r--. 1 root root 7023 May 30 19:41 tui.pyc [root@aker aker]#

Is there a way to find out the aker version which i am running on the server?

I was able to fix the issue. I was using IP in place of DNS name against "name" directive

"hosts": [{ "name": "app1.example.com", "hostname": "app1.example.com", "port": "22", "key": "~/.ssh/id_rsa", "groups": [ "lnxadmins" ] },

anazmy commented 7 years ago

good point , its on the top of /usr/bin/aker/aker.py

also whats output of ls -al /var/log/aker ?

kaushalshriyan commented 7 years ago

@anazmy

less /usr/bin/aker/aker.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#       Copyright 2016 ahmed@nazmy.io
#
# For license information see LICENSE.txt

# Meta
__version__ = '0.4.4'
__version_info__ = (0, 4, 4)
__license__ = "AGPLv3"
__license_info__ = {
    "AGPLv3": {
        "product": "aker",
        "users": 0, # 0 being unlimited
        "customer": "Unsupported",
        "version": __version__,
        "license_format": "1.0",
    }
}

ls -al /var/log/aker total 12 drwxrwxrwx. 3 root root 4096 May 30 19:07 . drwxr-xr-x. 12 root root 4096 May 30 18:46 .. drwxrwxrwx. 2 kaushalshriyan kaushalshriyan 4096 May 30 19:37 20170530 -rwxrwxrwx. 1 kaushalshriyan kaushalshriyan 0 May 30 15:39 aker.log

anazmy commented 7 years ago

thx @kaushalshriyan

please set logging to DEBUG in /etc/aker/aker.ini and retry , then provide /var/log/aker/aker.log

kaushalshriyan commented 7 years ago
[General]
log_level = DEBUG
ssh_port = 22

# Identity Provider to determine the list of available hosts
# options shipped are IPA, Json. Default is IPA
idp = Json
hosts_file = /etc/aker/hosts.json

# FreeIPA hostgroup name contatining Aker gateways
# to be excluded from hosts presented to user
gateway_group = gateways

ssh 172.16.0.23 /usr/bin/aker/aker.py:52: DeprecationWarning: You passed a bytestring as filenames. This will not work on Python 3. Use cp.read_file() or switch to using Unicode strings across the board. self.configparser.read(filename) /usr/bin/aker/hosts.py:70: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 logging.error("Hosts: all subsequent calls will fallback to backened idp, cache error: {0}".format(e.message)) /usr/bin/aker/pyte/streams.py:353: DeprecationWarning: As of version 0.6.0 pyte.streams.ByteStream is an alias for pyte.streams.Stream. The former will be removed in pyte 0.6.1. "removed in pyte 0.6.1.", DeprecationWarning) Last login: Tue May 30 19:41:14 2017 from 172.16.0.23

[root@aker aker]# ll total 4 drwxrwxrwx. 2 kaushalshriyan kaushalshriyan 4096 May 30 21:50 20170530 -rwxrwxrwx. 1 kaushalshriyan kaushalshriyan 0 May 30 15:39 aker.log [root@aker aker]#

[root@aker aker]# cd 20170530/ [root@aker 20170530]# cat kaushalshriyan_samba.example.com_214830_8ec79845-9453-46e8-866d-cd4f1826dd70.log Session Start 2017/05/30 21:48:30 Last login: Tue May 30 19:41:14 2017 from 172.16.0.23 [kaushalshriyan@samba ~]$ ls [kaushalshriyan@samba ~]$ pwd /home/kaushalshriyan [kaushalshriyan@samba ~]$ ls [kaushalshriyan@samba ~]$ cd /opt/ [kaushalshriyan@samba opt]$ [root@aker 20170530]#

@anazmy There is nothing in cat /var/log/aker/aker.log file and also i see lot of warning

/usr/bin/aker/aker.py:52: DeprecationWarning: You passed a bytestring as filenames. This will not work on Python 3. Use cp.read_file() or switch to using Unicode strings across the board. self.configparser.read(filename) /usr/bin/aker/hosts.py:70: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 logging.error("Hosts: all subsequent calls will fallback to backened idp, cache error: {0}".format(e.message)) /usr/bin/aker/pyte/streams.py:353: DeprecationWarning: As of version 0.6.0 pyte.streams.ByteStream is an alias for pyte.streams.Stream. The former will be removed in pyte 0.6.1. "removed in pyte 0.6.1.", DeprecationWarning)

Please do let me know if the above warning has to be taken care?

anazmy commented 7 years ago

/usr/bin/aker/aker.py:52: DeprecationWarning: You passed a bytestring as filenames. This will not work on Python 3.

Obviously you're using python 3 , Aker works with python 2.7 , please retry with python 2.7

kaushalshriyan commented 7 years ago

@anazmy I am running python 2.6.6 version

[root@aker ~]# python --version Python 2.6.6 [root@aker ~]#

anazmy commented 7 years ago

My bad , that's was wrong assumption from my side , Aker works with 2.7 , there are considerable changes between Python 2.6 and 2.7 , please try with Python 2.7

kaushalshriyan commented 7 years ago

@anazmy ok