Commit Graph

189 Commits

Author SHA1 Message Date
Stephen Finucane 5d2ab6c63b db: Replace use of Query.get()
Resolve the following LegacyAPIWarning warning:

  The Query.get() method is considered legacy as of the 1.x series of
  SQLAlchemy and becomes a legacy construct in 2.0. The method is now
  available as Session.get()

Change-Id: I30d0bccaddff6a1d91fcd5660f490f904e7c8965
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-02-28 17:26:39 +00:00
Jose Castro Leon 23477a13ab
Improve performance on trust deletion
During a trust deletion, the backend will fetch all trust by the same
trustor and look for redelegations to be deleted as well. If you have
a considerable amount of trusts that call becomes expensive. Just by
pushing this filter into the backend, the response time for the api call
just depends on the number of redelegations for that trust.

Change-Id: Id3a820fca0bb20561ba031797d2b0fb96ba1f78d
Closes-Bug: #1935840
2021-09-02 15:18:29 +02:00
Vishakha Agarwal 4530041931 Remove six usage
This repo does not support Python 2 anymore, so we don't need
six for compatibility between Python2 and 3, convert six usage to Python
3 code.

Change-Id: Icba56808f38277b27af2ae5aac4b8507dee71b3b
2020-01-30 06:06:51 +00:00
Jorge Munoz 2b9d409f0d Move redelegation fields out of extras
The trust SQL backend uses the extras column to store the
redeletegated_trust_id and redelegation_count info. It's
better to make them first class citizens and give them
their own columns.

This change does not add redelegation_trust_id to the trust schema
because this value is set by the token context, not by the user. We also
remove it from the api-ref example to avoid confusion about this.

Co-Authored-By: David Stanek <dstanek@dstanek.com>
Co-Authored-By: Alexander Makarov <amakarov@mirantis.com>
Change-Id: If496152e40d2213a03faad5645667220fddfcf62
2019-04-12 20:27:34 -07:00
Vishakha Agarwal 25e0e1474a Add abstract method in trusts base.py
This is a follow-up patch to add an abstract
method for flush_expired_and_soft_deleted_trusts
in base.py to avoid any burst in case people
supplying their own backend.

Change-Id: Ib326abddce239e87cd4cd37d06fa3b55112ee134
Related-Patch: https://review.openstack.org/#/c/589378/
Related-Bug: #1473292
2018-11-07 08:43:39 +05:30
Vishakha Agarwal 7e42d333c7 Adding 'date' for trust_flush
This patch adds functionality to purge
expired and soft-deleted trusts older
than the given date.

Change-Id: I0bd47e57f8650182e38b4f70e04cb53338fce474
Related-Bug: #1473292
2018-10-23 15:13:15 +05:30
Vishakha Agarwal 6aba78a7a2 Purge soft-deleted trusts
This patch adds the functionality for purging both
expired trusts as well as non-expired soft-deleted
trusts, since those soft-deleted trusts are
as likely to bloat the database as expired trusts.

Related to patch-
https://review.openstack.org/#/c/589378/

Change-Id: I3c74f2345a944ce03a8189c4e66c3c37350cd34f
Related-Bug: #1473292
2018-10-02 09:49:53 +05:30
Vishakha Agarwal 8232dabcf9 Implement Trust Flush via keystone-manage.
Creates a cli entry 'trust_flush' which removes
all expired trusts.

Change-Id: I1c85b67d24e05db86c85e722fbd773a411c24ac4
Closes-Bug: #1473292
2018-09-18 13:51:11 +05:30
Morgan Fainberg 3e948cfab4 Move trusts to flask native dispatching
Migrate trust APIs from legacy routes/webob to flask native
dispatching.

Change-Id: I6cba774c7dcf2fc6fdcbdc8f6e80111ccd8036a1
Partial-Bug: #1776504
2018-07-26 10:30:24 -07:00
Morgan Fainberg 4ec6bc5a44 Convert Keystone to use Flask
Basic conversion of Keystone's core application to flask framework.

This doesn't add much in the way of flask-specific-isms but should
get keystone running directly under flask. This implementation does
not use paste-deploy.

Change-Id: Ib4c1ed3f645dd55fbfb76395263ecdaf605caae7
2018-06-04 20:14:41 -07:00
Lance Bragstad 796198f196 Populate application credential data in token
Without this patch, the token formatter does not have enough data to
construct a token created with an application credential. This means
that if the token cache is disabled or expired, when keystone goes to
create the token it will not find any application credential information
and will not recreate the application_credential_restricted parameter in
the token data. This patch creates a new Payload class for application
credentials so that the application credential ID is properly persisted
in the msgpack'd payload. It also adds more data to the token data
object so that the application credential ID and name as well as its
restricted status is available when the token is queried.

Co-authored-by: Lance Bragstad <lbragstad@gmail.com>

