Commit Graph

35 Commits

Author SHA1 Message Date
Christian Rohmann 90dcff07c0 sql: Fixup for invalid unique constraint on external_id in access_rule table
There was a big drop of invalid constraints with [1]. One of them was on
`external_id` in the access_rule table.

While the change made it into a Alembic revision with [2], it still exists in
the schema causing an a new Alembic autogeneration to actually add it again as
a revision.

[1] https://review.opendev.org/c/openstack/keystone/+/851845
[2] 7d169870fe (diff-26484e3f6683ce7557e17b67220003784ff84fbe)

Closes-Bug: #1988297
Change-Id: I66626ba8771ef2aa8b3580fd3f5d15fd4b58ab48
2024-02-23 08:26:20 +00:00
Stephen Finucane 0bbaf63a5a db: Replace use of reverse cascades
Resolve the following RemovedIn20Warning warning:

  "ApplicationCredentialRoleModel" object is being merged into a Session
  along the backref cascade path for relationship
  "ApplicationCredentialModel.roles"; in SQLAlchemy 2.0, this reverse
  cascade will not take place.  Set cascade_backrefs to False in either
  the relationship() or backref() function for the 2.0 behavior; or to
  set globally for the whole Session, set the future=True flag

This also applies for "ApplicationCredentialAccessRuleModel" and
"AccessRuleModel.application_credential".

Change-Id: I277cb4d512ca6b4e4aca5aad60a97a78cdb961e3
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-02-28 17:26:39 +00:00
Andreas Jaeger f36111954b Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found.

Update local hacking checks for new flake8.

Change-Id: Ic440219814ee0c2b98217e9a821f38f5baf482ec
2020-04-15 07:17:58 +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
Colleen Murphy e2d83ae95d Re-enable line-length linter
In 09088690 we mistakenly added E501 to the flake8 ignore list. Since
then, many new violations have been introduced. This patch re-enables
the check and corrects all violations, except in some cases like unit
test names where the subunit output would suffer if we attempted to
shorten the function name.

This may appear to be a pointless no-op that messes with
git-blameability, and it is, but the reason to do this is that if PEP8
violations are introduced in master and then backported to a stable
branch, most stable branches will fail the pep8 job since the flake8
ignore list is correct for those branches. Rather than loosening the
check in older branches or requiring those backports to fix the linter
errors independently of what's been merged in master, we should fix it
now so that we don't introduce more errors in the future and patches can
more easily be backported.

Change-Id: I9f71926105eb448bb0200201d1838b67d4963cd6
2019-10-21 08:48:47 -07:00
Zuul 407565b001 Merge "Add notifications for deleting app creds by user" 2019-09-24 18:33:43 +00:00
Colleen Murphy 67682dcd07 Expose access rules as its own API
This change creates a /v3/users/{user_id}/access_rules endpoint to allow
users to view and delete their own access rules. Access rules are not
automatically deleted when an application credential is deleted, so they
can be re-used for other application credentials or explicitly deleted
by the user. Access rules are automatically deleted when the user is
deleted, the same way that application credentials are. Access rules
that are in use by an application credential may not be deleted.

bp whitelist-extension-for-app-creds

Change-Id: I37d243d802cd538189ccfffee6ebf0624b7785d3
2019-09-14 03:14:20 -07:00
Colleen Murphy 0bb980e9ec Add notifications for deleting app creds by user
Without this patch, when an individual application credential is deleted
it emits a notification, but when all are deleted for a user there is no
notification (although this is only triggered when a user is deleted or
disabled or has a change in role assignments, all of which generate
their own notifications). This patch ensures audit notifications are
generated for every application credential that gets deleted.

Change-Id: I7c820931585802c7afa53727623ac05adee56248
2019-08-21 09:14:03 -07:00
Colleen Murphy 14c4b177ef Add API changes for app cred access rules
bp whitelist-extension-for-app-creds

Change-Id: Ie022e379d03d0309ec320b6947b987758d87fe5d
2019-08-01 12:57:49 -07:00
Colleen Murphy ee7315971c Add manager support for app cred access rules
bp whitelist-extension-for-app-creds

Change-Id: Icce8b54e45ad94ca41a6b47ec6109346dc886334
2019-08-01 12:57:49 -07:00
Colleen Murphy 2203e81729 Add user_id, external_id to access rules table
Access rules that a user creates via an application credential will be
preserved independently of the application credential, and can be
queried on a per-user basis and re-used with new application
credentials. This change adds the user_id and external_id columns and
indices to allow that.

bp whitelist-extension-for-app-creds

Change-Id: I8a516fc19be25350593ef915a94f029c65db8de2
2019-08-01 12:57:49 -07:00
Colleen Murphy 25b2f151a7 Revert "Add manager support for app cred access rules"
This reverts commit 37fc2b9120.

