-
Notifications
You must be signed in to change notification settings - Fork 863
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
Enable Token Authorization by default #3163
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not enable the token authentication plugin by default to avoid big code changes and copying/pasting Token class?
frontend/server/src/main/java/org/pytorch/serve/http/TokenAuthorizationHandler.java
Show resolved
Hide resolved
| InstantiationException | ||
| InvocationTargetException | ||
| ClassNotFoundException e) { | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
logger.error("TOKEN CLASS IMPORTED UNSUCCESSFULLY"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We could remove this since we no longer use the plugin approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept it so that when TorchServe starts users can see if the keyfile was created successfully if enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will be able to see this through line 98
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats more important is that we fail in case the token auth setup could not be completed. The exception message need to be adapted here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also better to be more specific about which exception to catch.
I feel that if we are implementing token authorization as default it makes sense to integrate it into the frontend rather than as an external plugin as there is no need for that. It would also make future changes painful since we would have to build the plugin jar and publish to maven. It makes sense to integrate and remove the plugin completely so rather then duplication of code its just moving. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add test for the priority b/w config file vs cmd, especially for the negative test cases (eg. conflict setting)?
Added the test and added more clarification in the docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please create an RFC like #3066 before merging
} else { | ||
checkTokenAuthorization(req, "management"); | ||
} | ||
} else if (tokenType == TokenType.INFERENCE) { | ||
checkTokenAuthorization(req, "inference"); | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this clause? Would we not get a ResourceNotFoundException()
even if we don't handle this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to prevent the token api from being called when token authorization is disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @namannandan is referring to that the last element in the chain will throw the exception:
httpRequestHandlerChain.setNextHandler(invalidRequestHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are not sufficient. We need to add disable through env variable and the different priorities. We also need to test updating the expired and not expired tokens (of both types).
I've left a bunch of other comments which are more related to a refactoring as we're e.g. introducing dependency cycles here. I'll create a follow up issue where we need to address these on a short timeline. We can ignore these for now as this is time sensitive but the testing needs to be improved before we can merge this.
frontend/server/src/main/java/org/pytorch/serve/http/TokenAuthorizationHandler.java
Show resolved
Hide resolved
} else { | ||
checkTokenAuthorization(req, "management"); | ||
} | ||
} else if (tokenType == TokenType.INFERENCE) { | ||
checkTokenAuthorization(req, "inference"); | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @namannandan is referring to that the last element in the chain will throw the exception:
httpRequestHandlerChain.setNextHandler(invalidRequestHandler); |
@@ -1203,6 +1230,10 @@ public String getWorkflowStore() { | |||
return workflowStore; | |||
} | |||
|
|||
public String isTokenDisabled() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we use a string here instead of boolean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using this function to set prop and prop takes strings not booleans.
Added new tests
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets go ahead with this with the expectation that #3185 is addressed in the short-term.
Description
Setting token authorization by default #3157
Users can disable using environment variables, command line, or with config.properties.
Check Documentation for examples
Tests
Updating all existing tests to disable token authorization except for token authorization tests in pytest