KeystoneAuth1

5.13.1 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates basic V3 password authentication using environment variables for credentials. It initializes a V3 password authentication plugin and creates a session, then attempts to retrieve an authentication token.

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}")

view raw JSON →