Skip to content

Feature Request: Ability to whitelist/restrict Environment Variables passed to Provider PluginsΒ #37967

@or-shachar

Description

@or-shachar

Terraform Version

1.x

Use Cases

Currently, when Terraform initializes a provider, it spawns the provider plugin as a child process. By default, this child process inherits the entire environment context of the parent terraform CLI process.

This means that if I run terraform apply, every configured provider (AWS, Azure, Kubernetes, etc.) has visibility into every environment variable present in the shell (e.g., GITHUB_TOKEN, AWS_ACCESS_KEY_ID, ARM_CLIENT_ID), regardless of whether that specific provider needs them.


The current behavior violates the principle of Least Privilege and leads to configuration conflicts in complex environments:

  1. Security/Leakage: A compromised or malicious provider plugin (or a third-party community provider) theoretically has access to credentials meant for other providers (e.g., a Datadog provider process can read my AWS_SECRET_ACCESS_KEY).
  2. Implicit Auth Conflicts: When using multiple aliases for the same provider (e.g., aws.prod and aws.dev), accidentally set shell variables (like AWS_PROFILE) can override explicit HCL configurations if the provider precedence logic favors environment variables.
  3. CI/CD Hygiene: In CI pipelines where many secrets are injected as env vars, it is difficult to isolate which secrets are visible to which step without complex shell wrappers.

Attempted Solutions

For now the only way to do it is by using remote vault ephemeral data

Proposal

I propose adding a meta-argument to the provider block (or a global setting) that allows users to explicitly whitelist which environment variables are passed to the plugin process.

If this list is present, the Terraform Core should filter the environment passed to the go-plugin client, sending only the matching keys.


Proposed Syntax

Option 1 (preferred): Allow-list per provider This would be non-breaking. If omitted, behavior defaults to "inherit all."

provider "aws" {
  region = "us-east-1"
  
  # New Feature: Only pass these specific env vars to the plugin process
  # The plugin will not see GITHUB_TOKEN or other unrelated vars.
  allowed_environment_variables = ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
}

Option 2: Strict Isolation (Boolean) A flag to strictly disable all env var inheritance, forcing the user to rely solely on input variables defined in the HCL.

provider "google" {
  project = "my-project"
  
  # New Feature: The plugin process starts with an empty environment
  isolate_environment = true 
}

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions