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

Add testing for basic auth plugin for HTTP/gRPC clients #5739

Merged
merged 4 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions qa/L0_grpc/grpc_basic_auth_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/python
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import unittest
import sys

sys.path.append("../common")

import test_util as tu
import tritonclient.grpc as tritongrpcclient
import tritonclient.grpc.aio as asynctritongrpcclient

from tritonclient.grpc.auth import BasicAuth
from tritonclient.grpc.aio.auth import BasicAuth as AsyncBasicAuth


class GRPCBasicAuthTest(tu.TestResultCollector):

def setUp(self):
# Use the nginx port
self._client = tritongrpcclient.InferenceServerClient(
url='localhost:8004')
self._client.register_plugin(BasicAuth('username', 'password'))

def test_client_call(self):
self.assertTrue(self._client.is_server_live())

def tearDown(self):
self._client.close()


class GRPCBasicAuthAsyncTest(unittest.IsolatedAsyncioTestCase):

async def asyncSetUp(self):
# Use the nginx port
self._client = asynctritongrpcclient.InferenceServerClient(
url='localhost:8004')
self._client.register_plugin(AsyncBasicAuth('username', 'password'))

async def test_client_call(self):
self.assertTrue(await self._client.is_server_live())

async def asyncTearDown(self):
await self._client.close()


if __name__ == '__main__':
unittest.main()
54 changes: 54 additions & 0 deletions qa/L0_grpc/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

worker_processes 1;

error_log /var/log/nginx/error.log;

events {
worker_connections 1024;
}

http {
# Configure basic authentication
auth_basic "Restricted Content";
auth_basic_user_file /opt/tritonserver/qa/L0_grpc/pswd;

# Define upstream server
upstream backend {
server localhost:8001;
}

# Define server block for reverse proxy
server {
listen 8004 http2;

# Configure location for reverse proxy
location / {
grpc_pass grpc://backend;
}
}
}
15 changes: 15 additions & 0 deletions qa/L0_grpc/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export CUDA_VISIBLE_DEVICES=0
RET=0

CLIENT_PLUGIN_TEST="./grpc_client_plugin_test.py"
BASIC_AUTH_TEST="./grpc_basic_auth_test.py"
NGINX_CONF="./nginx.conf"
# On windows the paths invoked by the script (running in WSL) must use
# /mnt/c when needed but the paths on the tritonserver command-line
# must be C:/ style.
Expand Down Expand Up @@ -352,6 +354,19 @@ if [ $? -ne 0 ]; then
RET=1
fi
set -e

# Create a password file with username:password
echo -n 'username:' > pswd
echo "password" | openssl passwd -stdin -apr1 >> pswd
nginx -c `pwd`/$NGINX_CONF

python3 $BASIC_AUTH_TEST
if [ $? -ne 0 ]; then
cat ${CLIENT_LOG}.python.plugin.auth
RET=1
fi
service nginx stop

kill $SERVER_PID
wait $SERVER_PID

Expand Down
71 changes: 71 additions & 0 deletions qa/L0_http/http_basic_auth_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/python
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import unittest
import sys

sys.path.append("../common")

import test_util as tu
import tritonclient.http as tritonhttpclient
import tritonclient.http.aio as asynctritonhttpclient

from tritonclient.http.auth import BasicAuth
from tritonclient.http.aio.auth import BasicAuth as AsyncBasicAuth


class HTTPBasicAuthTest(tu.TestResultCollector):

def setUp(self):
# Use the nginx port
self._client = tritonhttpclient.InferenceServerClient(
url='localhost:8004')
self._client.register_plugin(BasicAuth('username', 'password'))

def test_client_call(self):
self.assertTrue(self._client.is_server_live())

def tearDown(self):
self._client.close()


class HTTPBasicAuthAsyncTest(unittest.IsolatedAsyncioTestCase):

async def asyncSetUp(self):
# Use the nginx port
self._client = asynctritonhttpclient.InferenceServerClient(
url='localhost:8004')
self._client.register_plugin(AsyncBasicAuth('username', 'password'))

async def test_client_call(self):
self.assertTrue(await self._client.is_server_live())

async def asyncTearDown(self):
await self._client.close()


if __name__ == '__main__':
unittest.main()
57 changes: 57 additions & 0 deletions qa/L0_http/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

worker_processes 1;

error_log /var/log/nginx/error.log;

events {
worker_connections 1024;
}

http {
# Configure basic authentication
auth_basic "Restricted Content";
auth_basic_user_file /opt/tritonserver/qa/L0_http/pswd;

# Define upstream server
upstream backend {
server localhost:8000;
}

# Define server block for reverse proxy
server {
listen 8004;

# Configure location for reverse proxy
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
14 changes: 14 additions & 0 deletions qa/L0_http/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export CUDA_VISIBLE_DEVICES=0
RET=0

CLIENT_PLUGIN_TEST="./http_client_plugin_test.py"
BASIC_AUTH_TEST="./http_basic_auth_test.py"
NGINX_CONF="./nginx.conf"
# On windows the paths invoked by the script (running in WSL) must use
# /mnt/c when needed but the paths on the tritonserver command-line
# must be C:/ style.
Expand Down Expand Up @@ -240,6 +242,18 @@ if [ $? -ne 0 ]; then
RET=1
fi

# Create a password file with username:password
echo -n 'username:' > pswd
echo "password" | openssl passwd -stdin -apr1 >> pswd
nginx -c `pwd`/$NGINX_CONF

python3 $BASIC_AUTH_TEST
if [ $? -ne 0 ]; then
cat ${CLIENT_LOG}.python.plugin.auth
RET=1
fi
service nginx stop

# Test with the base path in url.
$SIMPLE_INFER_CLIENT -u localhost:8000/base_path -v >> ${CLIENT_LOG}.c++.base_path_url 2>&1
if [ $? -eq 0 ]; then
Expand Down