Registry / auth-security / keystonemiddleware

keystonemiddleware

JSON →
library13.0.0pypypiunverified

Keystonemiddleware provides WSGI middleware components for OpenStack Identity (Keystone) integration. It enables services to authenticate requests against Keystone, handle tokens, and authorize access based on user roles and projects. The current stable version is 12.0.0, and it follows the OpenStack release cycle, typically releasing new versions with each OpenStack cycle, leading to several major releases per year.

pip install keystonemiddleware
INSTALL
IMPORT
SIG · KEYSTONEMIDDLEWARE
K
keystonemiddleware
auth-securitypythonv13.0.0
Install
6.2s avg
Import
Disk
61MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v13.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 55.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 6.2s · import 0.000s · 57MB
61MB installed
● package 61MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AuthTokenMiddleware
from keystonemiddleware.auth_token import AuthTokenMiddleware
from keystonemiddleware.auth_token import AuthTokenMiddleware

This quickstart demonstrates how to wrap a simple WSGI application with the `AuthToken` middleware. It uses environment variables for configuration to make it runnable without hardcoding credentials. For `AuthToken` to function, a running Keystone instance and optionally Memcached (for token caching) are required. The example shows how to access user and project IDs populated by the middleware from the WSGI `environ`.

import os from wsgiref.simple_server import make_server from keystonemiddleware.auth_token import AuthToken def simple_app(environ, start_response): """Simplest possible WSGI application""" status = '200 OK' headers = [('Content-type', 'text/plain; charset=utf-8')] start_response(status, headers) # AuthToken populates these if a valid token is provided user_id = environ.get('HTTP_X_USER_ID', 'Unknown User ID') project_id = environ.get('HTTP_X_PROJECT_ID', 'Unknown Project ID') return [f"Hello, user '{user_id}' from project '{project_id}' via keystonemiddleware!\n".encode('utf-8')] # Configuration for AuthToken (simplified, typically from paste.ini or configuration files) # IMPORTANT: Replace with your actual Keystone endpoint and user/project details. # For production, avoid 'insecure=True' and set 'memcached_servers'. auth_config = { 'auth_url': os.environ.get('OS_AUTH_URL', 'http://localhost:5000/v3'), 'username': os.environ.get('OS_USERNAME', 'admin'), 'password': os.environ.get('OS_PASSWORD', 'secret'), 'project_name': os.environ.get('OS_PROJECT_NAME', 'admin'), 'user_domain_name': os.environ.get('OS_USER_DOMAIN_NAME', 'Default'), 'project_domain_name': os.environ.get('OS_PROJECT_DOMAIN_NAME', 'Default'), 'memcached_servers': os.environ.get('MEMCACHED_SERVERS', '127.0.0.1:11211'), # Required for caching 'insecure': 'True' if os.environ.get('OS_INSECURE') else 'False', # Use only for testing/development 'delay_auth_decision': 'True' # Allows app to handle unauthenticated requests if needed } # Wrap the application with AuthToken middleware application = AuthToken(simple_app, auth_config) if __name__ == '__main__': httpd = make_server('', 8000, application) print("Serving on port 8000...") print("Access with a valid X-Auth-Token header to see user info:") print(" curl -H \"X-Auth-Token: <your-keystone-token>\" http://localhost:8000/") print("Or with no token (if 'delay_auth_decision' is True):") print(" curl http://localhost:8000/") print("Ensure memcached is running if configured, e.g., 'sudo apt install memcached' and 'systemctl start memcached'.") print("Configure environment variables like OS_AUTH_URL, OS_USERNAME, OS_PASSWORD, etc. for actual Keystone integration.") httpd.serve_forever()
Debug
Known issues
breakingPython 3.10 or higher is now required for keystonemiddleware 12.0.0. Older Python versions are no longer supported.
fix
Upgrade your Python environment to 3.10 or newer. If you cannot upgrade Python, consider using an older `keystonemiddleware` version (e.g., 11.x for Python 3.9).
affects: 12.0.0+
gotchaThe `AuthToken` middleware now strictly requires `memcached_servers` to be configured for efficient token caching. If not set, token validation can be slow or fail under load.
fix
Ensure `memcached_servers` is configured with the address(es) of your Memcached server(s) (e.g., `memcached_servers = 127.0.0.1:11211`) in your `AuthToken` configuration. Ensure Memcached is running and accessible.
affects: 12.0.0+
deprecatedThe `keystonemiddleware.multiformats` module has been deprecated and its functionality has been moved to `oslo_middleware.base.RequestBodySizeLimiter`.
fix
Update your code to use `oslo_middleware.base.RequestBodySizeLimiter` for request body size limiting instead of `keystonemiddleware.multiformats`. Check the `oslo.middleware` documentation for usage details.
affects: 11.0.0+
gotchaIncorrect or missing `auth_url`, `www_authenticate_uri`, or service catalog type/name can lead to authentication failures or delays during discovery.
fix
Double-check your Keystone configuration parameters, especially `auth_url` (Keystone endpoint URL, e.g., `http://<keystone-ip>:5000/v3`) and `www_authenticate_uri` (usually the same as `auth_url`). Ensure the service catalog type and name match your Keystone setup.
affects: all
Upgrade
Version history
13.0.0latest on PyPI · released May 13, 2026
Audit
Dependencies
keystoneauth1requiredCore library for interacting with Keystone for authentication.
oslo.configrequiredCommon dependency for OpenStack projects, used for configuration management.
Agent activity
20 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
keystonemiddleware — pip install keystonemiddleware · libregistry