KeystoneAuth1
KeystoneAuth1 is the common authentication library for OpenStack clients, providing a standard way to handle authentication and service requests within the OpenStack ecosystem. It is designed to simplify writing new clients and works in conjunction with existing OpenStack clients. The current stable version is 5.13.1, with releases typically tied to the OpenStack development cycle, offering frequent updates and bug fixes.
Warnings
- breaking Migration from `python-keystoneclient` to `keystoneauth1` required significant import path changes and a different API for session management. The `Session` class moved from `keystoneclient.session` to `keystoneauth1.session`.
- gotcha Encountering `keystoneauth1.exceptions.discovery.DiscoveryFailure` often indicates an incorrect `auth_url`, a misconfigured Keystone endpoint, or issues with SSL certificate verification. The error message 'Could not find versioned identity endpoints when attempting to authenticate' is common.
- gotcha When working with SSL/TLS, `keystoneauth1` might raise `SSLError` or `ConnectionError` if certificate verification fails or the connection times out. This can be due to self-signed certificates, missing CA certificates, or network issues.
Install
-
pip install keystoneauth1
Imports
- Password
from keystoneauth1.identity import v3; auth = v3.Password(...)
- Session
from keystoneauth1 import session; sess = session.Session(...)
- Adapter
from keystoneauth1.adapter import Adapter
Quickstart
import os
from keystoneauth1 import session
from keystoneauth1.identity import v3
# Environment variables for authentication
OS_AUTH_URL = os.environ.get('OS_AUTH_URL', 'http://localhost:5000/v3')
OS_USERNAME = os.environ.get('OS_USERNAME', 'admin')
OS_PASSWORD = os.environ.get('OS_PASSWORD', 'password')
OS_PROJECT_NAME = os.environ.get('OS_PROJECT_NAME', 'admin')
OS_USER_DOMAIN_NAME = os.environ.get('OS_USER_DOMAIN_NAME', 'Default')
OS_PROJECT_DOMAIN_NAME = os.environ.get('OS_PROJECT_DOMAIN_NAME', 'Default')
# Configure authentication plugin
auth = v3.Password(
auth_url=OS_AUTH_URL,
username=OS_USERNAME,
password=OS_PASSWORD,
project_name=OS_PROJECT_NAME,
user_domain_name=OS_USER_DOMAIN_NAME,
project_domain_name=OS_PROJECT_DOMAIN_NAME
)
# Create a session
sess = session.Session(auth=auth)
# Example: Authenticate and get a token (actual API calls would use sess.get(), sess.post(), etc.)
try:
token = sess.get_token()
print(f"Successfully authenticated. Token: {token[:10]}...")
except Exception as e:
print(f"Authentication failed: {e}")