Skip to content
tezvyn:

How do you manage secrets within IaC configurations?

Source: github.comMediumHow cards are made

This tests secret injection and the security-complexity tradeoff in IaC. A strong answer contrasts a cloud secret manager with encrypted files or env vars, covering rotation and blast radius. A red flag is plaintext secrets in Git or state files.

What's really being asked

This question probes whether you understand that Infrastructure as Code is fundamentally code that gets executed, which means secrets embedded in it create a persistent attack surface across version history, state files, and execution logs. The interviewer is looking for awareness of the secret lifecycle: generation, distribution, rotation, revocation, and auditing. They also want to see that you treat CI/CD pipelines and orchestrators as untrusted boundaries rather than safe zones for plaintext credentials.

The full answer

First, contrast a dedicated secrets manager such as AWS Secrets Manager, Azure Key Vault, or HashiCorp Vault against encrypted files in version control like SOPS or git-crypt. For the secrets manager, note the pros of automatic rotation, fine-grained IAM policies, centralized audit logs, and dynamic secrets that expire; note the cons of network dependency, cost, and operational overhead. For encrypted files in Git, note the pros of simplicity and git-native versioning; note the cons of key distribution challenges, risk of key leakage, and difficulty of fine-grained revocation. Second, treat environment variables as runtime injection only, not storage, since they leak in process listings and crash reports. Third, address IaC state files, since Terraform and Pulumi can store secrets in plaintext state unless remote backends encrypt at rest and enforce strict IAM. Fourth, discuss runtime injection via init containers, sidecars, or CI/CD references that fetch credentials at deploy time rather than baking them into images.

The mistakes people make

Storing plaintext secrets in Git, Terraform variables files, or Docker images. Treating environment variables as a secure vault rather than a transport layer. Ignoring Terraform state file security entirely. Proposing manual secret rotation without automation. Claiming that private repositories are sufficient protection. Failing to mention that logs and crash dumps can capture secrets if they are passed as command-line arguments or plain text outputs.

What usually comes next

How would you rotate a database credential without causing an outage? What is your strategy if your Terraform state file already contains a plaintext secret? How do you handle secrets in a multi-cloud or hybrid environment? What is the blast radius if your CI/CD runner is compromised, and how does your design limit it? How do you audit which human or service accessed a secret and when?

A concrete example

Suppose you are deploying an Amazon RDS instance with Terraform. Instead of putting the master password in a terraform.tfvars file, you store it in AWS Secrets Manager with automatic rotation enabled via a Lambda function. Your Terraform configuration references the secret ARN, not the value, and retrieves it through a data source at apply time. The Terraform remote state backend lives in an S3 bucket with server-side encryption and a strict bucket policy denying all but the deployment role. Application pods in EKS retrieve the same secret at startup via the Secrets Store CSI Driver, so the credential never lives in the container image or the manifest in Git. If the secret rotates, the next pod restart picks up the new value without a code change, and AWS CloudTrail logs every retrieval for audit.

Interview question

When configuring Terraform for an RDS database, which approach best limits secret exposure across version history and state files?

  • a.Store the master password in AWS Secrets Manager with rotation enabled, reference the ARN in Terraform, and use an encrypted remote state backendCorrect
  • b.Encrypt the master password with git-crypt and commit it to the same repository as the Terraform code
  • c.Pass the master password as an environment variable to the Terraform apply step
  • d.Store the master password in terraform.tfvars inside a private Git repository
Why?

AWS Secrets Manager keeps the actual value out of code and enables automatic rotation and fine-grained access control, while an encrypted remote state backend prevents plaintext storage in state files. Passing the password via an environment variable is a common shortcut, but environment variables leak in process listings, crash reports, and potentially logs.

Just read this? Test yourself on what you have been reading.

Read the original → github.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles