Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 36 ยท Getting Started

The Secrets Problem and Secret Sprawl

See how secrets leak through code, config and logs, why rotation is hard, and how a secrets manager fixes it. Includes a runnable secret scanner model.

Before learning a tool, it helps to feel the problem it solves. Secret sprawl means credentials are scattered across many places, copied by many people, and rarely changed. Most real-world breaches that involve credentials start with a secret that was somewhere it should not have been: in a Git repository, a container image, a CI log or a screenshot.

This lesson lists the common leak paths, explains why rotation is the hard part, and shows what a secrets manager changes. You will run a small scanner that finds secret-like strings in text.

The scanner below is a teaching stand-in with a few simple patterns. Real scanners use hundreds of rules plus entropy checks. All secrets in the examples are fake.

Where secrets leak

  • Source code and Git history: deleting a password from a file does not delete it from history.
  • Environment variables: they show up in process listings, crash dumps and docker inspect output.
  • Container images: ENV and COPY .env bake secrets into layers anyone can pull.
  • CI/CD logs and variables: build logs echo commands; shared variables are readable by many jobs.
  • Chat, tickets, wikis: "Here is the prod password" is searchable forever.
  • Config files on disk: copied to backups, laptops and shared drives.

Each copy is a separate thing to rotate, and you cannot rotate what you cannot find.

Why rotation is hard

A static password used by ten services means changing it requires coordinated deploys, and if one is missed, an outage follows. Teams therefore avoid rotating, so credentials live for years. A secrets manager changes the shape of the problem:

  1. Applications fetch the secret at runtime instead of storing it.
  2. Rotation happens in one place; clients pick up the new value on their next read.
  3. Dynamic secrets are unique per client and expire, so there is nothing long-lived to steal.
  4. Audit logs answer "who read it?" after an incident.
flowchart TB
    subgraph Before
      A1["Repo"] --- P1(("password"))
      A2["CI vars"] --- P1
      A3["Wiki"] --- P1
      A4["Laptop .env"] --- P1
    end
    subgraph After
      B1["App"] -->|"login, read"| V["Vault"]
      B2["CI job"] -->|"login, read"| V
    end

Before: the same password lives in four places. After: one authority hands it out on demand.

A secret scanner you can run

This script looks for a few well-known shapes: a private key header, an AWS-style access key ID, and assignments such as password = "...". It reports line numbers but masks the value.

Python Find secret-like strings in a config

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Lines that merely look like configuration (DB_HOST, timeout) are ignored. False positives and false negatives are both normal for pattern scanners, which is why scanning is a safety net and not the fix.

Counting the blast radius

How many places must change when one password leaks? This model compares the copies approach to a central store.

Python Rotation effort: copies versus a central store

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The numbers are deliberately simple. The point is that "how many copies exist?" is a question you can answer with a central store and not without one.

What a secrets manager does not fix

  • It does not stop a compromised application from reading its own secrets. It limits which secrets and for how long.
  • It adds a critical service you must run and protect, covered under deployment and high availability later in the course.
  • You still need a secure way for each application to prove its identity (the "secret zero" problem). The answer is platform identity: Kubernetes service accounts, cloud IAM roles, or AppRole with wrapped secret IDs. See AppRole.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. You committed a password and then deleted it in the next commit. What is true?

    History keeps old versions. Rotate the secret, then optionally clean history.
  2. 2. Which change most reduces the damage of a leaked credential?

    A credential that expires in an hour, and belongs to one client, is useful to an attacker only briefly.
  3. 3. What is the "secret zero" problem?

    The first credential has to come from somewhere. Platform identity or wrapped, single-use bootstrap tokens answer it.
  4. 4. A pattern scanner finds no secrets in your repo. What can you conclude?

    Scanners catch common shapes. Custom tokens can slip through.

Summary

  • Secret sprawl means many uncontrolled copies; you cannot rotate or audit what you cannot find.
  • Common leak paths: Git, env vars, images, CI logs, chat and config files.
  • A central secrets manager gives one place to rotate, restrict and audit.
  • Short-lived, per-client credentials shrink the window of misuse.
  • Secret zero still needs a trusted identity mechanism.

Next: Installing Vault and Using Dev Mode