OpenStack Keystone Documentation
repository·master·Indexed 20 days ago
https://github.com/openstack/keystoneDocumentation for OpenStack Identity (Keystone), covering the Identity API v3, authentication token management, and core abstractions like domains, projects, and roles. Includes guides on bootstrapping the service via keystone-manage, configuring TOTP authentication, managing Identity API v3 extensions (OAuth, Trust, Federation), and database migration logic using Alembic and SQLAlchemy.
What's inside OpenStack Keystone
- OpenStack Keystone is an identity service that provides authentication, authorization, and service discovery mechanisms via HTTP. It is primarily designed for use by OpenStack projects and is frequently deployed as an HTTP interface to existing identity systems like LDAP.
Overview of Keystone, the OpenStack Identity Service
masterKeystone is the OpenStack service responsible for providing API client authentication, service discovery, and distributed multi-tenant authorization. It implements the OpenStack Identity API.
Developers can interact with Keystone through several related components:
- WSGI middleware: For integrating Keystone authentication into WSGI applications.
- Authentication library: For handling authentication logic.
- Python client library: For programmatic access to Keystone services.
Supported Keystone clients
masterKeystone provides two primary ways to interact with its services:
- python-keystoneclient: Provides Python bindings for programmatic access.
- python-openstackclient: Provides a command-line interface (CLI) for managing Keystone resources.
Use the keystone-manage CLI utility
masterThe
keystone-managecommand-line tool is used to interact with the Keystone service for administrative operations that cannot be performed via the standard HTTP API. Its primary use cases include:- Database Migrations: Updating the Keystone database schema.
- Data Import/Export: Moving Keystone data between environments.
- Initialization: Setting up the initial Keystone data structures.
Usage Pattern:
keystone-manage [options] action [additional args]What is Keystone Federation?
masterKeystone Federation allows sharing identity information across multiple identity management systems. Instead of Keystone managing user credentials directly, users authenticate with an external identity source, which then provides Keystone with user attributes.
This is distinct from using LDAP as an identity backend; while LDAP allows Keystone to fetch identity information, Keystone still handles the passwords directly. In Federation, authentication is offloaded to the external source.
Key use cases include:
- Using an existing primary identity source so users don't need new cloud credentials.
- Connecting multiple clouds by using one Keystone instance as an identity source for another.
What is JSON Home and how is it used for API discovery?
masterJSON Home is a method for API discovery designed for non-browser HTTP clients. It provides a JSON document that informs clients about available API endpoints, their locations (URIs), and their current status (e.g., experimental, supported, or deprecated). This allows programmatic clients to discover the Keystone API surface dynamically.What is X.509 Tokenless Authorization?
masterX.509 Tokenless Authorization allows Keystone to authorize client operations using an X.509 SSL client certificate instead of requiring the issuance and validation of a user token.
This approach provides several benefits:
- Reduced Complexity: Eliminates the need for
auth_tokenmiddleware to use a service user token for authentication and authorization. - Operational Efficiency: Avoids the overhead of requesting, caching, and renewing service user tokens.
- Improved Security: Uses X.509 certificates for authentication instead of passwords, and removes the need to manage and protect service user credentials in configuration files.
- Reduced Complexity: Eliminates the need for
Understand the Fernet key lifecycle and rotation
masterKeystone manages a repository of Fernet keys to allow for seamless rotation. The repository contains different types of keys that work together to ensure continuous service:
- Primary Key: The key currently used to encrypt all new tokens.
- Secondary Keys: Older keys retained in the repository to decrypt tokens that were issued before the last rotation but have not yet expired.
- Staged Key: A key prepared for the next rotation.
Key Rotation Workflow
- Initial State: A repository has a staged key and a primary key. New tokens use the primary key.
- Rotation: The staged key becomes a secondary key, the old primary key becomes a secondary key, and a new key is staged/promoted to primary.
- Pruning: Once a key is no longer needed (i.e., all tokens encrypted with it have passed their expiration time plus any
allow_expired_window), it can be safely removed from the repository without affecting valid users.
If you rotate keys too frequently without increasing
max_active_keys, you will remove keys that are still required to decrypt unexpired tokens, causing legitimate users to be rejected.## Example directory state during rotation # After first rotation (Primary is key 1, Staged is 0) $ ls -la /etc/keystone/fernet-keys/ -rw------- 1 keystone keystone 44 0 (staged key) -rw------- 1 keystone keystone 44 1 (primary key) # After second rotation (Primary is key 2, Secondary is 1, Staged is 0) $ ls -la /etcystone/fernet-keys/ -rw------- 1 keystone keystone 44 0 (staged key) -rw------- 1 keystone keystone 44 1 (secondary key) -rw------- 1 keystone keystone 44 2 (primary key)Understand the Flat enforcement model
masterThe
Flatenforcement model treats every project as an isolated peer, completely ignoring any project hierarchy.Key Characteristics:
- Isolation: Limits and usage in parent, sibling, or child projects have no effect on a specific project.
- Validation: You can set a child project's limit higher than its parent's limit.
- Manual Control: To simulate hierarchy, you must manually adjust limits through the project tree.
When to use it:
- When your project hierarchies are deeper than two levels.
- When you require extremely strict isolation and do not want resource usage to bleed across projects or domains.
Use Variable Substitution in Mappings
masterYou can extract values from IdP attributes using the
emptycondition and substitute them into local user attributes using indexed placeholders{0},{1}, etc. The indices correspond to the order of theremoteattribute list.Example: If your remote attributes are
[{"type": "FirstName"}, {"type": "LastName"}], then{0}maps to theFirstNamevalue and{1}maps to theLastNamevalue.{ "rules": [ { "local": [ { "user": { "name": "{0} {1}" } } ], "remote": [ { "type": "FirstName" }, { "type": "LastName" } ] } ] }How to set scope types in oslo.policy
masterWhen refactoring a service to use
oslo.policyfor scope checking, you can assign a scope type to a policy rule.- Behavior: If a
RuleDefaulthas a scope associated with it,oslo.policyvalidates that the scope of the token used in the request matches the required scope. - Configuration: The enforcement behavior is controlled by the
oslo_policy.enforce_scopeconfiguration.- If
enforce_scopeis disabled:oslo.policylogs a warning when a scope mismatch occurs. - If
enforce_scopeis enabled:oslo.policyrejects the request with an error if the scope is incorrect.
- If
- Choosing a Scope:
- Use
systemscope for operators managing the entire deployment. - Use
projectscope for end users operating within a specific project.
- Use
- Multi-scope APIs: For APIs that require different scopes based on the resource (e.g., listing all users vs. listing users in a domain), you may need to implicitly filter responses. If using
oslo.contextandkeystonemiddleware, query theRequestContextobject to inspect the token's scope.
- Behavior: If a
Configure Keystone-to-Keystone (K2K) Attribute Mappings
masterIn Keystone-to-Keystone federation, an attribute file (such as a Shibboleth
attribute-map.xml) is used to add attributes to the mappingcontext. The Service Provider (SP) matches these attributes against theremotesection of the mapping rules.Available attributes for mapping include:
openstack_useropenstack_user_domainopenstack_rolesopenstack_projectopenstack_project_domainopenstack_groups