DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

WHAT IS A SECRET?

A secret is any piece of sensitive information that must be protected from unauthorized access.

Examples:

  • API keys
  • Access tokens
  • Database passwords
  • Private keys (.pem)
  • Confluent Cloud credentials
  • Terraform backend credentials
  • OAuth tokens
  • SSH keys

Goal: Keep secrets encrypted at rest, encrypted in transit, and never stored in plaintext (repo, logs, artifacts).


πŸ”₯ 2. WHY SECRETS MANAGEMENT IS CRITICAL

A senior DevOps engineer must prevent:

  • Credential leaks
  • Unauthorized access
  • Accidental commits to Git
  • Hardcoding in Terraform, Kubernetes, Docker, or CI/CD

Secrets leaks cause:

  • Environment compromise
  • Data breaches
  • Unauthorized AWS usage costing thousands
  • Repository takeovers

This is why we use secure secret stores, not files.


🟦 3. SECRET STORAGE OPTIONS DevOps MUST know

There are 4 main secret management solutions you must understand:

Tool Where Used Strengths Weaknesses
GitHub Secrets GitHub CI/CD Easy to use, encrypted Not for runtime apps
AWS Secrets Manager Apps running on AWS Automatic rotation, IAM integration Expensive at scale
AWS SSM Parameter Store AWS Systems Manager Cheaper than Secrets Manager Rotation not native
HashiCorp Vault Enterprise multi-cloud Most secure, dynamic secrets Complex to manage

🟩 4. GITHUB SECRETS β€” Used for CI/CD Only

βœ” Where used:

  • GitHub Actions CI/CD pipelines

βœ” What it stores:

  • AWS access key + secret key
  • Docker registry token
  • Terraform Cloud token
  • Confluent Cloud credentials
  • Any deployment API keys

βœ” How it works:

  • GitHub encrypts the secret with libsodium
  • Only GitHub Actions that run in your repository can access it
  • Not available to fork PRs

βœ” Security rules for senior DevOps:

  • Never store database passwords here for applications
  • Never store long-lived AWS keys (prefer OIDC)
  • Rotate keys every 90 days
  • Give repositories minimum access
  • Avoid storing complex JSON β€” use AWS Parameter Store instead

❌ GitHub Secrets DO NOT replace:

  • Secrets Manager
  • Vault
  • Kubernetes Secrets
  • Application runtime secrets

GitHub Secrets are ONLY for CI/CD.


πŸŸ₯ 5. AWS SECRETS MANAGER β€” Production-grade secret storage

βœ” Where used:

Production microservices on AWS.

βœ” Features:

  • Automatic rotation (Lambda)
  • Version history
  • Multi-account access with IAM
  • Replication across regions
  • KMS encryption (built-in)

βœ” Typical use cases:

  • Store RDS master password
  • Store Confluent API secret
  • Store Stripe keys
  • Store OAuth tokens
  • Store DB credentials for ECS tasks

βœ” Access via IAM:

ecsTaskExecutionRole:
  can access secret: arn:aws:secretsmanager:...
Enter fullscreen mode Exit fullscreen mode

βœ” Code example (ECS task environment):

{
  "name": "DB_PASSWORD",
  "valueFrom": "arn:aws:secretsmanager:us-east-2:xxx:secret:db_pass"
}
Enter fullscreen mode Exit fullscreen mode

❗ When to choose Secrets Manager:

  • You need rotation
  • You need strict auditing
  • You manage cross-account apps

🟨 6. AWS SSM PARAMETER STORE

(SecureString parameters)

βœ” Cheaper alternative to Secrets Manager

Costs: $0 for Standard tier
(Secrets Manager costs $0.40 per secret per month)

βœ” Good for Dev / QA / Non-critical secrets

βœ” Use cases:

  • Microservice configs
  • Non-rotating tokens
  • S3 bucket names
  • Feature flags

❗ NOT recommended

for production database passwords (no rotation).


πŸŸͺ 7. HASHICORP VAULT β€” The most advanced system

This is enterprise-level secret management.

βœ” Why Vault is used:

  • Supports AWS, GCP, Azure, Kubernetes, On-prem
  • Dynamic secrets (temporary DB creds)
  • Encryption as a service (Transit)
  • PKI certificate generation
  • Fine-grained access policies
  • Audit logs
  • Can run on-prem or as HCP Vault Cloud

βœ” Dynamic secrets example:

Vault generates:

  • A PostgreSQL username/password
  • Valid for 1 hour
  • Automatically deleted afterward

Perfect for:

  • Short-lived CI/CD tasks
  • High-security environments
  • Banks, healthcare, fintech

