summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColleen Murphy <colleen@gazlene.net>2018-01-30 23:23:15 +0100
committerColleen Murphy <colleen.murphy@suse.de>2018-02-12 14:22:52 +0100
commitb6a009254f7975bf806c499874ad87746bb8cbd8 (patch)
tree1d5c4d16de9a014372b983814f4bb05961b5eb61
parent5c34cb43d373330534bdcf5feff64fb0abbb8cda (diff)
Delete SQL users before deleting domain
Since the users table has a foreign key to the projects table[1], users must be deleted before the domain can be deleted. However, the notification emitted from the domain deletion comes too late, and keystone runs into a foreign key reference error before it can delete the users. This patch addresses the problem by adding a new internal notification to alert the identity manager that users should be deleted. This uses a new notification rather than the existing notification because the existing one is used to alert listeners that the domain deletion has been fully completed, whereas this one must happen in the middle of the domain delete process. The callback must also only try to delete SQL users. The LDAP driver doesn't support deleting users, and we can't assume other drivers support it either. Moreover, the foreign key reference is only a problem for SQL users anyway. Because our backend unit tests run with SQLite and foreign keys do not work properly, we can't properly expose this bug in our unit tests, but there is an accompanying tempest test[2][3] to validate this fix. [1] https://github.com/openstack/keystone/blob/2bd88d3/keystone/common/sql/expand_repo/versions/014_expand_add_domain_id_to_user_table.py#L140-L141 [2] https://review.openstack.org/#/c/509610 [3] https://review.openstack.org/#/c/509947 Change-Id: If5bdb6f5eef80b50b000aed5188ce7da4dfd1083 Closes-bug: #1718747 (cherry picked from commit 62ee18b359cbb2e6a9469bdaac9057ef19de1bdf)
Notes
Notes (review): Code-Review+1: Lance Bragstad <lbragstad@gmail.com> Code-Review+1: Gage Hugo <gagehugo@gmail.com> Code-Review+2: Morgan Fainberg <morgan.fainberg@gmail.com> Workflow+1: Morgan Fainberg <morgan.fainberg@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 15 Feb 2018 05:28:34 +0000 Reviewed-on: https://review.openstack.org/543379 Project: openstack/keystone Branch: refs/heads/stable/ocata
-rw-r--r--keystone/identity/core.py21
-rw-r--r--keystone/notifications.py1
-rw-r--r--keystone/resource/core.py3
-rw-r--r--releasenotes/notes/bug-1718747-50d39fa87bdbb12b.yaml17
4 files changed, 36 insertions, 6 deletions
diff --git a/keystone/identity/core.py b/keystone/identity/core.py
index c97b6a7..5168bf0 100644
--- a/keystone/identity/core.py
+++ b/keystone/identity/core.py
@@ -487,17 +487,26 @@ class Manager(manager.Manager):
487 def __init__(self): 487 def __init__(self):
488 super(Manager, self).__init__(CONF.identity.driver) 488 super(Manager, self).__init__(CONF.identity.driver)
489 self.domain_configs = DomainConfigs() 489 self.domain_configs = DomainConfigs()
490 490 notifications.register_event_callback(
491 self.event_callbacks = { 491 notifications.ACTIONS.internal, notifications.DOMAIN_DELETED,
492 notifications.ACTIONS.deleted: { 492 self._domain_deleted
493 'domain': [self._domain_deleted], 493 )
494 }, 494 self.event_callbacks = {}
495 }
496 495
497 def _domain_deleted(self, service, resource_type, operation, 496 def _domain_deleted(self, service, resource_type, operation,
498 payload): 497 payload):
499 domain_id = payload['resource_info'] 498 domain_id = payload['resource_info']
500 499
500 driver = self._select_identity_driver(domain_id)
501
502 if not driver.is_sql:
503 # The LDAP driver does not support deleting users or groups.
504 # Moreover, we shouldn't destroy users and groups in an unknown
505 # driver. The only time when we should delete users and groups is
506 # when the backend is SQL because the foreign key in the SQL table
507 # forces us to.
508 return
509
501 user_refs = self.list_users(domain_scope=domain_id) 510 user_refs = self.list_users(domain_scope=domain_id)
502 group_refs = self.list_groups(domain_scope=domain_id) 511 group_refs = self.list_groups(domain_scope=domain_id)
503 512
diff --git a/keystone/notifications.py b/keystone/notifications.py
index 9354e66..8488ae0 100644
--- a/keystone/notifications.py
+++ b/keystone/notifications.py
@@ -78,6 +78,7 @@ CONF = keystone.conf.CONF
78INVALIDATE_USER_TOKEN_PERSISTENCE = 'invalidate_user_tokens' 78INVALIDATE_USER_TOKEN_PERSISTENCE = 'invalidate_user_tokens'
79INVALIDATE_USER_PROJECT_TOKEN_PERSISTENCE = 'invalidate_user_project_tokens' 79INVALIDATE_USER_PROJECT_TOKEN_PERSISTENCE = 'invalidate_user_project_tokens'
80INVALIDATE_USER_OAUTH_CONSUMER_TOKENS = 'invalidate_user_consumer_tokens' 80INVALIDATE_USER_OAUTH_CONSUMER_TOKENS = 'invalidate_user_consumer_tokens'
81DOMAIN_DELETED = 'domain_deleted'
81 82
82 83
83class Audit(object): 84class Audit(object):
diff --git a/keystone/resource/core.py b/keystone/resource/core.py
index 175ec6b..3c5c26c 100644
--- a/keystone/resource/core.py
+++ b/keystone/resource/core.py
@@ -757,6 +757,9 @@ class Manager(manager.Manager):
757 'first.')) 757 'first.'))
758 758
759 self._delete_domain_contents(domain_id) 759 self._delete_domain_contents(domain_id)
760 notifications.Audit.internal(
761 notifications.DOMAIN_DELETED, domain_id
762 )
760 self._delete_project(domain_id, initiator) 763 self._delete_project(domain_id, initiator)
761 try: 764 try:
762 self.get_domain.invalidate(self, domain_id) 765 self.get_domain.invalidate(self, domain_id)
diff --git a/releasenotes/notes/bug-1718747-50d39fa87bdbb12b.yaml b/releasenotes/notes/bug-1718747-50d39fa87bdbb12b.yaml
new file mode 100644
index 0000000..2ee2f44
--- /dev/null
+++ b/releasenotes/notes/bug-1718747-50d39fa87bdbb12b.yaml
@@ -0,0 +1,17 @@
1---
2fixes:
3 - |
4 [`bug 1718747 <https://bugs.launchpad.net/keystone/+bug/1718747>`_]
5 Fixes a regression where deleting a domain with users in it caues a server
6 error. This bugfix restores the previous behavior of deleting the users
7 namespaced in the domain. This only applies when using the SQL identity
8 backend.
9other:
10 - |
11 [`bug 1718747 <https://bugs.launchpad.net/keystone/+bug/1718747>`_]
12 As part of solving a regression in the identity SQL backend that prevented
13 domains containing users from being deleted, a notification callback was
14 altered so that users would only be deleted if the identity backend is SQL.
15 If you have a custom identity backend that is not read-only, deleting a
16 domain in keystone will not delete the users in your backend unless your
17 driver has an is_sql property that evaluates to true.