Untrusted Terraform Plan

Untrusted Terraform Plan

A plan runs code, and CI runs plan with full credentials.

What Is Untrusted Terraform Plan?

A Terraform plan is not a read-only preview: an external data source executes during planning, and CI runs plan with credentials broad enough to build the whole account. You'll open a fork pull request whose innocuous data source runs during the plan job, captures the pipeline's cloud credentials, and ships them out, with no apply and no approval. Then you'll stop fork pull requests from ever meeting real credentials, split the plan and apply roles, and gate apply behind an approval so untrusted code never runs with real credentials.

What You'll Learn in Untrusted Terraform Plan

Untrusted Terraform Plan — Training Steps

  1. A pull request from a fork

    Bob does not need to merge anything. Quorvel's infrastructure repository is public, and its pipeline plans every pull request. He forks it and adds one file. Quorvel runs a fleet telematics platform. Its Terraform is applied by a pipeline that holds broad cloud credentials.

  2. It runs at plan time

    The file adds an external data source. A plan does not just describe changes; it reads data sources, and an external data source does that by running a program. The program is a script this same pull request added.

  3. Open the pull request

    Bob pushes the change to his fork and opens the pull request. Quorvel's pipeline picks it up and runs a plan, as it does for every pull request.

  4. What the plan sent him

    The data source's program read the plan job's environment and posted it to a host Bob controls. He checks what arrived.

  5. Whose credentials they are

    Bob loads the captured credentials and asks the cloud who they belong to.

  6. What it reaches

    A role that can build the account can also read what the account keeps. Bob reads the production database secret.

  7. Why a plan was enough

  8. The CI role used from nowhere

    Quorvel's monitoring flags the CI role's credentials used from an unknown address, and the build logs show a plan job on a fork pull request ran an external data source.

  9. The code that ran

    Alice opens the file the fork pull request added. It is the external data source, and understanding it is understanding why the plan step leaked.

  10. The damage was at plan time

    The data source ran the fork's script during the plan, which is why reviewing the apply would never have caught it. The script read the job's environment and sent the credentials out.

Security Framework Coverage

CWE

  • CWE-94 Improper Control of Generation of Code ('Code Injection')
  • CWE-829 Inclusion of Functionality from Untrusted Control Sphere

MITRE ATT&CK

  • T1552 Unsecured Credentials

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