Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Security & DevOps: Scenario-Based Questions

87. How do you securely manage secrets in CI/CD pipelines and infrastructure?

Secrets — like API keys, DB credentials, and tokens — are critical assets. Mishandling them can lead to breaches, outages, or compliance issues. Secure handling in pipelines and infra is non-negotiable.

🔐 What Counts as a Secret?

  • API tokens, service account keys
  • Database passwords and TLS certs
  • SSH keys, encryption keys, and license files

🧰 Tools & Storage Options

  • Secret Managers: HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager
  • CI/CD Vaulting: GitHub Actions Secrets, GitLab CI Variables, Jenkins Credentials Plugin
  • Kubernetes: SealedSecrets, External Secrets Controller

✅ Best Practices

  • Never hard-code secrets in code or Docker images
  • Rotate secrets periodically and automate revocation
  • Use short-lived credentials where possible (e.g., AWS STS)
  • Audit access to secrets and use RBAC to restrict scope
  • Encrypt secrets at rest and in transit

📦 In CI/CD Pipelines

  • Inject secrets as environment variables or temporary files
  • Restrict who can modify or view pipeline secrets
  • Use dynamic credentials (e.g., workload identity federation)

🚫 Common Pitfalls

  • Storing secrets in plaintext config files or Git
  • Over-permissive IAM roles accessing all secrets
  • Logging secrets by mistake in CI/CD logs or crash reports

📌 Final Insight

Secure secret management is a foundation of DevSecOps. By vaulting, rotating, auditing, and automating access, you protect critical infrastructure from silent but catastrophic risks.