In the Train PTG[1] we agreed to defer the access rules config part of
this feature until we had some kind of traceability or discoverability
for APIs. For simplicity of review, this patch reverts the access rules
addition to the app cred manager so that we can reimplement it in a way
that doesn't require using the access_rules_config API provider.

[1] https://etherpad.openstack.org/p/keystone-train-ptg-application-credentials

Change-Id: I65ac52b8730221562391adc8b0dbccd22ea79b16
2019-05-28 08:38:40 -07:00
Colleen Murphy 37fc2b9120 Add manager support for app cred access rules
This uses the access_rules manager to validate access rules against
configured access rules.

bp whitelist-extension-for-app-creds

Change-Id: I075ab8472cbe93db1c2327c2e82211ff71e9ef72
2019-03-04 09:22:21 +01:00
Colleen Murphy e8aa678a2b Add driver support for app cred access rules
Change-Id: Iff51313de8b2dc8c71efa901d4eab5ab417234d3
2019-03-03 18:33:49 +01:00
wangxiyuan f8834bc9a9 Fix app_cred schema spell nit
Change-Id: I92cee8f75bf3cf7d0e919afa04421809cf503828
2019-01-10 17:09:39 +08:00
Mike Chen 4385eb239f Remove unused logging module
Change-Id: I2090fa08ce51b5f4f83614ad4e65f902d099d85f
2018-10-25 14:22:50 +08:00
Morgan Fainberg 906a1d3f68 Invalidate app cred AFTER deletion
Invalidate the application credential after deletion, not before.
This prevents timing issues where an app_cred could remain active
after deletion.

Change-Id: I14748bf2399e5da4ee360f451a8050f25dd90803
2018-10-16 11:29:28 -07:00
Morgan Fainberg 86f968163e Convert /v3/users to flask native dispatching
Convert /v3/users to use flask native dispatching.

The following test changes were required:

* Application Credentials did not have the plural form
  in the JSON Home document. The JSON Home document was
  corrected both in code and in tests.

* Application Credentials "patch" test needed to be
  refactored to look for METHOD_NOT_ALLOWED instead
  of NOT FOUND for invalid/unimplemented methods.
  The "assertValidErrorResponse" method was
  insufficient and the test now uses the flask
  test_client mechanism instead.

Change-Id: Iedaf405d11450b11e2d1fcdfae45ccb8eeb6f255
Partial-Bug: #1776504
2018-10-11 15:27:45 -07:00
morgan fainberg d97832e8e8 Convert auth to flask native dispatching
Convert the /auth paths to flask native dispatching.

A minor change to additional_urls was implemented to ensure all
urls are added at once instead of individually (causing an over-
write issue within flask as a single resource may only have a
single set of URL mappings).

Alternate URLs now support adding alternate JSON Home rel links.
This is to support the case of OS-FEDERATION auth routes moving
to /auth. The old JSON Home entries must exist but reference
the new paths.

This port includes the following test changes (needed due to the
way flask handles requests and the way requests are passed through
the auth system):

* Implemented keystone.common.render_token (module)
  containing render_token_response_from_model and use it instead
  of keystone.common.controller.render_token_response_from_model.

  Minor differences occur in render_token_response_from_model in
  the keystone.common.render_token module, this is simply
  for referencing data from flask instead of the request object.

* Test cases have been modified to no longer rely on the auth
  controller(s) directly

* Test cases now use "make_request" as a context manager
  since authenticate/authenticate_for_token directly
  reference the flask contexts and must have an explicit
  context pushed.

* Test cases no longer pass request objects into methods
  such as authenticate/authenticate_for_token or similar
  methods on the auth plugins

* Test cases for federation reference the token model now
  where possible instead of the rendered token response.
  Rendered token responses are generated where needed.

* Auth Plugin Configuration is done in test core as well.
  This is because Auth controller does not exist.

NOTE: This is a massive change, but must of these changes
were now easily uncoupled because of how far reaching auth
is.

Change-Id: I636928102875760726cc3493775a2be48e774fd7
Partial-Bug: #1776504
2018-10-09 23:23:03 -07:00
zlyqqq 954bd1a9cc Code optimization of create application credential
We check if user has specified roles in project when creating
application credential. The code can be optimized here instead
of two level loop.

Change-Id: I9de223b693d33a45331af9ffd2960f733c6b43da
2018-08-03 16:10:27 +08:00
Lance Bragstad 140a34b439 Remove KeystoneToken object
This commit removes the original KeystoneToken object in favor of the
new TokenModel object. Since we have a token provider that knows how
to deal with TokenModel object, we don't really need another object
that uses reflection at all.

