Library interface — keystoneauth — branch stable/2026.2
Branch
stable/2026.2@1cd5400202c6(5.17.0+ 2 maintenance commits) — repository https://opendev.org/openstack/keystoneauth — analysed on 2026-10-28
keystoneauth (keystoneauth1) exposes no network service. It is the HTTP and authentication library shared by every OpenStack client and service: openstackclient, openstacksdk, keystonemiddleware, Nova (for Placement, Neutron, Cinder…), osc-placement. Its interface is a Python API and a set of authentication plugins. Its contract with the outside world is the requests it sends to Keystone and to the services (interactions, client contract).
1. Building blocks
| Block | Role | Source |
|---|---|---|
Session | sends every request: headers, authentication, endpoint lookup, retries, redirects, logging, timings | keystoneauth1/session.py:302-1660 |
Adapter | a Session bound to a service (service_type, interface, region_name, version, default_microversion, retries) | keystoneauth1/adapter.py |
auth plugins (BaseIdentityPlugin) | get, cache and renew a token; give the endpoints of the catalog; drive version discovery | keystoneauth1/identity/base.py:34-570 |
discover | parse version documents, choose a version and a microversion, combine URLs | keystoneauth1/discover.py |
access | AccessInfoV2/V3 (token and catalog read from the Keystone response), ServiceCatalog | keystoneauth1/access/access.py, keystoneauth1/access/service_catalog.py |
exceptions | HttpError hierarchy by status, connection and discovery errors | keystoneauth1/exceptions/ |
loading | build plugins, sessions and adapters from argparse options, oslo.config or a dict | keystoneauth1/loading/ |
2. Authentication plugins (entry points keystoneauth1.plugin, pyproject.toml:52-78)
Name (--os-auth-type) | What it sends to Keystone |
|---|---|
password, token (generic) | first version discovery on auth_url, then the v3 (or v2) variant (keystoneauth1/identity/generic/base.py) |
v3password, v3token | POST /v3/auth/tokens, method password (user by ID or by name + domain) or token |
v3applicationcredential | method application_credential (ID + secret, or name + user) |
v3totp, v3multifactor | totp method, or several methods in a single request; reacts to MFA receipts |
v3oidc* (5 variants), v3websso, v3samlpassword, v3adfspassword, v3fedkerb | federation: obtain an assertion or token from the IdP, then …/OS-FEDERATION/identity_providers/{idp}/protocols/{p}/auth, then rescoping |
v3oauth1, v3oauth2clientcredential, v3oauth2mtlsclientcredential | OAuth1; OAuth2 client_credentials at /v3/OS-OAUTH2/token (secret or mTLS certificate) |
v3kerberos, v3tokenlessauth | Kerberos (REMOTE_USER behind Apache); tokenless (client certificate + X-Project-* headers) |
admin_token, none, http_basic, v2password, v2token | fixed token; no authentication; HTTP Basic; Keystone v2 (obsolete) |
Scope (keystoneauth1/identity/v3/base.py:186-227): exactly one of project (ID, or name + domain), domain, trust, system: {all: true} or "unscoped", otherwise AuthorizationFailure before any call.
3. Behaviours of Session.request (keystoneauth1/session.py:744-1162)
- URL: an absolute URL is used as is. A relative path needs an
endpoint_filter, thenget_endpoint()goes through the plugin: catalog, then version discovery. - Headers:
User-Agent(keystoneauth1/<version> python-requests/…, plus the application);X-Auth-Tokenfrom the plugin (get_auth_headers);X-Openstack-Request-Idif aglobal_request_idis given;- microversion:
OpenStack-API-Version: <service_type> <version>, plus the legacy headersX-OpenStack-Nova-API-Version/X-OpenStack-Ironic-API-Version. The service type is normalised:volumefor Cinder,shared-file-systemfor Manila (keystoneauth1/session.py:683-742).
- Connection retries:
connect_retries(default 0), exponential delay from 0.5 s, capped at 60 s (keystoneauth1/session.py:62-64,keystoneauth1/session.py:280-300). - Status retries:
status_code_retries(default 0) onretriable_status_codes, 429 and 503 by default. - Redirects: handled by hand, up to 30 (
_DEFAULT_REDIRECT_LIMIT), for 301/302/303/305/307/308. The method is kept, theparamsare dropped and the request ID is carried over (keystoneauth1/session.py:385-387,keystoneauth1/session.py:1246-1290). - 401 after authentication: if
allow_reauth, the plugin invalidates its token and the request is replayed once with a new token (keystoneauth1/session.py:1128-1136; verified by scenario 6 of the client contract). - Status ≥ 400 with
raise_exc(default):exceptions.from_response(see errors).
4. Token cache and renewal (keystoneauth1/identity/base.py:93-160)
The plugin keeps its AccessInfo. It re-authenticates when the token expires within **MIN_TOKEN_LIFE_SECONDS = 120 s**, or after invalidate(). Nothing is persisted to disk by default.
5. Endpoint selection (keystoneauth1/access/service_catalog.py:156-260, keystoneauth1/identity/base.py:166-335)
- Filter the catalog:
service_type, recognising the aliases of os-service-types (volumev3↔block-storage…);service_nameandservice_idwhen the catalog gives them;region_name;interface:publicby default, or an ordered list of preferences, wherepublicURL,internalURLandadminURLare normalised.
- Then version discovery (
EndpointData.get_versioned_data,keystoneauth1/discover.py:1205). It tries the candidate URLs in order (catalog URL, URL without the version, withproject_idremoved…;keystoneauth1/discover.py:1444-1520) and reads the first version document found.- Without a document: the catalog URL is used as is if the "version hack" is allowed, otherwise
DiscoveryFailure. - Discovery is skipped when the catalog URL already matches the requested version exactly (
_catalog_matches_exactly).
- Without a document: the catalog URL is used as is if the "version hack" is allowed, otherwise
endpoint_overrideshort-circuits the catalog.
6. Configuration (loading)
- CLI (
keystoneauth1/loading/cli.py,keystoneauth1/loading/session.py):--os-auth-type(envOS_AUTH_TYPEorOS_AUTH_PLUGIN), the plugin's options (--os-auth-url,--os-username,--os-project-name…),--insecure,--os-cacert,--os-cert,--os-key,--timeout,--collect-timing,--tls-ciphers,--tls-min-version. - oslo.config (services):
[<group>] auth_type, plugin options,cafile,certfile,keyfile,insecure,timeout… and for adaptersservice-type,service-name,valid-interfaces,region-name,endpoint-override,version,min-version,max-version,connect-retries,connect-retry-delay,status-code-retries,status-code-retry-delay,retriable-status-codes(keystoneauth1/loading/adapter.py).
Source: reverse-spec-keystoneauth/01-library-api_stable-2026.2.md. The _rewrite/ and _inventory/ files are not published on the site.