βœ” Vault is used by:

  • Uber
  • Stripe
  • Goldman Sachs
  • Netflix

🟦 8. Kubernetes Secrets (Optional but DevOps MUST know)

βœ” Stored inside etcd (encrypted with KMS in prod)

βœ” Used for:

  • API keys
  • DB passwords
  • TLS certs

βœ” Mounted as:

  • env variables
  • files

🟫 9. Terraform & Secrets β€” Senior Level Knowledge

Terraform NEVER stores secrets in:

  • Git
  • tf files
  • modules

❗❗ Secrets MUST be passed via:

  • terraform.tfvars (locally only)
  • CI/CD environment variables
  • SSM Parameter Store
  • Secrets Manager

βœ” Example bad code (DO NOT DO):

password = "MySecret123"
Enter fullscreen mode Exit fullscreen mode

βœ” Good:

password = var.db_password
Enter fullscreen mode Exit fullscreen mode

βœ” Best:

password = data.aws_secretsmanager_secret_version.db_password.secret_string
Enter fullscreen mode Exit fullscreen mode

🟩 10. How Secrets Flow in a Real CI/CD Pipeline

Example using GitHub Actions + AWS Secrets Manager:

Step 1:

Secrets stored in Secrets Manager

Step 2:

EC2/ECS Lambda uses IAM role to access secrets

Step 3:

GitHub Actions stores only:

  • AWS Access Key
  • Secret Key
  • Confluent API key

Step 4:

Terraform deploys infrastructure
β†’ references secrets with ARN

Step 5:

Applications retrieve secrets using:

  • AWS SDK
  • IAM role permissions

πŸŸ₯ 11. What NOT TO DO (Senior DevOps Knowledge)

❌ Never store secrets in GitHub repository
❌ Never store secrets in Slack or Teams
❌ Never store secrets in Docker image
❌ Never store secrets in YAML files
❌ Never store secrets in Terraform state
❌ Never store secrets in code comments
❌ Never echo secrets in CI logs
❌ Never send secrets in email

If leaked β†’ rotate immediately.


🟦 12. Interview-Level Explanation (You can say this)

β€œIn my pipelines, GitHub Secrets are used only for CI/CD credentials.
For application runtime secrets, I use AWS Secrets Manager or SSM Parameter Store depending on rotation requirements.
I avoid hardcoding secrets in Terraform by pulling them from the secret stores at runtime.
For enterprise multi-cloud environments, I integrate HashiCorp Vault with AWS IAM and Kubernetes service accounts for secure authentication and dynamic secrets.
All secrets are KMS-encrypted and never exposed in logs.”

This is senior-level.

*πŸ”΅ SECRETS FLOW β€” High-Level Diagram *

                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚     Developer Machine     β”‚
                        β”‚    (Push Git Changes)     β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                      β”‚
                                      β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚    GitHub Repository    β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                      β”‚
                                      β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚     GitHub Actions Runner     β”‚
                         β”‚   (CI/CD Workflow Execution)  β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      SECRETS ENTER HERE FROM GITHUB β†’  β”‚ 
                                      β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚                           GitHub Secrets Storage                               β”‚
   β”‚    - AWS_ACCESS_KEY_ID                                                         β”‚
   β”‚    - AWS_SECRET_ACCESS_KEY                                                     β”‚
   β”‚    - CONFLUENT_API_KEY                                                         β”‚
   β”‚    - CONFLUENT_API_SECRET                                                      β”‚
   β”‚    - EXISTING_VPC_ID                                                           β”‚
   β”‚    - SUBNETS / SG IDs                                                          β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚ ENV VARIABLES PASSED TO TERRAFORM
                   β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚            TERRAFORM ENGINE           β”‚
        β”‚   terraform init / plan / apply       β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
         TERRAFORM USES SECRETS β†’ β”‚ 
                                  β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚          AWS Terraform Provider              β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
────────────────────────────────────────────────────────────────────────
β”‚                         AWS Cloud                                     β”‚
β”‚                                                                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚                     AWS IAM (Identity)                          β”‚   β”‚
β”‚   β”‚   - Permissions for Terraform                                   β”‚   β”‚
β”‚   β”‚   - Permissions for ECS tasks                                   β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚              AWS Secrets Manager / Parameter Store              β”‚   β”‚
β”‚   β”‚   - Terraform can CREATE secrets here                           β”‚   β”‚
β”‚   β”‚   - ECS tasks retrieve secrets automatically                    β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚                        AWS ECS Cluster                         β”‚   β”‚
β”‚   β”‚   - Backend container                                           β”‚   β”‚
β”‚   β”‚   - Producer container                                          β”‚   β”‚
β”‚   β”‚   - Payment / Fraud / Analytics                                 β”‚   β”‚
β”‚   β”‚   - Containers read secrets at runtime                          β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                                        β”‚
────────────────────────────────────────────────────────────────────────
Enter fullscreen mode Exit fullscreen mode