Closes-Bug: 1778945
Change-Id: I778cab0a6449184ecf7d5ccfbfa12791be139236
2018-08-01 21:33:59 +00: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
Zuul 68df7bf1f3 Merge "Populate application credential data in token" 2018-02-20 04:50:33 +00: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
Lance Bragstad c7658abfd6 Simplify token persistence callbacks
The INVALIDATE_USER_TOKEN_PERSISTENCE and
INVALIDATE_USER_PROJECT_TOKEN_PERSISTENCE callbacks were meant to
clean up invalid tokens from the token storage layer. Now that the
sql token driver has been removed, we don't need them any more. This
commit removes those notifications and refactors the places where
notifications are still needed, making them more specific and not
eluding to token persistence.

This commit also removes a significant amount of logic from the
assignment API that used to notify the token API when assignments
were deleted. This made sense when tokens were written to disk
because there was an opportunity to invalidate them when users were
removed from projects. This is no longer needed since we do
validation online and we don't persist tokens anymore.

Change-Id: I100b7416e8ba61eb4ea2c2eb4962e952a53ea388
2018-02-16 21:40:07 +00:00
wangxiyuan c6cfaadf5f Add cache invalidation when delete application credential
When delete application credentials for a user/project, the
realted cache information should be invalidated as well.

Closes-Bug: #1747332
Change-Id: I431bf1921a636cce00a807f9d639628da8664c24
2018-02-05 14:09:07 +08:00
wangxiyuan 63fde3eefb Fix cache invalidation for application credential
The cache invalidation doesn't work for application credential.

This patch fixed it.

Change-Id: I730df6f4abe1ec63d93e999535de7afad05e76a7
Closes-bug: #1746868
2018-02-05 09:23:16 +08:00
wangxiyuan e740d728da Update the base class for application credential
This patch updated some base functions' input parameters
and documentation in application credential backend to
keep the same with the usage. So that the customer could
write their own backend easliy.

Change-Id: I5d090d3ab72ab1f31bf3c3edcb8f4429085829ed
2018-02-03 23:04:03 +00:00
Colleen Murphy d827e6e3ab Impose limits on application credentials
In order to protect against possible abuse or bloat, add a config option
to set a limit on the number of application credentials a user may have.

bp application-credentials

Change-Id: Ieab33c3265fa0c0b1b1c6d586e5ea8a9a39edfb1
2018-01-27 12:00:23 +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
Colleen Murphy 166eced28b Add Application Credentials controller
Add the controller, router, schema, and policies for application
credentials. If a secret is not provided, one is generated at the
controller layer.

bp application-credentials

Depends-on: Id26a2790acae25f80bd28a8cb121c80cb5064645
Depends-on: Icbd58464182b082854fb5d73ccc93c900ede020c

Change-Id: I7a371d59c19a11e55f17baf12d92327c1258533d
2018-01-27 11:55:05 +01:00
Colleen Murphy 5fe9e3761d Rename application credential restriction column
In the application credential spec[1] we decided to add on a parameter
that would control whether an application credential could be used to
create other application credentials. This parameter is also used to
control whether it can be used to delete other application credentials
and whether it can create and delete trusts. Therefore the name
`allow_application_credential_creation` is misleading. Moreover, giving
a property of the resource a name that is an imperative verb is not
great. It makes more sense for a property to be a noun, an adjective, or
a passive verb.

This change renames the `allow_application_credential_creation`` column
to ``unrestricted``. This maintains the same boolean context, i.e. a
"true" value for the old name maintains the same meaning as a "true"
value for the new name.

At this point, the application credential API has not yet been exposed,
so there should be no data in this table and no need for complicated
migration triggers. In general, we only need to do a column alter to
rename it. Sqlite is special because it does not support column alters,
so in order to accomodate our tests the migration involves copying the
whole table, minus the old column, and recreating it with the new
column.

Change-Id: Id26a2790acae25f80bd28a8cb121c80cb5064645
2018-01-22 14:42:08 +01:00
Lance Bragstad d94d9c566f Add system column to app cred table
While the application credential logic was going through review we
noticed the project_id column of the table was not nullable. It is
possible for this to hinder the ability to create system-level
application credentials in the future.

For now, let's create a system column for application credentials
and alter the table so that project_ids can be nullable. This will
make it easier to expand application credential usage in the future.

bp application-credentials

Change-Id: I4e1104f95cc3c7567ee8f6edfe8515d45d154a9f
2018-01-19 15:03:03 +00:00
Colleen Murphy 716abfca59 Add Application Credentials manager
Add the manager layer for application credentials. This handles
generating CADF notifications on create/delete and listening for
notifications that affect application credentials' lifetime. On create,
the manager keeps a copy of the initial secret so that it may be
returned to the user, but it is otherwise never stored. The secret hash
is stored and must be filtered out before being returned to the user.

bp application-credentials

Change-Id: Iae6377e78d2b8e15472d378ef54e29a946dc51b5
2018-01-17 22:12:33 +01:00
Colleen Murphy 52a32aa583 Add application credentials driver
Add a sql model and driver for application credential CRUD operations
and authentication.

bp application-credentials

Change-Id: I192052434c0b0d49d1612824aec1034507dfd233
2018-01-17 20:56:53 +01:00