💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Add documentation for API security, closes #627
davidmezzetti25fc8ad39c37
diff --git a/docs/api/extensions.md b/docs/api/customization.mdsimilarity index 53%rename from docs/api/extensions.mdrename to docs/api/customization.mdindex 64632ecf..5118048d 100644--- a/docs/api/extensions.md+++ b/docs/api/customization.md@@ -1,4 +1,10 @@-# Extensions+# Customization++The txtai API has a number of features out of the box that are designed to help get started quickly. API services can also be augmented with custom code and functionality. The two main ways to do this are with extensions and dependencies.++Extensions add a custom endpoint. Dependencies add middleware that executes with each request. See the sections below for more.++## ExtensionsWhile the API is extremely flexible and complex logic can be executed through YAML-driven workflows, some may prefer to create an endpoint in Python. API extensions define custom Python endpoints that interact with txtai applications.@@ -7,3 +13,7 @@ See the link below for a detailed example covering how to create an API extensio| Notebook | Description | ||:----------|:-------------|------:|| [Custom API Endpoints](https://github.com/neuml/txtai/blob/master/examples/51_Custom_API_Endpoints.ipynb) | Extend the API with custom endpoints | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/51_Custom_API_Endpoints.ipynb) |++## Dependencies++txtai has a default API token authorization method that works well in many cases. Dependencies can also add custom logic with each request. This could be an additional authorization step and/or an authentication method.diff --git a/docs/api/index.md b/docs/api/index.mdindex cb706fcc..5445a62d 100644--- a/docs/api/index.md+++ b/docs/api/index.md@@ -88,14 +88,6 @@ curl \-d '{"name":"sumfrench", "elements": ["https://github.com/neuml/txtai"]}'```-## HTTPS--The API service command specified earlier starts a Uvicorn server as a HTTP service on port 8000. To run a HTTPS service, consider the following options.--- [TLS Proxy Server](https://fastapi.tiangolo.com/deployment/https/). *Recommended choice*. With this configuration, the txtai API service runs as a HTTP service only accessible on the localhost/local network. The proxy server handles all encryption and redirects requests to local services. See this [example configuration](https://www.uvicorn.org/deployment/#running-behind-nginx) for more.--- [Uvicorn SSL Certificate](https://www.uvicorn.org/deployment/). Another option is setting the SSL certificate on the Uvicorn service. This works in simple situations but gets complex when hosting multiple txtai or other related services.-## Local instanceA local instance can be instantiated. In this case, a txtai application runs internally, without any network connections, providing the same consolidated functionality. This enables running txtai in Python with configuration.diff --git a/docs/api/security.md b/docs/api/security.mdnew file mode 100644index 00000000..cbe4a791--- /dev/null+++ b/docs/api/security.md@@ -0,0 +1,33 @@+# Security++The default implementation of an API service runs via HTTP and is fully open. If the service is being run as a prototype on an internal network, that may be fine. In most scenarios, the connection should at least be encrypted. Authorization is another built-in feature that requires a valid API token with each request. See below for more.++## HTTPS++The default API service command starts a Uvicorn server as a HTTP service on port 8000. To run a HTTPS service, consider the following options.++- [TLS Proxy Server](https://fastapi.tiangolo.com/deployment/https/). *Recommended choice*. With this configuration, the txtai API service runs as a HTTP service only accessible on the localhost/local network. The proxy server handles all encryption and redirects requests to local services. See this [example configuration](https://www.uvicorn.org/deployment/#running-behind-nginx) for more.++- [Uvicorn SSL Certificate](https://www.uvicorn.org/deployment/). Another option is setting the SSL certificate on the Uvicorn service. This works in simple situations but gets complex when hosting multiple txtai or other related services.++## Authorization++Authorization requires a valid API token with each API request. This token is sent as a HTTP `Authorization` header.++*Server*+```bash+CONFIG=config.yml TOKEN=<sha256 encoded token> uvicorn "txtai.api:app"+```++*Client*+```bash+curl \+ -X POST "http://localhost:8000/workflow" \+ -H "Content-Type: application/json" \+ -H "Authorization: Bearer <token>" \+ -d '{"name":"sumfrench", "elements": ["https://github.com/neuml/txtai"]}'+```++It's important to note that HTTPS **must** be enabled using one of the methods mentioned above. Otherwise, tokens will be exchanged as clear text.++Authentication and Authorization can be fully customized. See the [dependencies](../customization#dependencies) section for more.diff --git a/mkdocs.yml b/mkdocs.ymlindex 3c8cd588..2e0941db 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -113,8 +113,9 @@ nav:- api/index.md- Cluster: api/cluster.md- Configuration: api/configuration.md- - Extensions: api/extensions.md+ - Customization: api/customization.md- Methods: api/methods.md+ - Security: api/security.md- Cloud: cloud.md- Examples: examples.md- FAQ: faq.md