Untrusted Terraform Modules
A module pinned to a branch can change under you.
What Is Untrusted Terraform Modules?
A Terraform module source is a remote code dependency that provisions with your credentials. A networking module pinned to a branch gains a commit that adds an IAM role trusting an outside account, and the next apply creates it, three lines in a diff nobody reads. You'll watch the outside account assume that role and read a production export, then pin the module to a reviewed commit so a new push no longer changes your infrastructure, and commit the provider lock file so a provider cannot change under you either.
What You'll Learn in Untrusted Terraform Modules
- A module source is code that runs with your credentials, so an untrusted module is an untrusted dependency in your account.
- A module pinned to a branch is mutable: a new commit is pulled on the next apply, changing what you provision without a change on your side.
- Pinning the module by commit SHA, and vendoring critical modules, makes an upgrade a deliberate change with a diff to review.
- A provider is a binary that runs with your credentials, so committing .terraform.lock.hcl pins providers by checksum the same way.
Untrusted Terraform Modules — Training Steps
-
A module pinned to a branch
Bob maintains a public networking module that many accounts use. He has noticed that Rudmoss pins it to a branch, not a commit, so whatever he pushes to that branch, Rudmoss applies. Rudmoss runs a workforce scheduling platform on AWS.
-
Whatever the branch becomes
The source points at the module's main branch. Every apply pulls whatever is on that branch at the time, which is not necessarily what Rudmoss reviewed.
-
Open the module
Bob controls the module's code. He opens its IAM file to add something that looks like part of the networking.
-
Add a role that trusts him
Next to the flow-log resource, which belongs here, Bob adds an IAM role whose trust policy names his own AWS account. In a hundred-line module it reads as more networking.
-
Three lines that matter
The role grants whoever can assume it read access to the account's storage, and the account allowed to assume it is Bob's.
-
Push it to the branch
Bob pushes the change to the module's main branch. From this moment, every account pinned to that branch gets the role on its next apply.
-
Assume the role
The role now exists in Rudmoss's production account, and its trust policy names Bob's account. He assumes it.
-
Read a production export
The role carries S3 read across the account. Bob reads a customer export straight out of production storage.
-
Where the role came from
-
A role trusting a stranger
Rudmoss's monitoring flags a new IAM role whose trust policy names an external account, created by the nightly pipeline, and an S3 export read from that account.
Security Framework Coverage
CWE
- CWE-494 Download of Code Without Integrity Check
- CWE-829 Inclusion of Functionality from Untrusted Control Sphere
MITRE ATT&CK
- T1195.001 Supply Chain Compromise: Compromise Software Dependencies and Development Tools
CIS Controls
- CIS 2 Inventory and Control of Software Assets
- CIS 16 Application Software Security
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
- ID.AM Asset Management
- PR.PS Platform Security
NICE Framework
- DD-WRL-004 Secure Systems Development
- IO-WRL-005 Systems Administration