-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
117 lines (106 loc) · 3.24 KB
/
template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: >
Creates and maps IAM role Arns created by SSO to predictable names in AWS Parameter store
Parameters:
ParameterStorePrefix:
Type: String
Description: Prefix for the parameters in parameter store
Default: /attini/aws-sso-role-names/
S3Bucket:
Type: String
Description: Name of S3 bucket containing packaged code
Default: attini-artifacts-us-east-1
S3BucketKey:
Type: String
Description: Packaged code
Default: __S3_KEY__
Schedule:
Type: String
Description: Cron/Rate Expression https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html
Default: cron(0 0 1 * ? *)
Resources:
TriggerOnSchedule:
Type: AWS::Events::Rule
Properties:
Description: Triggers on schedule
ScheduleExpression: !Ref Schedule
Targets:
- Arn: !GetAtt DistributeSSORoles.Arn
Id: DistributeSSORoles
Input: '{"ExecutionType": "Sync"}'
TriggerOnEvent:
Type: AWS::Events::Rule
Properties:
Description: Triggers on the creation/deletion of an SSO PermissionSet role
EventPattern: |
{
"source": [
"aws.iam"
],
"detail-type": [
"AWS API Call via CloudTrail"
],
"detail": {
"eventSource": [
"iam.amazonaws.com"
],
"userAgent": [
"sso.amazonaws.com"
],
"eventName": [
"CreateRole",
"DeleteRole"
]
}
}
Targets:
- Arn: !GetAtt DistributeSSORoles.Arn
Id: DistributeSSORoles
TriggerLambda:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt DistributeSSORoles.Arn
Principal: events.amazonaws.com
DistributeSSORolesLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub
- /aws/lambda/${LambdaName}
- { LambdaName: !Ref DistributeSSORoles }
RetentionInDays: 90
DistributeSSORoles:
Type: AWS::Serverless::Function
Properties:
PackageType: Zip
CodeUri:
Bucket: !Ref S3Bucket
Key: !Ref S3BucketKey
Description: This lambda maps IAM role names created by SSO to simple names in AWS Parameter store.
Handler: not.used.in.provided.runtime
MemorySize: 512
Runtime: provided
Timeout: 900
Environment:
Variables:
PARAMETER_STORE_PREFIX: !Ref ParameterStorePrefix
DISABLE_SIGNAL_HANDLERS: true
Policies:
Statement:
- Effect: Allow
Action:
- ssm:PutParameter
- ssm:DeleteParameter
- ssm:DeleteParameters
Resource: !Sub arn:aws:ssm:*:${AWS::AccountId}:parameter${ParameterStorePrefix}*
- Effect: Allow
Action:
- ssm:GetParametersByPath
Resource:
- arn:aws:ssm:*::parameter/aws/service/global-infrastructure/regions
- !Sub arn:aws:ssm:*:${AWS::AccountId}:parameter/*
- Effect: Allow
Action:
- iam:ListRoles
Resource: "*"