πŸ” Explanation of Every Secret Component

Everything explained as a senior DevOps must understand.


#1 β€” GitHub Secrets (CI/CD)

GitHub Secrets are stored encrypted in GitHub.
They are used only during workflow execution.

Used in your project:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • RDS_PASSWORD
  • CONFLUENT_API_KEY
  • CONFLUENT_API_SECRET
  • VPC_ID / SUBNET_IDS / SG_IDS

GitHub Secrets lifetime:

  • Used only during pipeline execution
  • Not accessible after the run
  • Good for CI/CD only, NOT for runtime

#2 β€” AWS Secrets Manager

This is AWS’s official secret storage system.

What you store here:

  • Database passwords
  • API keys
  • Confluent secrets
  • JWT secrets
  • Backend environment variables

Why AWS Secrets Manager is better than GitHub Secrets:

GitHub Secrets = CI/CD
AWS Secrets = Runtime

ECS Tasks β†’ automatically fetch secrets from Secrets Manager and inject into containers.

Benefits:

  • Automatic rotation
  • KMS encryption
  • IAM auth
  • Direct injection into ECS Task Definitions
  • No need to expose environment variables in Terraform

#3 β€” AWS Parameter Store (SSM)

Simpler version of Secrets Manager.

When to use:

  • When you need configuration (not secrets)
  • When cost matters (cheaper than Secrets Manager)
  • When you need infrastructure parameters

Sample:

  • /backend/SERVICE_URL
  • /kafka/bootstrap
  • /env/prod/feature-flag

#4 β€” HashiCorp Vault (Senior-level DevOps Topic)

Vault is used in enterprise environments for high-grade secret management.

Why Vault?

  • Dynamic secrets (MySQL, AWS IAM, Kafka credentials)
  • Zero-trust access
  • Multi-cloud support
  • Token-based authentication
  • Secret leasing (expires automatically)
  • Audit logs

Vault is often used when:

  • You have Kubernetes clusters
  • You need dynamic credentials
  • You need multi-cloud
  • You need compliance (PCI, HIPAA)
  • You need secret encryption policies

#5 β€” Terraform and Secrets

Terraform itself should never store secrets in .tf files.

Correct ways:

  1. Pass secrets through TF_VAR_* from GitHub
  2. Read secrets from Secrets Manager
  3. Use Sensitive = true variables

Incorrect:

  • Hardcoding secrets
  • Committing terraform.tfvars with passwords

#6 β€” How Secrets flow in YOUR project

Step 1 β€” GitHub Actions Reads GitHub Secrets

GitHub Secrets β†’ environment variables β†’ Terraform variables

Step 2 β€” Terraform writes:

  • VPC, subnets, SGs
  • RDS
  • ECS cluster
  • Task definitions
  • ALB

Step 3 β€” Optional: Terraform can push secrets to AWS Secrets Manager

Then ECS Task Definitions read from Secrets Manager at runtime.


#7 β€” Interview-Level Summary

A Senior DevOps must know:

βœ” GitHub Secrets

Used for pipeline-level secrets only.

βœ” AWS Secrets Manager

For production runtime secrets.

βœ” AWS Parameter Store

For configuration and non-secret values.

βœ” HashiCorp Vault

Enterprise-grade, dynamic secrets, KMS integration.

βœ” Terraform Secrets Handling

Never hardcode.
Use TF_VAR + Secrets Manager injection.

βœ” ECS Secret Injection

ECS can read secrets directly
(no environment variables exposed).


🟦 B β€” Interview Cheat Sheet

Here are short, crisp answers:

❓What is GitHub Secrets?

Pipeline-only encrypted secret store.
Used to authenticate Terraform, Docker, AWS during CI/CD.

❓Why not store runtime secrets in GitHub?

Because GitHub Secrets only live during CI/CD.
Containers need secrets at runtime β†’ use AWS Secrets Manager.

❓What is AWS Secrets Manager?

Fully managed encrypted secret store with rotation, IAM, audit logging.

❓What is Parameter Store?

Cheaper config store for non-secrets.

❓What is HashiCorp Vault?

Enterprise secret management offering dynamic credentials and zero-trust access.

❓How does Terraform handle secrets?

Use sensitive variables + backend secrets.
Never commit secrets.

❓How does ECS access secrets?

Through β€œvalueFrom” Secrets Manager ARNs in the task definition.

Top comments (0)