I have an AS2 ASG on AWS and I am interested in storing a shell script that was used to instantiate any instance in the S3 bucket and it loaded and started when the instance was created, but it all feels a bit shaky even though I use IAM Instance Role by transmitting via HTTPS and encrypting the script itself, being at rest in the bucket <3> using KMS using S3 Server Side Encryption ( because the KMS method selected an "Unknown" error ).
Customization
IAM Instance Role , which is assigned to any instance in my ASG after creating the instance, as a result, my AWS credits are baked into the instance as ENV vars- My
Instance-Init.sh script is uploaded and encrypted to S3, which leads to a private endpoint, for example: https://s3.amazonaws.com/super-secret-bucket/Instance-Init.sh
In the User-Data field
I enter the following into the User Data field when creating the Launch Configuration I want my ASG to use:
#!/bin/bash apt-get update apt-get -y install python-pip apt-get -y install awscli cd /home/ubuntu aws s3 cp s3://super-secret-bucket/Instance-Init.sh . --region us-east-1 chmod +x Instance-Init.sh . Instance-Init.sh shred -u -z -n 27 Instance-Init.sh
The above does the following:
- Service Pack Lists
- Installs Python (required to run
aws-cli ) - Installs
aws-cli - Changes to the
/home/ubuntu directory - Uses
aws-cli to download the Instance-Init.sh file from S3 . Due to the IAM Role assigned to my instance, my AWS credits are automatically detected by aws-cli . IAM Role also provides my instance with the permissions necessary to decrypt the file. - Makes it executable
- Runs the script
- Deletes a script after its completion.
Instance-Init.sh script
the script itself will do things like installing ENV vars and docker run containers, which I need to deploy on my instance. Kind:
#!/bin/bash export MONGO_USER='MyMongoUserName' export MONGO_PASS='Top-Secret-Dont-Tell-Anyone' docker login -u <username> -p <password> -e <email> docker run - e MONGO_USER=${MONGO_USER} -e MONGO_PASS=${MONGO_PASS} --name MyContainerName quay.io/myQuayNameSpace/MyAppName:latest
Very comfortably
This creates a very convenient way to update User-Data scripts without having to create a new Launch Config every time you need to make minor changes. And it does an excellent job of getting ENV vars from your code base and into a narrow controlled space ( Instance-Init.sh script itself).
But it all feels a little insecure. The idea of putting my master DB files in a file on S3 is a concern, to say the least.
Questions
- Is this a common practice or am I seeing a bad idea here?
- Is the fact that the file is downloaded and stored (albeit not for long) in a new instance is a vulnerability in general?
- Is there a better way to delete a file in a more secure way?
- Does it matter if the file is deleted after it is launched? Given that secrets are passed to
ENV vars, it seems almost unnecessary to delete the Instance-Init.sh file. - Is there something I miss in my nascent days?
Thanks for any help in advance.
bash shell amazon-s3 amazon-ec2
AJB Apr 29 '15 at 0:36 2015-04-29 00:36
source share