Change-Id: I322a40404d8287748fe8c3a8d6dc1256d935d84a
Closes-bug: #1750415
2018-02-19 22:41:12 +01:00
Colleen Murphy 29280b1f68 Add application credential auth plugin
Add an auth plugin for application credentials and update the common
auth utilities to understand an auth method of 'application_credential'
and validate and scope accordingly.

By default, application credentials should not be allowed to be used for
creating other application credentials or trusts. If a user creates an
application credential with flag `allow_application_credential_creation`
then that application should be allowed to be used for creating and
deleting other application credentials and trusts. Ensure a flag is set
in the token if this property is set to allow this behavior.

bp application-credentials

Change-Id: I15a03e79128a11314d06751b94343f22d533243a
2018-01-27 12:00:19 +01:00
Zuul 2db7de856b Merge "Use keystone.common.provider_api for trust APIs" 2018-01-16 17:51:06 +00:00
Colleen Murphy 30e1cae952 Extract expiration validation to utils
Extract the expiration time parsing from the trusts controller to the
utils module. This will be useful to any API that needs to validate
user-inputted timestamps.

Change-Id: If99b2c456e61ae25123c5597e2788e667021cb2c
2018-01-12 21:09:33 +01:00
Lance Bragstad 9875135aa2 Use keystone.common.provider_api for trust APIs
This change converts the usage of self.<provider_api> to
keystone.common.providers_api.ProviderAPIs.<provider_api> in manager
and controller logic. This is the correct way to reference
providers from other managers and controllers now that dependency
injection has been eliminated.

Change-Id: I26bdb8cc3707b294c79b098211debf65f88587f9
2018-01-08 14:35:49 +00:00
Colleen Murphy 07b07d5b83 Add expired_at_int column to trusts
We've already converted Password objects to use the DateTimeInt format
for its datetime attributes[1]. This was necessary to cope with
differences in date storage formats between different DBMSs that was
causing intermittent test failures. While we're not experiencing those
CI problems any more, the DateTimeInt format is the way forward for
consistent datetime storage. This patch converts the trust table and
model to use the new format.

[1] https://review.openstack.org/#/c/493259/

Related-bug: #1702211

Change-Id: If524c743170924e5b8cfdafa862ed31b06db018c
2018-01-04 22:28:44 +01:00
Colleen Murphy e6fb2318f1 Implement get_unique_role_by_name
Implement a convenience method in the role manager to look up a single role
by its name. This is useful for moving role-specific logic out of the
trust controller and will be useful again for application credentials
which will also need to look up roles by name.

Change-Id: I94083cd4e719f105b5555e4676e119a358d6b1c6
2017-12-29 23:30:10 +01:00
Morgan Fainberg 81f9fe6fed Remove Dependency Injection
Refactors all of keystone's dependency injection to maintain a
single centralized repository of instantiated objects. This
means that we are no longer having to resolve order. All
objects that need to reference the various manager APIs simply
do so via the __getattr__ built into the Manager common object
or the ProviderAPIMixin object.

This is also the first step towards correcting our tests to
where they cannot run "load_backends" multiple times.

This forces any/all managers to properly run super()
as the way to register the api is via __init__.

This eliminates all use of the @dependency.requires and
@dependency.provides decorators, simplifying the objects
all around.

Any instantiations of a Manager after keystone is running
will now generate an error, ensuring everything for keystone
is running before handling requests. An exception is for
CLI and CLI tests, as the CLI may directly instantiate
managers and will not lock the registry.

Change-Id: I4ba17855efd797c0db9f4824936b49e4bff54b6a
2017-12-13 10:59:39 -08:00
Colleen Murphy f97df5cb6f Fix role schema in trust object
Previously, we weren't doing any validation on the roles attribute of a
trust except to validate that it was an array. A hasty glance, however,
would lead you to believe that it was validating an array of
parameter_types.id_string[1] and so we translated that to the new role
object validation. However, id_string doesn't include some valid role
names like _member_. This patch updates the role name schema to match
parameter_types.name, which is the same as the schema for the main role
object.

[1] http://git.openstack.org/cgit/openstack/keystone/tree/keystone/trust/schema.py?id=62f9e57cd81dc98c5816da9fa483d385b4c1a66c#n41

Change-Id: I83aafc7a96e81a9b6b1056b39cd8c5d23676c014
Closes-bug: #1734871
2017-11-28 15:21:45 +01:00
wangxiyuan f8e79ab507 Fix 500 error when create trust with invalid role key
When create trust with invalid role key(neither 'id' nor
'name'), Keystone should raise 400 BadRequest, instead of
500 Internal Error.

This patch removed the redundant loops in
_normalize_role_list as well.

