Skip to content

Commit e2f6f9d

Browse files
author
Ranganath
committed
Added 'packaged' CFN template
1 parent 3170af7 commit e2f6f9d

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Description: Lambda function to rotate SSH keys
3+
Parameters:
4+
MasterWorkersStack:
5+
AllowedPattern: ^[a-zA-Z][-a-zA-Z0-9]*$
6+
Default: MasterWorkers
7+
Description: CloudFormation Stack Name for Master and Workers
8+
MaxLength: 255
9+
MinLength: 1
10+
Type: String
11+
TagName:
12+
AllowedPattern: ^[a-zA-Z][-a-zA-Z0-9]*$
13+
Default: RotateSSHKeys
14+
Description: Tag Name to locate Worker EC2 Instances to update with SSH Public
15+
Keys
16+
MaxLength: 255
17+
MinLength: 1
18+
Type: String
19+
TagValue:
20+
Default: 'True'
21+
Description: Tag Value to locate Worker EC2 Instances to update with SSH Public
22+
Keys
23+
MaxLength: 255
24+
MinLength: 1
25+
Type: String
26+
Username:
27+
AllowedPattern: ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$
28+
Default: ec2-user
29+
Description: Username for the Linux user that is used to log into the Workers
30+
MaxLength: 32
31+
MinLength: 1
32+
Type: String
33+
Resources:
34+
InvokePermission:
35+
Properties:
36+
Action: lambda:InvokeFunction
37+
FunctionName:
38+
Ref: RotateSSH
39+
Principal: secretsmanager.amazonaws.com
40+
Type: AWS::Lambda::Permission
41+
RotateSSH:
42+
Properties:
43+
CodeUri: s3://awsiammedia/public/sample/SecretsManagerStoreRotateSSHKeyPairs/rotate_ssh.zip
44+
Description: Rotates SSH Keys
45+
Environment:
46+
Variables:
47+
TAGNAME:
48+
Ref: TagName
49+
TAGVALUE:
50+
Ref: TagValue
51+
USERNAME:
52+
Ref: Username
53+
FunctionName: RotateSSH
54+
Handler: rotate.lambda_handler
55+
MemorySize: 1536
56+
Policies:
57+
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
58+
- arn:aws:iam::aws:policy/service-role/AWSLambdaENIManagementAccess
59+
- Statement:
60+
- Action:
61+
- secretsmanager:DescribeSecret
62+
- secretsmanager:GetSecretValue
63+
- secretsmanager:PutSecretValue
64+
- secretsmanager:UpdateSecretVersionStage
65+
Condition:
66+
StringEquals:
67+
secretsmanager:resource/AllowRotationLambdaArn:
68+
Fn::Sub: arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:RotateSSH
69+
Effect: Allow
70+
Resource:
71+
Fn::Sub: arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:/dev/ssh*
72+
Sid: SecretsManagerActions
73+
- Action:
74+
- ssm:SendCommand
75+
Effect: Allow
76+
Resource:
77+
- Fn::Sub: arn:aws:ssm:${AWS::Region}::document/AWS-RunShellScript
78+
Sid: SSMRunShellScriptDocument
79+
- Action:
80+
- ssm:SendCommand
81+
Condition:
82+
StringEquals:
83+
ssm:resourceTag/RotateSSHKeys:
84+
Ref: TagValue
85+
Effect: Allow
86+
Resource:
87+
- Fn::Sub: arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:instance/*
88+
Sid: SSMRunShellScriptOnTaggedInstances
89+
- Action:
90+
- ssm:ListCommandInvocations
91+
- ssm:GetCommandInvocation
92+
- ssm:ListCommands
93+
- ssm:DescribeInstanceInformation
94+
Effect: Allow
95+
Resource: '*'
96+
Sid: SSMTrackCommands
97+
- Action:
98+
- ec2:DescribeInstances
99+
Effect: Allow
100+
Resource: '*'
101+
Sid: EC2DescribeInstances
102+
Version: '2012-10-17'
103+
Runtime: python3.6
104+
Timeout: 300
105+
VpcConfig:
106+
SecurityGroupIds:
107+
- Fn::ImportValue:
108+
Fn::Sub: ${MasterWorkersStack}-MasterSecurityGroup
109+
SubnetIds:
110+
- Fn::ImportValue:
111+
Fn::Sub: ${MasterWorkersStack}-PrivateSubnet
112+
Type: AWS::Serverless::Function
113+
Transform: AWS::Serverless-2016-10-31

0 commit comments

Comments
 (0)