Skip to content

Commit 7ac1b75

Browse files
AymericDufvennetier
authored andcommitted
IAM: make Effect case insensitive, allow null Condition
Thanks to @fvennetier
1 parent 6934e6a commit 7ac1b75

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

swift3/iam.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
EXPLICIT_DENY = "DENY"
3535
RESOURCE_VERSION = "2012-10-17"
3636

37-
# Rule effect: allow
38-
RE_ALLOW = "Allow"
37+
# Actually "Allow" and "Deny" in all examples
38+
# but we will make them case-insensitive.
39+
# Rule effect: allow.
40+
RE_ALLOW = "allow"
3941
# Rule effect: deny
40-
RE_DENY = "Deny"
42+
RE_DENY = "deny"
4143

4244
# Resource type: object
4345
RT_OBJECT = "Object"
@@ -206,8 +208,8 @@ def check_condition(self, statement, req):
206208
:param statement: the statement dict using the condition
207209
:param req: the current request
208210
"""
209-
cond = statement.get('Condition', {})
210-
effect = statement['Effect']
211+
cond = statement.get('Condition') or dict()
212+
effect = statement['Effect'].lower() # case insensitive comparison
211213
for opname, operands in cond.items():
212214
if IamConditionOp.get(opname, None) is None:
213215
if effect == RE_ALLOW:
@@ -258,7 +260,7 @@ def do_explicit_check(self, effect, action, req_res, req):
258260
sid = statement.get('Sid', 'statement-id-%d' % num)
259261
self.logger.debug("===> Checking statement %s (%s)",
260262
sid, statement['Effect'])
261-
if statement['Effect'] != effect:
263+
if statement['Effect'].lower() != effect:
262264
continue
263265

264266
# Check Action

0 commit comments

Comments
 (0)