Skip to main content

Terraform User API Token

A Terraform User API Token is a credential used to authenticate and authorize access to Terraform Cloud services. This token allows users to perform operations such as managing infrastructure, accessing state files, and executing runs within Terraform Cloud. Exposure of this token is a significant security concern because it can grant unauthorized users the ability to manipulate infrastructure, potentially leading to data breaches, service disruptions, and unauthorized resource provisioning.


How Does It Look

Terraform User API Tokens can appear in various contexts, such as:

  • Environment variables:

    export TERRAFORM_API_TOKEN="tfp_1234567890abcdef"
  • Configuration files (JSON, YAML, .env):

    {
    "terraform": {
    "api_token": "tfp_1234567890abcdef"
    }
    }
  • Code snippets:

    terraform_api_token = "tfp_1234567890abcdef"
  • Connection strings (if applicable): Not typically used in connection strings.


Severity

  • 🔴 Critical

This credential is marked as critical because it provides access to Terraform Cloud, allowing full control over infrastructure management. The blast radius includes potential unauthorized changes to infrastructure, data exposure, and financial implications due to resource misuse.


What Can an Attacker Do?

With immediate access to a Terraform User API Token, an attacker can control Terraform Cloud operations, leading to severe consequences.

Key actions an attacker can perform:

  • Modify Infrastructure: Change or delete infrastructure resources (if the token has write permissions).
  • Access Sensitive Data: Retrieve state files containing sensitive information (if the token has read access).
  • Provision Resources: Spin up new resources, potentially for malicious purposes like cryptomining (if compute permissions are granted).
  • Access Billing Information: View or modify billing settings (if the account has billing scope enabled).

An attacker could also escalate their access by leveraging the token to gain insights into the infrastructure, potentially moving laterally to other connected systems or services.


Real-World Impact

The exposure of a Terraform User API Token poses significant business risks, including:

Primary impact includes unauthorized infrastructure changes and data exposure.

Potential consequences include:

  • Data Exposure: Access to sensitive configuration and state data (if the credential has read access to sensitive data).
  • Financial Loss: Increased costs due to unauthorized resource provisioning (if billing/resource creation is permitted).
  • Operational Disruption: Downtime or service degradation from unauthorized infrastructure changes (if the attacker has delete/modify permissions).
  • Reputational Damage: Loss of customer trust and brand integrity due to security breaches.

In worst-case scenarios, the cascading effects of infrastructure manipulation can lead to prolonged service outages and significant financial and reputational damage.


Prerequisites for Exploitation

To exploit a Terraform User API Token, an attacker needs:

  • Network access: Ability to communicate with Terraform Cloud endpoints.
  • Additional context: Knowledge of the Terraform Cloud organization and workspace IDs.
  • No rate limits: Exploitation is easier if there are no strict rate limits or IP restrictions in place.

How to Verify If It's Active

To verify if a Terraform User API Token is active, use the following command:

curl -H "Authorization: Bearer [TOKEN]" https://app.terraform.io/api/v2/organizations

Valid credential response: A successful response will return a list of organizations associated with the token.

Invalid/expired credential response: An error message indicating unauthorized access or token expiration.


Detection Patterns

Common Variable Names:

  • TERRAFORM_API_TOKEN
  • TF_API_TOKEN
  • TERRAFORM_TOKEN
  • TF_TOKEN
  • API_TOKEN
  • TOKEN

File Locations:

  • .env
  • terraform.tfvars
  • config.json
  • settings.yaml

Regex Pattern:

tfp_[0-9a-fA-F]{16,}

Remediation Steps

  1. Revoke immediately - Go to Terraform Cloud > User Settings > Tokens and delete the compromised token.
  2. Audit access logs - Review Terraform Cloud audit logs for unauthorized actions or changes during the exposure window.
  3. Assess blast radius - Identify all systems, applications, and environments that used the exposed credential.
  4. Rotate credential - Generate a new API token in Terraform Cloud with least-privilege permissions.
  5. Update dependent systems - Deploy the new credential to all applications and update CI/CD pipelines securely.
  6. Harden access controls - Enable IP allowlisting in Terraform Cloud and require two-factor authentication.
  7. Implement secrets management - Migrate credentials to a secrets manager (HashiCorp Vault, AWS Secrets Manager) to prevent hardcoding.
  8. Add detection controls - Set up pre-commit hooks and repository scanning to catch credential leaks before they reach production.

Credential exposures often go undetected for extended periods, increasing the window for exploitation. As a long-term strategy, plan to establish an internal process or engage an external vendor for continuous external exposure monitoring. This helps identify leaked secrets across public repositories, paste sites, dark web forums, and other external sources before attackers can leverage them. Proactive detection and rapid response are essential to minimizing the impact of credential leaks.


References