Terraform Password Protection of AWS, GCP, and Azure resources

Search for a command to run...

No comments yet. Be the first to comment.
State management lies at the heart of building large-scale React and Next.js applications, ensuring that data flows predictably and efficiently across various components and also between client and server for server-side rendered pages. Redux, a powe...

Monitoring is an essential aspect of maintaining the health and performance of your web applications. It's important because it helps you catch problems before they become big issues. It also makes sure your programs run smoothly with optimized resou...

In the startup hassle, product development is always the highest priority, and due to this race to build and ship products in a very short period, we generally forget to follow some basic coding practices. One of the problems among them is the use of...

Infinite Scrolling with Collapsible Headers: The Virtual Approach UI Scroll: Scrolling is a method used to display data when it is not possible to fit all the content onto a single page. This implementation is commonly seen on most websites, such as ...

After working for a couple of startups and MNCs, in my final year of engineering, I got an opportunity to work with one of the most amazing startups in India, BharatPe. The best thing which attracted me to join BharatPe is the company's goals and its...

Problem Statement
Nowadays DevOps guys use terraform quite a lot for creating resources in AWS, GCP, or AZURE cloud platforms. But while maintaining terraform versioning they use various Version Control Systems like git, bitbucket and while pushing the code they do commit the passwords in plaintext which are required to create resources like AWS RDS, documentDB, etc.

So to protect our sensitive information like plaintext passwords which in our case is “password” we can do a few changes in our terraform code to get rid of this problem without using any 3rd party tools.
Resolution
Here Let’s take an example of creating AWS RDS as a resource from terraform. Create a directory “sensitive-information” to store your password file separately.
mkdir sensitive-information
cd sensitive-information
Create a JSON file to store your password
echo “{ \”password\”: \”ourpassword\” }” >> sensitive-information/rds_pass.json
Not we will use the data module of terraform to read the AWS RDS password from the JSON file.

Now we are almost done just passing this data as a password in the aws_db_instance resource.

or if we have set up the module-wise architecture of terraform we can also add this to the main directory from where you are calling this aws_db_instance resource a module.

Now we are good to go just encrypt the rds_pass.json and you will get rds_pass.json.gpg
gpg -o sensitive-information/rds_pass.json.gpg \ — batch \ — symmetric \ — openpgp \ — cipher-algo AES256 \ — s2k-cipher-algo AES256 \ — s2k-digest-algo SHA512 \ — s2k-mode 3 \ — s2k-count 65011712 \ — armor \ — emit-version \ sensitive-information/rds_pass.json
Now you can add rds_pass.json in your .gitignore and push the changes in git only rds_pass.json.gpg file will be committed later you can use that file to decrypt your passwords.
Note
I hope this article will help you to protect your passwords from exposure, these issues are being faced by the company who are in their beginning phase to starting with terraform and got into securities issues of exposing passwords or any other sensitive information.