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

added code to only get a new logins on 401,403 or 415. #26

Closed

Conversation

open4storage
Copy link
Contributor

A new token is issue when there is a /whoami that returns non 200. The problem is that 404 for example are not invalid token and just a page that is not found. In such case a 404 will cause the ecsclient to login again. A long running code that produce 404s eventually exhaust all the tokens in the system.

@open4storage open4storage changed the title added code to only get a new logins in 401 or 403. added code to only get a new logins on 401 or 403. Mar 17, 2017
@coveralls
Copy link

coveralls commented Mar 17, 2017

Coverage Status

Coverage decreased (-0.1%) to 54.875% when pulling 2480ff6 on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

@coveralls
Copy link

coveralls commented Mar 17, 2017

Coverage Status

Coverage decreased (-0.1%) to 54.875% when pulling 58a395a on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 54.875% when pulling 58a395a on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

@coveralls
Copy link

coveralls commented Mar 17, 2017

Coverage Status

Coverage decreased (-0.1%) to 54.875% when pulling 58a395a on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

@coveralls
Copy link

coveralls commented Mar 17, 2017

Coverage Status

Coverage decreased (-0.06%) to 54.953% when pulling 629b798 on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

@coveralls
Copy link

coveralls commented Mar 17, 2017

Coverage Status

Coverage decreased (-0.06%) to 54.953% when pulling acb9fa9 on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

@padthaitofuhot
Copy link
Contributor

@adrianmo this looks good, recommend merge.

if req.status_code == requests.codes.ok:
log.debug("Token is valid")
return token
if req.status_code == 401 or req.status_code == 403:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are assuming that if status code is not 401 or 403 it'll be a 200 OK response, but we may get another response from the server, like a 500 server error.

I like the fact of getting a new token only for 401 and 403 codes, but we should raise an exception if code != 200.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, @open4storage have you checked what status code ECS returns when the token is invalid/expired. It should only be 401 Unauthorized, not 403. 403 Forbidden means that the token is valid (user is authenticated) but the user has no permissions to access that resource.

@coveralls
Copy link

coveralls commented Mar 20, 2017

Coverage Status

Coverage decreased (-0.07%) to 54.936% when pulling 5e7a1b6 on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

@coveralls
Copy link

coveralls commented Mar 20, 2017

Coverage Status

Coverage decreased (-0.07%) to 54.936% when pulling ab9c5a7 on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) to 54.936% when pulling ab9c5a7 on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) to 54.936% when pulling ab9c5a7 on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 54.693% when pulling 0842ed9 on open4storage:fix-token-leak-on-non-200 into ae488d4 on EMCECS:master.

@open4storage open4storage changed the title added code to only get a new logins on 401 or 403. added code to only get a new logins on 401,403 or 415. Mar 21, 2017
if req.status_code == requests.codes.ok:
log.debug("Token is valid")
if req.status_code == 200:
msg = "Token validation error. Code returned: {0}".format(req.status_code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log message should be "Token validated successfully" or similar.

return token

elif req.status_code in [401, 403, 415]:
msg = "Token validation error. Code returned: {0}".format(req.status_code)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message should be "Invalid token. Trying to get a new one" or similar.

@@ -98,13 +98,29 @@ def get_token(self):
token = self._get_existing_token()

if token:
'''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to a single line comment with the pound sign (#)?

else: # i.e. 500 or unknown raise an exception
msg = "Token validation error. Code returned: {0}".format(req.status_code)
log.error(msg)
raise ECSClientException(msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception should be raised from the response like this:

raise ECSClientException.from_response(req, message=msg)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we should also add a couple of test cases to validate this new behaviour.

@adrianmo
Copy link
Contributor

adrianmo commented Mar 22, 2017

This PR was manually squashed and merged in commit 47a6152

@adrianmo adrianmo closed this Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants