Skip to content

Commit 7402f5e

Browse files
mathrockttx
authored andcommitted
Ensure user and tenant enabled in EC2
Fixes bug 1121494. Change-Id: Ia9a149a93dec87f46b667100e0ee2eda56d9489d
1 parent e49390e commit 7402f5e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Maru Newby <[email protected]>
7575
Michael Basnight <[email protected]>
7676
Michael Still <[email protected]>
7777
Monty Taylor <[email protected]>
78+
Nathanael Burton <[email protected]>
7879
Pádraig Brady <[email protected]>
7980
Paul Voccio <[email protected]>
8081
Peng Yong <[email protected]>

keystone/contrib/ec2/core.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@
4343
from keystone import policy
4444
from keystone import service
4545
from keystone import token
46+
from keystone.common import logging
4647
from keystone.common import manager
4748
from keystone.common import utils
4849
from keystone.common import wsgi
4950

5051

5152
CONF = config.CONF
53+
LOG = logging.getLogger(__name__)
5254

5355

5456
class Manager(manager.Manager):
@@ -112,9 +114,9 @@ def check_signature(self, creds_ref, credentials):
112114
credentials['host'] = hostname
113115
signature = signer.generate(credentials)
114116
if not utils.auth_str_equal(credentials.signature, signature):
115-
raise exception.Unauthorized(message='Invalid EC2 signature.')
117+
raise exception.Unauthorized()
116118
else:
117-
raise exception.Unauthorized(message='EC2 signature not supplied.')
119+
raise exception.Unauthorized()
118120

119121
def authenticate(self, context, credentials=None,
120122
ec2Credentials=None):
@@ -145,7 +147,7 @@ def authenticate(self, context, credentials=None,
145147
credentials = ec2Credentials
146148

147149
if not 'access' in credentials:
148-
raise exception.Unauthorized(message='EC2 signature not supplied.')
150+
raise exception.Unauthorized()
149151

150152
creds_ref = self._get_credentials(context,
151153
credentials['access'])
@@ -157,9 +159,19 @@ def authenticate(self, context, credentials=None,
157159
tenant_ref = self.identity_api.get_tenant(
158160
context=context,
159161
tenant_id=creds_ref['tenant_id'])
162+
# If the tenant is disabled don't allow them to authenticate
163+
if tenant_ref and not tenant_ref.get('enabled', True):
164+
msg = 'Tenant %s is disabled' % tenant_ref['id']
165+
LOG.warning(msg)
166+
raise exception.Unauthorized()
160167
user_ref = self.identity_api.get_user(
161168
context=context,
162169
user_id=creds_ref['user_id'])
170+
# If the user is disabled don't allow them to authenticate
171+
if not user_ref.get('enabled', True):
172+
msg = 'User %s is disabled' % user_ref['id']
173+
LOG.warning(msg)
174+
raise exception.Unauthorized()
163175
metadata_ref = self.identity_api.get_metadata(
164176
context=context,
165177
user_id=user_ref['id'],
@@ -170,7 +182,7 @@ def authenticate(self, context, credentials=None,
170182
# fill out the roles in the metadata
171183
roles = metadata_ref.get('roles', [])
172184
if not roles:
173-
raise exception.Unauthorized(message='User not valid for tenant.')
185+
raise exception.Unauthorized()
174186
roles_ref = [self.identity_api.get_role(context, role_id)
175187
for role_id in roles]
176188

@@ -275,7 +287,7 @@ def _get_credentials(self, context, credential_id):
275287
creds = self.ec2_api.get_credential(context,
276288
credential_id)
277289
if not creds:
278-
raise exception.Unauthorized(message='EC2 access key not found.')
290+
raise exception.Unauthorized()
279291
return creds
280292

281293
def _assert_identity(self, context, user_id):

0 commit comments

Comments
 (0)