dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.42k stars 661 forks source link

--login-path argument not working #967

Closed karakays closed 3 years ago

karakays commented 3 years ago

I am having issues with mycli regarding the --login-path argument although same configuration works for mysql client. Command below fails and asks me password. On top of that, authentication fails even if the password is correct.

mycli --login-path=foo -D bar
Connecting to socket /tmp/mysql.sock, owned by user 
Password:

However, this works

mysql --login-path=foo -D bar

What could be the problem?

~ $ mysql --version
mysql  Ver 14.14 Distrib 5.7.32, for osx10.15 (x86_64) using  EditLine wrapper
~ $ mycli --version
Version: 1.23.2
gfrlv commented 3 years ago

Yes, it seems this login option is broken, we have been testing the decryption mechanism, but not the actual login procedure. I just pushed a fix, can you install mycli from git branch and check if it solves the problem?

pip install git+https://github.com/dbcli/mycli.git@pasenor/fix-mylogin-cnf
karakays commented 3 years ago

I saw that you already merged fix branch but I would like to test your fix if it would help. Only if you can tell me how to build from your commit (couldn't see anything related in CONTRIBUTING.md) I tried pip install -e . from master and tested it but it seems like it didn't help (mycli fails with same behavior)

gfrlv commented 3 years ago

That's bad news :(

pip install -e . from master

That should do the trick. Are you sure you are using the updated master and the correct credentials? Does ~/.mycli.log report any errors? Do you use mysql_config_editor to create the login path? There are few things that can go wrong

  1. we end up trying the wrong login method -- that should be fixed now
  2. there is an error reading the ~/.mylogin.cnf. Can you decrypt it with the following command?
    python -c"import os; from mycli.config import open_mylogin_cnf; print(open_mylogin_cnf(os.path.expanduser('~/.mylogin.cnf')).read())"
  3. we are using the wrong login file. It's either ~/.mylogin.cnf or wherever the MYSQL_TEST_LOGIN_FILE environment variable points to, do you have it set?
gfrlv commented 3 years ago

Also, are you sure the default client actually uses the login path and doesn't fall back on a different authentication method? Like, if you use the wrong login path, does it fail to login?

karakays commented 3 years ago

master is up to date. credentials are set through mysql_config_editor and seems to be correct as I am able to connect with mysql --login-path=foo. mysql doesn't ask for any password input. I would expect the same from mycli.

I have $MYSQL_HOME=~/.mysql and MYSQL_TEST_LOGIN_FILE=~/.mysql/mylogin.cnf.

I also tested the case after having $MYSQL_TEST_LOGIN_FILE copied to ~/.mylogin.cnf but nothing has changed (same error)

I am able to decrypt ~/.mysql/mylogin.cnf file with that command (import open_mylogin_cnf)

here are the logs from my attempts

2021-02-28 19:13:36,218 (79586/MainThread) mycli.main ERROR - traceback: 'Traceback (most recent call last):\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 424, in _connect\n    self.sqlexecute = SQLExecute(\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/sqlexecute.py", line 63, in __init__\n    self.connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/sqlexecute.py", line 121, in connect\n    conn = pymysql.connect(\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 353, in __init__\n    self.connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 633, in connect\n    self._request_authentication()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 907, in _request_authentication\n    auth_packet = self._read_packet()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 725, in _read_packet\n    packet.raise_for_error()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/protocol.py", line 221, in raise_for_error\n    err.raise_mysql_exception(self._data)\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/err.py", line 143, in raise_mysql_exception\n    raise errorclass(errno, errval)\npymysql.err.OperationalError: (1045, "Access denied for user \'stage-dev\'@\'localhost\' (using password: YES)")\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/click/termui.py", line 129, in prompt_func\n    return f("")\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/click/termui.py", line 54, in hidden_prompt_func\n    return getpass.getpass(prompt)\n  File "/usr/local/Cellar/python@3.9/3.9.2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/getpass.py", line 77, in unix_getpass\n    passwd = _raw_input(prompt, stream, input=input)\n  File "/usr/local/Cellar/python@3.9/3.9.2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/getpass.py", line 146, in _raw_input\n    line = input.readline()\nKeyboardInterrupt\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 447, in connect\n    _connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 431, in _connect\n    new_passwd = click.prompt(\'Password\', hide_input=True,\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/click/termui.py", line 147, in prompt\n    value = prompt_func(prompt)\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/click/termui.py", line 136, in prompt_func\n    raise Abort()\nclick.exceptions.Abort\n'
2021-02-28 19:15:21,017 (79733/MainThread) mycli.main ERROR - traceback: 'Traceback (most recent call last):\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 424, in _connect\n    self.sqlexecute = SQLExecute(\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/sqlexecute.py", line 63, in __init__\n    self.connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/sqlexecute.py", line 121, in connect\n    conn = pymysql.connect(\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 353, in __init__\n    self.connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 633, in connect\n    self._request_authentication()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 907, in _request_authentication\n    auth_packet = self._read_packet()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 725, in _read_packet\n    packet.raise_for_error()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/protocol.py", line 221, in raise_for_error\n    err.raise_mysql_exception(self._data)\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/err.py", line 143, in raise_mysql_exception\n    raise errorclass(errno, errval)\npymysql.err.OperationalError: (1045, "Access denied for user \'stage-dev\'@\'localhost\' (using password: YES)")\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 467, in connect\n    raise e\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 447, in connect\n    _connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 433, in _connect\n    self.sqlexecute = SQLExecute(\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/sqlexecute.py", line 63, in __init__\n    self.connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/sqlexecute.py", line 121, in connect\n    conn = pymysql.connect(\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 353, in __init__\n    self.connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 633, in connect\n    self._request_authentication()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 907, in _request_authentication\n    auth_packet = self._read_packet()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 725, in _read_packet\n    packet.raise_for_error()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/protocol.py", line 221, in raise_for_error\n    err.raise_mysql_exception(self._data)\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/err.py", line 143, in raise_mysql_exception\n    raise errorclass(errno, errval)\npymysql.err.OperationalError: (1045, "Access denied for user \'stage-dev\'@\'localhost\' (using password: YES)")\n'
2021-02-28 19:20:47,584 (80044/MainThread) mycli.main ERROR - traceback: 'Traceback (most recent call last):\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 424, in _connect\n    self.sqlexecute = SQLExecute(\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/sqlexecute.py", line 63, in __init__\n    self.connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/sqlexecute.py", line 121, in connect\n    conn = pymysql.connect(\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 353, in __init__\n    self.connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 633, in connect\n    self._request_authentication()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 907, in _request_authentication\n    auth_packet = self._read_packet()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/connections.py", line 725, in _read_packet\n    packet.raise_for_error()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/protocol.py", line 221, in raise_for_error\n    err.raise_mysql_exception(self._data)\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/pymysql/err.py", line 143, in raise_mysql_exception\n    raise errorclass(errno, errval)\npymysql.err.OperationalError: (1045, "Access denied for user \'stage-dev\'@\'localhost\' (using password: YES)")\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/click/termui.py", line 129, in prompt_func\n    return f("")\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/click/termui.py", line 54, in hidden_prompt_func\n    return getpass.getpass(prompt)\n  File "/usr/local/Cellar/python@3.9/3.9.2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/getpass.py", line 77, in unix_getpass\n    passwd = _raw_input(prompt, stream, input=input)\n  File "/usr/local/Cellar/python@3.9/3.9.2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/getpass.py", line 146, in _raw_input\n    line = input.readline()\nKeyboardInterrupt\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 447, in connect\n    _connect()\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 431, in _connect\n    new_passwd = click.prompt(\'Password\', hide_input=True,\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/click/termui.py", line 147, in prompt\n    value = prompt_func(prompt)\n  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/click/termui.py", line 136, in prompt_func\n    raise Abort()\nclick.exceptions.Abort\n'
karakays commented 3 years ago

Not sure if I followed your last questions but if I give invalid login_path to mysql, it doesn't fall back to any password input - it just fails with the following

~ $ mysql --login-path=not-exists --host=[host] --port=[port]
ERROR 1045 (28000): Access denied for user 'user@'host' (using password: NO)
gfrlv commented 3 years ago

Your log does not seem to refer to the current code:

2021-02-28 19:20:47,584 (80044/MainThread) mycli.main ERROR - traceback: 'Traceback (most recent call last):
  File "/usr/local/Cellar/mycli/1.23.2/libexec/lib/python3.9/site-packages/mycli/main.py", line 424, in _connect
    self.sqlexecute =

That code is on a different line now, line 424 in the trace suggests you are running version 1.23.2. Does starting mycli like this work?

python -c"from mycli.main import cli; cli()" --login-path=your-login-path
karakays commented 3 years ago

you are right. I can see it works now with import cli; clit() command. many thanks.

when is the next release expected?

gfrlv commented 3 years ago

sometime next week most likely, there is a critical mass of bug fixes waiting.

gfrlv commented 3 years ago

Released in version 1.24.1