Change-Id: I62bd201c1dda7b573e2ee8b97322c1f25275892c
Closes-bug: #1734244
2017-11-27 15:11:34 +00:00
chenaidong1 faec97fb2b Delete redundant code
_trustor_trustee_only has been called in function
TrustV3::get_trust. It is not necessary to be called again.

Change-Id: Ice93b826fef4616801fd02bcf8175b7c8dc11839
2017-08-22 02:22:44 +00:00
Jenkins 8badbabd6a Merge "Ensure the trust API supports HEAD requests" 2017-06-23 05:23:13 +00:00
Kristi Nikolla 1ec118a85f Return 400 when trying to create trust with ambiguous role name
If a user is trying to create a trust by specifying roles by name
and the name is used by multiple roles, return a more descriptive
error message. Prior to this it was returning "role not found".

Change-Id: Ife437ac15774f546f551e191cd5e6fdde7c67d49
Partial-Bug: 1696111
2017-06-22 18:03:50 +00:00
Lance Bragstad 37d73b15b0 Ensure the trust API supports HEAD requests
This commit makes it so all GET requests in the trust API also
support HEAD.

Change-Id: I6b6ec5cbd651a601a18b04428183b21044305be7
Partial-Bug: 1696574
2017-06-21 15:04:03 +00:00
Morgan Fainberg dce7c52de9 Make use of Dict-base including extras explicit
This change replaces the use of DictBase with the ModelDictMixin
for any SQL models that do not contain an extra column and renames
the DictBase to a more descriptive name of ModelDictMixinWithExtras.

A Docstring has been added indicating the continued usage of
ModelDictMixinWithExtras should not be done for any "new"
models.

Change-Id: I9a4767cacf7620e878df70084060f3e43e1318df
2017-02-06 19:15:15 -08:00
Boris Bobrov 05f2317c5b Remove eventlet-related call to sleep
Eventlet patched time.sleep. When time.sleep was called, eventlet
switched to another worker. The code being removed gave eventlet
a chance to switch to another worker if there was one.

Eventlet was removed a long time ago and the call being removed
is not needed any more.

Change-Id: I2d23f20f94c2f2e0917be9ea67e7e5edf3514aff
2016-11-24 12:43:18 +00:00
Rodrigo Duarte Sousa 03319d1ab9 Improvements in error messages
Minor improvements in trust/controllers.py error messages.

Change-Id: I273c470c140e2ac94d98374586113da36ad88efa
2016-11-22 14:33:24 +00:00
David Stanek 1e6f78013f Normalizes use of ForbiddenAction in trusts
In review Id5de16d446cf4fdacfefdad0523e84821e4fd72c we decided that
ForbiddenAction should be used in place of Forbidden when extra context is
necessary. This is to allow the error message to contain the normal
"You are not authorized" messaging in addition to that extra context.

Change-Id: I2f9204602e95e45f6db1733c41984ae160745d37
2016-11-21 19:49:03 +00:00
Alexander Makarov 5ae4ca12a7 Verbose 401/403 debug responses
Add text to raised Unauthorized and Forbidden exception to show the client
what happened.

Change-Id: Id5de16d446cf4fdacfefdad0523e84821e4fd72c
Closes-Bug: 1625120
2016-11-21 14:11:52 +00:00
Dave Chen f0319c752a Invalidate trust when the related project is deleted
The trust without a valid project is useless and will no longer
be active since the id of project is a random number and only
assigned when it created.

The patch invalidate the trust if the related project is deleted.

Change-Id: I51214c46ef5332c159b1e18bbd7046d12aba4a65
Closes-Bug: #1622310
2016-10-14 16:55:06 +00:00
Dave Chen 52642cc562 Invalidate trust when the trustor or trustee is deleted
The trust without a valid trustee, trustor is useless and will
no longer be active since the id of user is a random number and
only assigned when it created.

The patch delete trust if the related trustee or trustor is
deleted if the user is maintained by keystone.

Change-Id: I67dac6b7bac8cb94575ceda4a3277847a2bcc2d8
Partial-Bug: #1622310
2016-10-13 09:36:04 +08:00
Dave Chen 38f2305ee3 Remove the decorator where it's not applied
There is no need and should not any conflicts or integrity
exception for the list something from DB.

Change-Id: I9f999a204ee7ef9e51384e6e032257aae7794e5e
2016-10-11 10:10:03 +08:00
Jenkins 83bd595b22 Merge "Pass initiator to Manager as a kwarg" 2016-10-09 02:57:43 +00:00
Jenkins eb55c2c9f1 Merge "Move audit initiator creation to request" 2016-10-08 00:58:51 +00:00
Lance Bragstad 86229b3e75 Pass initiator to Manager as a kwarg
Keystone's various Manager classes typically handle the sending of
a notification. In order to send the notification an `initiator` is
needed. All Manager CRUD methods typically ask for this as a kwarg
since it's not required in all cases.

