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

Allow using SSL between transformer and predictor/explainer #2911

Merged
merged 4 commits into from
May 18, 2023

Conversation

greenmoon55
Copy link
Contributor

@greenmoon55 greenmoon55 commented May 16, 2023

What this PR does / why we need it: Currently the transformer is hard-coded to use http to communicate with the predictor. We add a use_ssl property to Model class to allow using SSL between transformer and predictor/explainer for both rest and grpc.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2863

Type of changes
Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Feature/Issue validation/testing:

Please describe the tests that you ran to verify your changes and relevant result summary. Provide instructions so it can be reproduced.
Please also list any relevant details for your test configuration.

  • Run a local transformer with a remote predictor with REST v2 with ssl enabled. Make sure we get the inference result.
  • Run a local transformer with a remote predictor with GRPC with ssl enabled. Make sure we get the inference result.

Note that if you need a custom root CA, you can set an environment variable like this export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=bundle.pem

  • Logs

Special notes for your reviewer:

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.
    No.

Checklist:

  • Have you added unit/e2e tests that prove your fix is effective or that this feature works?
  • Has code been commented, particularly in hard-to-understand areas?
  • Have you made corresponding changes to the documentation?

Release note:

Added `use_ssl` property to `Model` to allow using SSL between transformer and predictor/explainer.

Signed-off-by: Jin Dong <jdong183@bloomberg.net>
@yuzisun
Copy link
Member

yuzisun commented May 16, 2023

Thanks @greenmoon55 ! Can you help update the local transformer testing instruction here for using https predictor url?
https://github.com/kserve/kserve/tree/master/docs/samples/v1beta1/transformer/torchserve_image_transformer#testing-with-a-local-transformer--predictor-in-kubernetes-kserve-developer-guide

@@ -232,9 +237,10 @@ def postprocess(self, response: Union[Dict, InferResponse, ModelInferResponse],
return response

async def _http_predict(self, payload: Union[Dict, InferRequest], headers: Dict[str, str] = None) -> Dict:
predict_url = PREDICTOR_URL_FORMAT.format(self.predictor_host, self.name)
protocol = "https" if self.use_ssl else "http"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have test cases for this function to verify if http or https is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not. I can't find a good way to add tests here. We have e2e tests for http but not for https.

@@ -311,9 +317,11 @@ async def explain(self, payload: Dict, headers: Dict[str, str] = None) -> Dict:
"""
if self.explainer_host is None:
raise NotImplementedError("Could not find explainer_host.")
explain_url = EXPLAINER_URL_FORMAT.format(self.explainer_host, self.name)

protocol = "https" if self.use_ssl else "http"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we have test cases for this function.

Signed-off-by: Jin Dong <jdong183@bloomberg.net>
Signed-off-by: Jin Dong <jdong183@bloomberg.net>
self.predictor_host = self.predictor_host + ":80"
_channel = grpc.aio.insecure_channel(self.predictor_host)
port = 443 if self.use_ssl else 80
self.predictor_host = self.predictor_host + f":{port}"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: both predictor_host and port can be in the fstring

Signed-off-by: Jin Dong <jdong183@bloomberg.net>
@@ -103,9 +104,12 @@ def postprocess(self, infer_response: Union[Dict, ModelInferResponse], headers:
parser.add_argument(
"--model_name", help="The name that the model is served under."
)
parser.add_argument(
"--use_ssl", help="Use ssl for connecting to the predictor", action='store_true'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be true with --use_ssl, otherwise False.

@yuzisun
Copy link
Member

yuzisun commented May 18, 2023

Great work @greenmoon55 !

/lgtm
/approve

@kserve-oss-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: greenmoon55, yuzisun

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kserve-oss-bot kserve-oss-bot merged commit 0d3e41d into kserve:master May 18, 2023
52 checks passed
@greenmoon55 greenmoon55 deleted the allow-ssl branch June 20, 2023 16:03
Iamlovingit pushed a commit to Iamlovingit/kserve that referenced this pull request Oct 1, 2023
)

* Allow using SSL between transformer and predictor/explainer

Signed-off-by: Jin Dong <jdong183@bloomberg.net>

* Update custom transformer example

Signed-off-by: Jin Dong <jdong183@bloomberg.net>

* Update document

Signed-off-by: Jin Dong <jdong183@bloomberg.net>

* Update doc and use f string format

Signed-off-by: Jin Dong <jdong183@bloomberg.net>

---------

Signed-off-by: Jin Dong <jdong183@bloomberg.net>
Signed-off-by: iamlovingit <freecode666@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow using SSL between transformer and predictor
4 participants