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

Run the command below as it applies to the version you have installed

sudo docker run -e API-KEY=Mysecretkey -e VISION-SCENE=True -v localstorage:/datastore -p 80:5000 deepquestai/deepstack

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.

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.

Run the command below as it applies to the version you have installed

sudo docker run -e ADMIN-KEY=Secretadminkey -e API-KEY=Mysecretkey -e VISION-SCENE=True -v localstorage:/datastore -p 80:5000 deepquestai/deepstack

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.

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()