Most of the controller layers pass the initiator value as a
positional argument. This commit makes it so the controller passes it
as a kwarg since that's how the Manager class method signature
describes it.

Change-Id: Ic805f6ea2767c9c5cf01aa04ad554773b9cc8c39
2016-10-07 15:20:45 +00:00
Jamie Lennox 9117e45d6e Move audit initiator creation to request
The audit initiator is basically a context with all the information
about the current operation available. This information is all gathered
from the request and context so we can simplify its generation by moving
it onto the request object.

Change-Id: If91eacd3e07e0d9cd825f92b06c0ac819b3daf8c
2016-10-05 11:42:03 +11:00
Steve Martinelli 810e15689b Remove stable driver interfaces
bp removed-as-of-ocata

Change-Id: I4672cf7d9d72ef725212085972dbcd90db0e47cf
2016-09-28 17:18:37 +00:00
Alexander Makarov 9838e542af Trust controller refactoring
In lieu of new more complicated role system role collections tend to grow,
so extracting all roles to normalize/populate trust scope should be more
granular. This patch is a rework of role treating logic in trust controller.

Change-Id: Id6945ff9be23250d72909beceaa9cd73eebde04f
2016-08-04 18:49:32 +03:00
Jamie Lennox b3e065efaa Remove get_user_id in trust controller
The get_user_id function relied on the token model in auth_context -
which amongst other things means it would fail with a tokenless auth
context. This can be replaced with user_id from the request.context.

Normally I try not to mix in cleanups, but whilst doing this and
changing variables in list_trusts a small reshuffle and some whitespace
just made the whole thing actually readable.

Change-Id: I5b64210fc797961b422a0ab9a1b4cee078fe6a0f
2016-07-14 18:28:30 +10:00
Jamie Lennox 813536b4dd Cleanup trusts controller
One or two line functions that are only used once make it harder to read
because you need to jump around and see what the function is doing. Just
bring this code in to where it is actually used.

Change-Id: I741271bea9c44d96bc6d98f92660f52fdbbdb534
2016-07-14 18:28:29 +10:00
Jamie Lennox 9dc21e8525 Handle more auth information via context
Add more information from the auth_context dict to the request context
object and start the process of converting code over to using the
context instead.

Change-Id: I3a5d8af30834873dfc7a10464a22355f379ebbcf
2016-07-13 17:14:46 +10:00
Jenkins 91432a1cfb Merge "Use the context's is_admin property" 2016-07-11 23:56:53 +00:00
Jenkins 7fd720be1f Merge "Move request validation inline" 2016-07-09 09:47:39 +00:00
Jenkins 28d86afb88 Merge "Move the trust abstract base class out of core" 2016-07-09 03:03:22 +00:00
Lance Bragstad 8ff6b0ea51 Move request validation inline
This commit moves all the decorated call to validate request inline with the
method. This is one way we can lazily validate requests - which allows us to
pick validation configuration options specifed in config.

Change-Id: Iee71fb3c34d296427cd485180dacb6bf02581845
2016-07-08 20:22:33 +00:00
Jamie Lennox e4ed9a4bd1 Use the context's is_admin property
The oslo_context provides a standard is_admin property that should be
used instead of pushing one around in our unstructred context dict. This
is part of a trend to use more of the standard context object instead of
our own dict.

Change-Id: Ia7b35ba80f483ef0baa1ae416d670fd45349bd89
2016-07-08 10:26:27 +10:00
Ronald De Rose 5f1eae1650 Move the trust abstract base class out of core
This patch moves the trust abstract base class out of core and
into backends/base.py

This removes dependencies where backend code references code in the
core. The reasoning being that the core should know about the backend
interface, but the backends should not know anything about the core
(separation of concerns). And part of the risk here is a potential for
circular dependencies.

Partial-Bug: #1563101

Change-Id: Ibe9203635ee4ad5d1afee3ad751f04de6ef66f94
2016-07-07 17:11:13 +00:00
Jamie Lennox 3a19aa518d Remove get_auth_context
The controller get_auth_context method simply fetches a dict from the
environment. We can simply put this method on the request now.

Change-Id: Icba3a0286e5af440108c27f41f54de64c922f29a
2016-07-07 15:11:34 +10:00
Jamie Lennox b66693ed23 Make assert_admin work with a request
Push further into pushing a request object around, fix the v2
assert_admin method to work with a request.

Change-Id: I83063178b04c5e401d1f1a6bb9bce63a4a38910e
2016-07-05 09:07:58 +10:00
Jamie Lennox ef70f52bef Use request.params instead of context['query_string']
The context['query_string'] is just a dictionary copy of the original
params object that comes from a request. Just use the existing params
instead.

Change-Id: I0ecd7a09e36b39a105c150b3affcbbcd26a544c2
2016-06-29 04:46:57 +10:00