Skip to content

Commit dc415dc

Browse files
author
ravigurram8
committed
secure-desktop CFT update
1 parent 15909eb commit dc415dc

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

cft-templates/ec2-secure-desktop.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ Parameters:
5656
Type: Number
5757
Default: 32
5858

59+
AllowedIpAddress:
60+
Description: The IP address range that can be used to SSH to instance and Connect to DCV
61+
Type: String
62+
MinLength: "9"
63+
MaxLength: "18"
64+
Default: 0.0.0.0/0
65+
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
66+
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
5967

6068
Conditions:
6169
IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, "{}"]
@@ -126,6 +134,9 @@ Resources:
126134
ManagedPolicyArns:
127135
- Ref: SSMPolicy
128136
PermissionsBoundary: !Ref InstanceRolePermissionBoundary
137+
138+
139+
129140
InstanceProfile:
130141
Type: "AWS::IAM::InstanceProfile"
131142
Properties:
@@ -153,7 +164,7 @@ Resources:
153164
Type: AWS::EC2::Instance
154165
CreationPolicy:
155166
ResourceSignal:
156-
Timeout: PT20M
167+
Timeout: PT15M
157168
Metadata:
158169
AWS::CloudFormation::Init:
159170
configSets:
@@ -255,10 +266,10 @@ Resources:
255266
content: !Sub |
256267
#!/bin/sh
257268
set -x
258-
sleep 120
269+
sleep 25
259270
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep mate-session)/environ|cut -d= -f2- | tr -d '\0')
260271
gsettings set org.mate.interface gtk-theme "Graphite-Light"
261-
gsettings set org.mate.background picture-filename "/home/ec2-user/Graphite-gtk-theme-main/wallpaper/Graphite/wave-color.png"
272+
gsettings set org.mate.background picture-filename "/home/ec2-user/Graphite-gtk-theme-main/wallpaper/Graphite/wave-color.png"
262273
config2:
263274
commands:
264275
01_start_ext_auth:
@@ -267,7 +278,6 @@ Resources:
267278
02_set_user_token:
268279
cwd: "/home/ec2-user"
269280
command: "/home/ec2-user/set_user_token.sh"
270-
271281
Properties:
272282
UserData:
273283
Fn::Base64: !Sub |
@@ -277,11 +287,12 @@ Resources:
277287

278288
# Copy environment instance files needed for the workspace
279289
aws s3 cp --region "${AWS::Region}" "${EnvironmentInstanceFiles}/secure_desktop/secure_desktop.perm" "/etc/dcv/"
280-
281-
# Download and execute bootstrap script
282290
aws s3 cp --region "${AWS::Region}" "${EnvironmentInstanceFiles}/get_bootstrap.sh" "/tmp"
283291
chmod 500 "/tmp/get_bootstrap.sh"
284-
/tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}' "${AWS::Region}"
292+
/tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}' "" "${AWS::Region}"
293+
294+
# Install supervisor and start on boot
295+
# pip3 install supervisor crudini
285296

286297
# Route auth request to external authenticator and restart dcv
287298
/usr/local/bin/crudini --set /etc/dcv/dcv.conf security auth-token-verifier \"http://127.0.0.1:8445\"
@@ -290,7 +301,6 @@ Resources:
290301

291302
# Create dcv session start script
292303
cat << EOF > /usr/local/bin/start-dcv-session
293-
sleep 15
294304
dcv create-session rg-session --name rg-session --user ec2-user --owner ec2-user --permissions-file /etc/dcv/secure_desktop.perm
295305
EOF
296306

@@ -299,6 +309,8 @@ Resources:
299309
chmod 775 "/usr/local/bin/start-dcv-session"
300310
sh "/usr/local/bin/start-dcv-session"
301311

312+
sleep 5
313+
302314
# Run init script to create files
303315
/opt/aws/bin/cfn-init --verbose --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region}
304316

@@ -309,17 +321,17 @@ Resources:
309321
echo '@reboot /usr/local/bin/start-dcv-session 2>&1 >> /var/log/start-dcv-session.log' >> "/tmp/crontab"
310322
echo '@reboot /home/ec2-user/set_user_token.sh 2>&1 >> /var/log/set_user_token.log' >> "/tmp/crontab"
311323
crontab "/tmp/crontab"
312-
313324
# Restart DCV session to start dcv-session
314325
dcv close-session rg-session
315326
sh "/usr/local/bin/start-dcv-session"
316327

317328
# Remove password and lock for ec2-user
318329
passwd -l ec2-user
319330
dcv create-session lock-session --name lock-session --user ec2-user --owner ec2-user --init /home/ec2-user/disable_lock.sh
320-
321331
sudo -u ec2-user /home/ec2-user/themes.sh
322332

333+
334+
323335
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region}
324336

325337
InstanceType: !Ref "InstanceType"
@@ -370,6 +382,7 @@ Outputs:
370382
InstanceId:
371383
Description: InstanceId of the newly created EC2 instance
372384
Value: !Ref "EC2Instance"
385+
373386
ApplicationPort:
374387
Description: The Port in which the application is running
375388
Value: "8443"

scripts/bootstrap-scripts/get_bootstrap.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
bootstrap_s3_location="$1"
33
s3_mounts="$2"
44
rstudio_user="$3"
5+
region="$4"
6+
7+
if [ -z "$region" ]
8+
then
9+
region=us-east-2
10+
fi
511

612
INSTALL_DIR="/usr/local/share/workspace-environment"
713

814
# Download instance files and execute bootstrap script
915
sudo mkdir "$INSTALL_DIR"
10-
sudo aws s3 sync "$bootstrap_s3_location" "$INSTALL_DIR"
16+
sudo aws s3 sync "$bootstrap_s3_location" "$INSTALL_DIR" --region $region
1117

1218
bootstrap_script="$INSTALL_DIR/bootstrap.sh"
1319
if [ -s "$bootstrap_script" ]
@@ -17,3 +23,4 @@ then
1723
fi
1824

1925
exit 0
26+

0 commit comments

Comments
 (0)