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

Enable Token Authorization by default #3163

Merged
merged 29 commits into from
Jun 12, 2024
Merged

Enable Token Authorization by default #3163

merged 29 commits into from
Jun 12, 2024

Conversation

udaij12
Copy link
Collaborator

@udaij12 udaij12 commented May 29, 2024

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

@udaij12 udaij12 changed the title Token Enable Token Authorization by default May 30, 2024
@udaij12 udaij12 marked this pull request as ready for review May 30, 2024 06:00
Copy link
Collaborator

@lxning lxning left a 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?

docs/token_authorization_api.md Outdated Show resolved Hide resolved
| InstantiationException
| InvocationTargetException
| ClassNotFoundException e) {
} catch (Exception e) {
e.printStackTrace();
logger.error("TOKEN CLASS IMPORTED UNSUCCESSFULLY");
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Collaborator

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.

@udaij12
Copy link
Collaborator Author

udaij12 commented May 31, 2024

Why not enable the token authentication plugin by default to avoid big code changes and copying/pasting Token class?

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.

Copy link
Collaborator

@lxning lxning left a 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)?

@lxning lxning requested a review from agunapal June 4, 2024 04:31
@udaij12
Copy link
Collaborator Author

udaij12 commented Jun 4, 2024

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.

docs/token_authorization_api.md Show resolved Hide resolved
docs/token_authorization_api.md Show resolved Hide resolved
Copy link
Collaborator

@agunapal agunapal left a 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

docs/token_authorization_api.md Outdated Show resolved Hide resolved
docs/token_authorization_api.md Outdated Show resolved Hide resolved
docs/token_authorization_api.md Outdated Show resolved Hide resolved
docs/token_authorization_api.md Outdated Show resolved Hide resolved
} else {
checkTokenAuthorization(req, "management");
}
} else if (tokenType == TokenType.INFERENCE) {
checkTokenAuthorization(req, "inference");
}
} else {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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);
as not other Handler should handle "token".

@udaij12 udaij12 enabled auto-merge June 7, 2024 22:26
@mreso mreso disabled auto-merge June 7, 2024 22:44
Copy link
Collaborator

@mreso mreso left a 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.

docs/token_authorization_api.md Show resolved Hide resolved
docs/token_authorization_api.md Show resolved Hide resolved
docs/token_authorization_api.md Show resolved Hide resolved
} else {
checkTokenAuthorization(req, "management");
}
} else if (tokenType == TokenType.INFERENCE) {
checkTokenAuthorization(req, "inference");
}
} else {
Copy link
Collaborator

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);
as not other Handler should handle "token".

@@ -1203,6 +1230,10 @@ public String getWorkflowStore() {
return workflowStore;
}

public String isTokenDisabled() {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

test/pytest/test_token_authorization.py Show resolved Hide resolved
test/pytest/test_utils.py Show resolved Hide resolved
test/pytest/test_token_authorization.py Show resolved Hide resolved
ts_scripts/tsutils.py Show resolved Hide resolved
@udaij12
Copy link
Collaborator Author

udaij12 commented Jun 11, 2024

Added new tests

  1. generating new tokens once expired
  2. priority with env, cmd, and config properties
  3. priority with env and cmd

Copy link
Collaborator

@mreso mreso left a 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.

@mreso mreso added this pull request to the merge queue Jun 12, 2024
Merged via the queue into master with commit d622230 Jun 12, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants