I’ve been writing an app that makes use of CloudFront signed URLs with a private S3 bucket as the origin. What’s the best way of storing the CloudFront private key?
I know there are lots of no-no’s when it comes to the storage of private keys. Since this is part of an EC2 ASG, I don’t want to just put the key in code or as part of the disk image - that just seems like it’s asking for trouble.
So what’s the preferred method here? I’m sure there’s more than one way to skin this cat…
One solution I can think of is storing it on a private S3 bucket, and grant access using bucket policy to the role your EC2 instances have. It may not be the best solution.
Someone on the ##aws IRC channel mentioned something similar to that. The difficulty is that the key still needs to be stored on disk after it’s read from S3. I suppose I could have it read from S3 in my init script and then store it somewhere in /etc/ ?
Yup, write a script to copy the file from S3, put that script into user data so that the instance will download it while startup. Since the instance use its role to authenticate the download action, no credential information needed in your script
Why does it need to be on disk? Just fetch the bits from S3 or parameter store/secrets manager and store them in memory when the app initializes. I would consider the key to be application config, not something the instance should worry about fetching.
Yup, as long as the file size doesn’t exceed Secrets Manager limit, using it would be better than S3. However, OP still need to grab the key and save as file as AWS SDK need a pem file to sign url