OpenStack Keystone Documentation

repository·master·Indexed 20 days ago

https://github.com/openstack/keystone

Documentation 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.

Tokens
92K
Snippets
249
Records
407
Agent score
71%

What's inside OpenStack Keystone

  1. Overview of OpenStack Keystone

    master
    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.
  2. Overview of Keystone, the OpenStack Identity Service

    master

    Keystone 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.
  3. Use the keystone-manage CLI utility

    master

    The keystone-manage command-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]
  4. What is Keystone Federation?

    master

    Keystone 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.
  5. What is JSON Home and how is it used for API discovery?

    master
    JSON 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.
  6. What is X.509 Tokenless Authorization?

    master

    X.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_token middleware 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.
  7. Understand the Fernet key lifecycle and rotation

    master

    Keystone 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

    1. Initial State: A repository has a staged key and a primary key. New tokens use the primary key.
    2. 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.
    3. 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)
  8. Understand the Flat enforcement model

    master

    The Flat enforcement 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.
  9. Use Variable Substitution in Mappings

    master

    You can extract values from IdP attributes using the empty condition and substitute them into local user attributes using indexed placeholders {0}, {1}, etc. The indices correspond to the order of the remote attribute list.

    Example: If your remote attributes are [{"type": "FirstName"}, {"type": "LastName"}], then {0} maps to the FirstName value and {1} maps to the LastName value.

    {
           "rules": [
               {
                   "local": [
                       {
                           "user": {
                               "name": "{0} {1}"
                           }
                       }
                   ],
                   "remote": [
                       { "type": "FirstName" },
                       { "type": "LastName" }
                   ]
               }
           ]
       }
  10. How to set scope types in oslo.policy

    master

    When refactoring a service to use oslo.policy for scope checking, you can assign a scope type to a policy rule.

    • Behavior: If a RuleDefault has a scope associated with it, oslo.policy validates 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_scope configuration.
      • If enforce_scope is disabled: oslo.policy logs a warning when a scope mismatch occurs.
      • If enforce_scope is enabled: oslo.policy rejects the request with an error if the scope is incorrect.
    • Choosing a Scope:
      • Use system scope for operators managing the entire deployment.
      • Use project scope for end users operating within a specific project.
    • 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.context and keystonemiddleware, query the RequestContext object to inspect the token's scope.
  11. Configure Keystone-to-Keystone (K2K) Attribute Mappings

    master

    In Keystone-to-Keystone federation, an attribute file (such as a Shibboleth attribute-map.xml) is used to add attributes to the mapping context. The Service Provider (SP) matches these attributes against the remote section of the mapping rules.

    Available attributes for mapping include:

    • openstack_user
    • openstack_user_domain
    • openstack_roles
    • openstack_project
    • openstack_project_domain
    • openstack_groups