blob: 8c9a16aa2ff20e5da6b4ff31a416622a601d4e7b [file] [log] [blame]
Matthew Treinishc51b7122017-07-17 12:28:07 -04001.. _cred_providers:
2
3Credential Providers
4====================
5
6These library interfaces are used to deal with allocating credentials on demand
Martin Kopecd76178e2024-01-16 20:43:56 +01007either dynamically by calling Keystone to allocate new credentials, or from
Matthew Treinish841b75e2017-07-17 13:17:43 -04008a list of preprovisioned credentials. These 2 modules are implementations of
shangxiaobj284d3112017-08-13 23:37:34 -07009the same abstract credential providers class and can be used interchangeably.
Matthew Treinish841b75e2017-07-17 13:17:43 -040010However, each implementation has some additional parameters that are used to
11influence the behavior of the modules. The API reference at the bottom of this
Martin Kopecd76178e2024-01-16 20:43:56 +010012doc shows the interface definitions for both modules, however, that may be a bit
Matthew Treinish841b75e2017-07-17 13:17:43 -040013opaque. You can see some examples of how to leverage this interface below.
Matthew Treinishc51b7122017-07-17 12:28:07 -040014
Matthew Treinish841b75e2017-07-17 13:17:43 -040015Initialization Example
16----------------------
17This example is from Tempest itself (from tempest/common/credentials_factory.py
18just modified slightly) and is how it initializes the credential provider based
19on config::
20
21 from tempest import config
22 from tempest.lib.common import dynamic_creds
23 from tempest.lib.common import preprov_creds
24
25 CONF = config.CONF
26
27 def get_credentials_provider(name, network_resources=None,
28 force_tenant_isolation=False,
29 identity_version=None):
30 # If a test requires a new account to work, it can have it via forcing
31 # dynamic credentials. A new account will be produced only for that test.
32 # In case admin credentials are not available for the account creation,
Martin Kopecd76178e2024-01-16 20:43:56 +010033 # the test should be skipped else it will fail.
Matthew Treinish841b75e2017-07-17 13:17:43 -040034 identity_version = identity_version or CONF.identity.auth_version
35 if CONF.auth.use_dynamic_credentials or force_tenant_isolation:
36 admin_creds = get_configured_admin_credentials(
37 fill_in=True, identity_version=identity_version)
38 return dynamic_creds.DynamicCredentialProvider(
39 name=name,
40 network_resources=network_resources,
41 identity_version=identity_version,
42 admin_creds=admin_creds,
43 identity_admin_domain_scope=CONF.identity.admin_domain_scope,
44 identity_admin_role=CONF.identity.admin_role,
45 extra_roles=CONF.auth.tempest_roles,
46 neutron_available=CONF.service_available.neutron,
47 project_network_cidr=CONF.network.project_network_cidr,
48 project_network_mask_bits=CONF.network.project_network_mask_bits,
49 public_network_id=CONF.network.public_network_id,
50 create_networks=(CONF.auth.create_isolated_networks and not
51 CONF.network.shared_physical_network),
ghanshyamb20f7e62017-12-10 07:10:22 +030052 resource_prefix='tempest',
Matthew Treinish841b75e2017-07-17 13:17:43 -040053 credentials_domain=CONF.auth.default_credentials_domain_name,
54 admin_role=CONF.identity.admin_role,
55 identity_uri=CONF.identity.uri_v3,
56 identity_admin_endpoint_type=CONF.identity.v3_endpoint_type)
57 else:
58 if CONF.auth.test_accounts_file:
59 # Most params are not relevant for pre-created accounts
60 return preprov_creds.PreProvisionedCredentialProvider(
61 name=name, identity_version=identity_version,
62 accounts_lock_dir=lockutils.get_lock_path(CONF),
63 test_accounts_file=CONF.auth.test_accounts_file,
64 object_storage_operator_role=CONF.object_storage.operator_role,
65 object_storage_reseller_admin_role=reseller_admin_role,
66 credentials_domain=CONF.auth.default_credentials_domain_name,
67 admin_role=CONF.identity.admin_role,
68 identity_uri=CONF.identity.uri_v3,
69 identity_admin_endpoint_type=CONF.identity.v3_endpoint_type)
70 else:
71 raise exceptions.InvalidConfiguration(
72 'A valid credential provider is needed')
73
74This function just returns an initialized credential provider class based on the
75config file. The consumer of this function treats the output as the same
76regardless of whether it's a dynamic or preprovisioned provider object.
77
78Dealing with Credentials
79------------------------
80
81Once you have a credential provider object created the access patterns for
82allocating and removing credentials are the same across both the dynamic
83and preprovisioned credentials. These are defined in the abstract
Martin Kopecd76178e2024-01-16 20:43:56 +010084CredentialProvider class. At a high level, the credentials provider enables
85you to get 3 basic types of credentials at once (per object): primary, alt,
Matthew Treinish841b75e2017-07-17 13:17:43 -040086and admin. You're also able to allocate a credential by role. These credentials
Martin Kopecd76178e2024-01-16 20:43:56 +010087are tracked by the provider object and delete must be called manually,
88otherwise, the created resources will not be deleted (or returned to the pool
89in the case of preprovisioned creds).
Matthew Treinish841b75e2017-07-17 13:17:43 -040090
91Examples
92''''''''
93
94Continuing from the example above, to allocate credentials by the 3 basic types
95you can do the following::
96
97 provider = get_credentials_provider('my_tests')
98 primary_creds = provider.get_primary_creds()
99 alt_creds = provider.get_alt_creds()
100 admin_creds = provider.get_admin_creds()
101 # Make sure to delete the credentials when you're finished
102 provider.clear_creds()
103
104To create and interact with credentials by role you can do the following::
105
106 provider = get_credentials_provider('my_tests')
107 my_role_creds = provider.get_creds_by_role({'roles': ['my_role']})
108 # provider.clear_creds() will clear all creds including those allocated by
109 # role
110 provider.clear_creds()
111
112When multiple roles are specified a set of creds with all the roles assigned
113will be allocated::
114
115 provider = get_credentials_provider('my_tests')
116 my_role_creds = provider.get_creds_by_role({'roles': ['my_role',
117 'my_other_role']})
118 # provider.clear_creds() will clear all creds including those allocated by
119 # role
120 provider.clear_creds()
121
122If you need multiple sets of credentials with the same roles you can also do
123this by leveraging the ``force_new`` kwarg::
124
125 provider = get_credentials_provider('my_tests')
126 my_role_creds = provider.get_creds_by_role({'roles': ['my_role']})
127 my_role_other_creds = provider.get_creds_by_role({'roles': ['my_role']},
128 force_new=True)
129 # provider.clear_creds() will clear all creds including those allocated by
130 # role
131 provider.clear_creds()
132
Matthew Treinishc51b7122017-07-17 12:28:07 -0400133
Masayuki Igawaa1c3af32017-09-07 10:22:37 +0900134API Reference
135-------------
136
Matthew Treinishc51b7122017-07-17 12:28:07 -0400137The dynamic credentials module
Masayuki Igawaa1c3af32017-09-07 10:22:37 +0900138''''''''''''''''''''''''''''''
Matthew Treinishc51b7122017-07-17 12:28:07 -0400139
140.. automodule:: tempest.lib.common.dynamic_creds
141 :members:
Matthew Treinishb19c55d2017-07-17 12:38:35 -0400142
Matthew Treinishb19c55d2017-07-17 12:38:35 -0400143The pre-provisioned credentials module
Masayuki Igawaa1c3af32017-09-07 10:22:37 +0900144''''''''''''''''''''''''''''''''''''''
Matthew Treinishb19c55d2017-07-17 12:38:35 -0400145
146.. automodule:: tempest.lib.common.preprov_creds
147 :members: