Skip to content

Commit a7ce58f

Browse files
committed
tf
1 parent d1f95b1 commit a7ce58f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/pentesting-ci-cd/terraform-security.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,35 @@ With these creds, attackers can create/modify/destroy resources directly using n
305305
- Detect exfiltration of `tfc-*` credential artifacts and alert on suspicious `external` program usage during plans.
306306

307307

308+
## Compromising Terraform Cloud
309+
310+
### Using a token
311+
312+
As **[explained in this post](https://www.pentestpartners.com/security-blog/terraform-token-abuse-speculative-plan/)**, terraform CLI stores tokens in plaintext at **`~/.terraform.d/credentials.tfrc.json`**. Stealing this token lets an attacker impersonate the user within the token’s scope.
313+
314+
Using this token it's possible to get the org/workspace with:
315+
316+
```bash
317+
GET https://app.terraform.io/api/v2/organizations/acmecorp/workspaces/gcp-infra-prod
318+
Authorization: Bearer <TF_TOKEN>
319+
```
320+
321+
Then it's possible to run arbitrary code using **`terraform plan`** as explained in the previous chapter.
322+
323+
### Escaping to the cloud
324+
325+
Then, if the runner is located in some cloud environment, it's possible to obtain a token of the principal attached to the runner and use it out of band.
326+
327+
- **GCP files (present in current run working directory)**
328+
- `tfc-google-application-credentials` — JSON config for Workload Identity Federation(WIF) that tells Google how to exchange the external identity.
329+
- `tfc-gcp-token` — short‑lived (≈1 hour) GCP access token referenced by the above
330+
331+
- **AWS files**
332+
- `tfc-aws-shared-config` — JSON for web identity federation/OIDC role assumption
333+
(preferred over static keys).
334+
- `tfc-aws-token` — short‑lived token, or potentially static IAM keys if misconfigured.
335+
336+
308337
## Automatic Audit Tools
309338

310339
### [**Snyk Infrastructure as Code (IaC)**](https://snyk.io/product/infrastructure-as-code-security/)

0 commit comments

Comments
 (0)