Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'st2 login' exits with "success" 0 on failure #4338

Closed
arm4b opened this issue Sep 11, 2018 · 1 comment · Fixed by #4390
Closed

'st2 login' exits with "success" 0 on failure #4338

arm4b opened this issue Sep 11, 2018 · 1 comment · Fixed by #4390
Assignees
Milestone

Comments

@arm4b
Copy link
Member

arm4b commented Sep 11, 2018

Auth failure for st2 login command results in "success" exit code 0.

Example:

# st2 login 123 -p 123
Failed to log in as 123: 401 Client Error: Unauthorized
MESSAGE: Invalid or missing credentials for url: http://quoting-rabbit-st2auth-enterprise:9100/tokens

root@quoting-rabbit-st2client-enterprise-7ccdb7d457-xcp87:/opt/stackstorm# echo $?
0

Same applies if for example st2 login can't reach the st2api server, - the command fails with error message, but exit status is 0.
There could be some other similar issues with st2 login as well that needs a closer look and overhaul.

I however see the correct rc behavior from st2 auth CLI.

@Kami Kami added this to the 3.0.0 milestone Sep 24, 2018
@LindsayHill
Copy link
Contributor

I think the issue is here

    def run_and_print(self, args, **kwargs):
        try:
            self.run(args, **kwargs)
        except Exception as e:
            print('Failed to log in as %s: %s' % (args.username, str(e)))
            if self.app.client.debug:
                raise

            return

If you run the command with --debug, it raises an Exception, and returns with rc=1.

extreme@EWC:~$ st2 --debug login -p foobar st2admin
# -------- begin 139989912095760 request ----------
curl -X POST -H  'Connection: keep-alive' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: */*' -H  'User-Agent: python-requests/2.14.2' -H  'content-type: application/json' -H  'Content-Length: 2' -H  'Authorization: Basic c3QyYWRtaW46Zm9vYmFy' --data-binary '{}' http://127.0.0.1:9100/tokens
# -------- begin 139989912095760 response ----------
{
    "faultstring": "Invalid or missing credentials"
}
# -------- end 139989912095760 response ------------

Failed to log in as st2admin: 401 Client Error: Unauthorized
MESSAGE: Invalid or missing credentials for url: http://127.0.0.1:9100/tokens
ERROR: 401 Client Error: Unauthorized
MESSAGE: Invalid or missing credentials for url: http://127.0.0.1:9100/tokens

CLI settings:
----------------
Config file path: /home/extreme/.st2/config
Client settings:
----------------
ST2_BASE_URL: http://127.0.0.1
ST2_AUTH_URL: http://127.0.0.1:9100
ST2_API_URL: http://127.0.0.1:9101/v1
ST2_STREAM_URL: http://127.0.0.1:9102/v1
ST2_AUTH_TOKEN: None

Proxy settings:
---------------
HTTP_PROXY:
HTTPS_PROXY:

Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2client/shell.py", line 402, in run
    func(args)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2client/commands/auth.py", line 153, in run_and_print
    self.run(args, **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2client/commands/auth.py", line 124, in run
    manager = self.manager.create(instance, auth=(args.username, args.password), **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2client/models/core.py", line 40, in decorate
    return func(*args, **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2client/models/core.py", line 306, in create
    self.handle_error(response)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2client/models/core.py", line 166, in handle_error
    response.raise_for_status()
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/requests/models.py", line 928, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 401 Client Error: Unauthorized
MESSAGE: Invalid or missing credentials for url: http://127.0.0.1:9100/tokens
extreme@EWC:~$ echo $?
1
extreme@EWC:~$

But if you're not using debug, the RC is 0.

extreme@EWC:~$ st2 login -p foobar st2admin
Failed to log in as st2admin: 401 Client Error: Unauthorized
MESSAGE: Invalid or missing credentials for url: http://127.0.0.1:9100/tokens
extreme@EWC:~$ echo $?
0
extreme@EWC:~$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants