7
7
AWS_ACCOUNT_NUMBER ,
8
8
AWS_REGION ,
9
9
LAMBDA_TYPE ,
10
+ SFN_TYPE ,
10
11
RUN_TASK_LAMBDA_NAME ,
11
12
CHECK_TASK_LAMBDA_NAME
12
13
)
@@ -20,6 +21,7 @@ class IAM(object):
20
21
account_id = AWS_ACCOUNT_NUMBER
21
22
region = AWS_REGION
22
23
lambda_type = LAMBDA_TYPE # lambda_type : '' for unicorn, 'pony' for pony, 'zebra' for zebra
24
+ sfn_type = SFN_TYPE # sfn type : 'unicorn' for unicorn, 'pony' for pony, 'zebra' for zebra
23
25
run_task_lambda_name = RUN_TASK_LAMBDA_NAME
24
26
check_task_lambda_name = CHECK_TASK_LAMBDA_NAME
25
27
@@ -48,6 +50,7 @@ def __init__(self, user_group_tag, bucket_names='', no_randomize=True):
48
50
random_tag = str (int (random .random () * 10000 ))
49
51
self .user_group_name = self .user_group_tag + '_' + random_tag
50
52
self .tibanna_policy_prefix = self .prefix + self .user_group_name
53
+ self .tibanna_sfn_name = self .prefix + self .sfn_type + '_' + self .user_group_name
51
54
52
55
# bucket names
53
56
self .bucket_names = bucket_names
@@ -63,7 +66,8 @@ def iam_group_name(self):
63
66
@property
64
67
def policy_types (self ):
65
68
return ['bucket' , 'termination' , 'list' , 'cloudwatch' , 'passrole' , 'lambdainvoke' ,
66
- 'desc_stepfunction' , 'cloudwatch_metric' , 'cw_dashboard' , 'dynamodb' , 'ec2_desc' ]
69
+ 'cloudwatch_metric' , 'cw_dashboard' , 'dynamodb' , 'ec2_desc' ,
70
+ 'executions' ]
67
71
68
72
def policy_arn (self , policy_type ):
69
73
return 'arn:aws:iam::' + self .account_id + ':policy/' + self .policy_name (policy_type )
@@ -75,11 +79,11 @@ def policy_suffix(self, policy_type):
75
79
'cloudwatch' : 'cloudwatchlogs' ,
76
80
'passrole' : 'iam_passrole_s3' ,
77
81
'lambdainvoke' : 'lambdainvoke' ,
78
- 'desc_stepfunction' : 'desc_sts' ,
79
82
'cloudwatch_metric' : 'cw_metric' ,
80
83
'cw_dashboard' : 'cw_dashboard' ,
81
84
'dynamodb' : 'dynamodb' ,
82
- 'ec2_desc' : 'ec2_desc' }
85
+ 'ec2_desc' : 'ec2_desc' ,
86
+ 'executions' : 'executions' }
83
87
if policy_type not in suffices :
84
88
raise Exception ("policy %s must be one of %s." % (policy_type , str (self .policy_types )))
85
89
return suffices [policy_type ]
@@ -94,11 +98,11 @@ def policy_definition(self, policy_type):
94
98
'cloudwatch' : self .policy_cloudwatchlogs ,
95
99
'passrole' : self .policy_iam_passrole_s3 ,
96
100
'lambdainvoke' : self .policy_lambdainvoke ,
97
- 'desc_stepfunction' : self .policy_desc_stepfunction ,
98
101
'cloudwatch_metric' : self .policy_cloudwatch_metric ,
99
102
'cw_dashboard' : self .policy_cw_dashboard ,
100
103
'dynamodb' : self .policy_dynamodb ,
101
- 'ec2_desc' : self .policy_ec2_desc_policy }
104
+ 'ec2_desc' : self .policy_ec2_desc_policy ,
105
+ 'executions' : self .policy_executions }
102
106
if policy_type not in definitions :
103
107
raise Exception ("policy %s must be one of %s." % (policy_type , str (self .policy_types )))
104
108
return definitions [policy_type ]
@@ -128,7 +132,7 @@ def role_service(self, role_type):
128
132
129
133
def policy_arn_list_for_role (self , role_type ):
130
134
run_task_custom_policy_types = ['list' , 'cloudwatch' , 'passrole' , 'bucket' , 'dynamodb' ,
131
- 'desc_stepfunction ' , 'cw_dashboard' ]
135
+ 'executions ' , 'cw_dashboard' ]
132
136
check_task_custom_policy_types = ['cloudwatch_metric' , 'cloudwatch' , 'bucket' , 'ec2_desc' ,
133
137
'termination' , 'dynamodb' ]
134
138
arnlist = {'ec2' : [self .policy_arn (_ ) for _ in ['bucket' , 'cloudwatch_metric' ]] +
@@ -268,18 +272,32 @@ def policy_lambdainvoke(self):
268
272
return policy
269
273
270
274
@property
271
- def policy_desc_stepfunction (self ):
272
- execution_arn_prefix = 'arn:aws:states:' + self .region + ':' + self .account_id + ':execution:'
273
- resource = execution_arn_prefix + self .tibanna_policy_prefix + ':*'
275
+ def policy_executions (self ):
276
+ execution_arn_prefix = 'arn:aws:states:' + self .region + ':' + self .account_id + ':stateMachine:'
277
+ sfn_arn_prefix = 'arn:aws:states:' + self .region + ':' + self .account_id + ':execution:'
278
+ resources = [execution_arn_prefix + self .tibanna_sfn_name ,
279
+ sfn_arn_prefix + self .tibanna_sfn_name + ':*' ]
274
280
policy = {
275
281
"Version" : "2012-10-17" ,
276
282
"Statement" : [
277
283
{
278
284
"Effect" : "Allow" ,
279
285
"Action" : [
280
- "states:DescribeExecution"
286
+ "states:StartExecution" ,
287
+ "states:StopExecution" ,
288
+ "states:ListExecutions" ,
289
+ "states:DescribeExecution" ,
290
+ "states:GetExecutionHistory" ,
291
+ "states:DescribeStateMachineForExecution" ,
292
+ "states:DescribeStateMachine"
281
293
],
282
- "Resource" : resource
294
+ "Resource" : resources
295
+ },
296
+ {
297
+ "Sid" : "VisualEditor1" ,
298
+ "Effect" : "Allow" ,
299
+ "Action" : "states:ListStateMachines" ,
300
+ "Resource" : "*"
283
301
}
284
302
]
285
303
}
@@ -421,16 +439,6 @@ def create_user_group(self, verbose=False):
421
439
# deleting a group would require users to be detached from the group.
422
440
self .detach_policies_from_group ()
423
441
group = self .iam .Group (self .iam_group_name )
424
- response = group .attach_policy (
425
- PolicyArn = 'arn:aws:iam::aws:policy/AWSStepFunctionsFullAccess'
426
- )
427
- if verbose :
428
- logger .debug ("response from IAM attach_policy :" + str (response ))
429
- response = group .attach_policy (
430
- PolicyArn = 'arn:aws:iam::aws:policy/AWSStepFunctionsConsoleFullAccess'
431
- )
432
- if verbose :
433
- logger .debug ("response from IAM attach_policy :" + str (response ))
434
442
response = group .attach_policy (
435
443
PolicyArn = 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
436
444
)
@@ -441,7 +449,8 @@ def create_user_group(self, verbose=False):
441
449
)
442
450
if verbose :
443
451
logger .debug ("response from IAM attach_policy :" + str (response ))
444
- custom_policy_types = ['bucket' , 'ec2_desc' , 'cloudwatch_metric' , 'dynamodb' , 'termination' ]
452
+ custom_policy_types = ['bucket' , 'ec2_desc' , 'cloudwatch_metric' , 'dynamodb' ,
453
+ 'termination' , 'executions' ]
445
454
for pn in [self .policy_name (pt ) for pt in custom_policy_types ]:
446
455
response = group .attach_policy (
447
456
PolicyArn = 'arn:aws:iam::' + self .account_id + ':policy/' + pn
0 commit comments