Security

Security

DeepStack allows you to protect your api endpoints with keys to prevent unauthorized access.

You can set two types of keys: API Key and Admin Key

The API Key protects all recognition and detection endpoints including face, scene, object detection and custom models. The admin key protects admin apis such as adding models, deleting models, list models, backup and restore.

Setting API Key

You can specify the api key during startup of deepstack

CPU Version
GPU Version
sudo docker run -e API-KEY=Mysecretkey -e VISION-SCENE=True -v localstorage:/datastore -p 80:5000 deepquestai/deepstack
sudo docker run --rm --runtime=nvidia -e API-KEY=Mysecretkey -e VISION-SCENE=True -v localstorage:/datastore -p 80:5000 deepquestai/deepstack:gpu

On Raspberry PI, specify the key as below.

sudo deepstack start "VISION-SCENE=True API-KEY=Mysecretkey"

On Windows, simply type in the API Key in the Start Up Interface

The command -e API-KEY=Mysecretkey sets “Mysecretkey” as the api key.

Below we shall attempt to classify the scene of the image below without specifying the key.

_images/test-image10.jpg
import requests
image_data = open("test-image10.jpg","rb").read()
response = requests.post("http://localhost:80/v1/vision/scene",
files={"image":image_data}).json()
print(response)

Response:

{'success': False, 'error': 'Incorrect api key'}

As seen above, the prediction fails returning incorrect api key

Below, we make the request with the api key specified

import requests
image_data = open("test-image10.jpg","rb").read()
response = requests.post("http://localhost:80/v1/vision/scene",
files={"image":image_data}, data={"api_key":"Mysecretkey"}).json()
print(response)

Response:

{'success': True, 'label': 'hospital_room', 'confidence': 0.4538608}

Setting Admin keys

Admin keys are set similarly to API Keys, see example below.

You can specify the admin key during startup of deepstack

CPU Version
GPU Version
sudo docker run -e ADMIN-KEY=Secretadminkey -e API-KEY=Mysecretkey -e VISION-SCENE=True -v localstorage:/datastore -p 80:5000 deepquestai/deepstack
sudo docker run --rm --runtime=nvidia -e ADMIN-KEY=Secretadminkey -e API-KEY=Mysecretkey -e VISION-SCENE=True -v localstorage:/datastore -p 80:5000 deepquestai/deepstack:gpu

The command -e ADMIN-KEY=Secretadminkey sets “Secretadminkey” as the admin key. In this example, the API key is also set, note that you can set either without setting the other.

On Raspberry PI, specify the key as below.

sudo deepstack start "VISION-SCENE=True ADMIN-KEY=Secretadminkey"

On Windows, simply type in the API Key in the Start Up Interface

Once you set an Admin key, you need to specify it when making admin calls such as backup, restore and model management.

Example below is for adding models.

import requests
from io import open
model = open("idenprof.pb","rb").read()
config = open("config.json","rb").read()
response = requests.post("http://localhost:80/v1/vision/addmodel",
files={"model":model,"config":config},data={"name":"profession","admin_key":"Secretadminkey"}).json()

Changing Keys

When you specify keys during startup of DeepStack, the keys will be stored and reused even if you run deepstack again without specifying a key.

This behaviour is slightly different for the Windows Version, if no key is provided in startup, it will not require any key for further requests.

You can easily change the keys by specifying new ones during startup of deepstack, you can also remove the keys by setting them to an empty string during startup.

Below, both keys are removed.

CPU Version
GPU Version
sudo docker run -e ADMIN-KEY="" -e API-KEY="" -e VISION-SCENE=True \
-v localstorage:/datastore -p 80:5000 deepquestai/deepstack
sudo docker run --rm --runtime=nvidia -e ADMIN-KEY="" -e API-KEY="" -e VISION-SCENE=True -v localstorage:/datastore -p 80:5000 deepquestai/deepstack:gpu

Next Previous