Terraform Drift

Terraform Drift

Close the port in the console, and the next apply reopens it.

What Is Terraform Drift?

A security group left open to the whole internet is closed by hand in the console, and the next routine apply reopens it, because the code is the source of truth and the code still says 0.0.0.0/0. You'll watch a production database read directly from the internet, close the port in the console, see an unrelated apply revert that fix, then move the fix into code so the pipeline keeps the port closed. You'll also meet the mirror problem: a resource removed from the configuration but never destroyed.

What You'll Learn in Terraform Drift

Terraform Drift — Training Steps

  1. A database port on the internet

    Bob scans Drumhallow's addresses for database ports answering directly. One does. Drumhallow runs a business payments platform. Its production ledger database should sit behind the application, on a private network.

  2. Connect to it

    An open database port is an invitation. Bob connects with a credential Drumhallow reused from a staging dump, which the open port let him reach.

  3. Read the ledger

    The connection is live, straight from the internet, with no application in the path. Bob reads the payouts table.

  4. Which control failed

  5. Reachable from the internet

    Drumhallow's security scan flags the ledger database as reachable from any address, and monitoring shows it was read from one it does not recognize.

  6. Find the rule

    The fastest way to stop the exposure is to close the rule where it is live, in the console. Alice opens the VPC security groups.

  7. Open the rule

    The database security group carries the open rule.

  8. The whole internet, on the database port

    The inbound rule allows any address to reach the database.

  9. Close it by hand

    Alice scopes the rule to the internal network range, so only the application subnets can reach the database. The exposure stops.

  10. The apply undoes it

    Overnight the pipeline runs a routine apply for an unrelated change. It detects Alice's console edit as drift and reverts the rule to what the code says: 0.0.0.0/0.

Security Framework Coverage

CWE

  • CWE-668 Exposure of Resource to Wrong Sphere

CIS Controls

  • CIS 4 Secure Configuration of Enterprise Assets and Software

NIST CSF

  • PR.AT-02 Individuals in specialized roles are provided with awareness and training so that they possess the knowledge and skills to perform relevant tasks with cybersecurity risks in mind
  • PR.PS Platform Security

NICE Framework

  • DD-WRL-004 Secure Systems Development
  • IO-WRL-005 Systems Administration