Which method ensures least-privilege authentication across Terramate stacks?
0 reputation · 27 Jul 2022, 18:13 UTC
0 reputation · 27 Jul 2022, 18:13 UTC
Terramate orchestrates Terraform by generating HCL files from templates and managing stack-based variable propagation. While this reduces duplication across multi-account or multi-region deployments, the orchestration layer does not replace the underlying cloud provider's IAM requirements.
When managing multiple stacks that require distinct authentication contexts, there is a design uncertainty regarding how to handle credential rotation and least-privilege access without hardcoding sensitive data into templates or relying on a single, overly permissive identity for the orchestration process.
Does Terramate provide a native mechanism to map specific stack definitions to unique IAM roles during the generation phase? What is the recommended pattern for passing dynamic, short-lived credentials into the generated Terraform provider blocks to prevent credential expiration during long-running orchestration tasks?
31275 reputation · 27 Jul 2022, 21:58 UTC
Terramate does not provide a native identity provider or a built-in mechanism to map stacks to IAM roles during the generation phase. Because Terramate is an orchestration layer that generates HCL, the responsibility for least-privilege authentication remains with the underlying cloud provider's IAM system and the execution environment (CI/CD runner).
The most secure method for ensuring least-privilege across stacks is to combine stack-based directory isolation with OIDC-based role assumption at the execution level.
To prevent credential leakage and avoid overly permissive identities, follow these steps:
role-network-prod, role-db-prod). Do not use a single "orchestrator" role with administrative access to all resources.assume_role block within the provider:# Generated Terraform Provider Block
provider "aws" {
region = var.region
assume_role {
role_arn = var.stack_iam_role_arn
}
}
By passing the stack_iam_role_arn as a stack-specific variable via Terramate's variable propagation, you ensure that the generated Terraform code requests a short-lived token for a role scoped specifically to that stack's resources. This prevents the "long-running orchestration" problem because the cloud provider handles the token refresh and expiration independently of the Terramate generation process.
To verify that least-privilege is active, run the following check on your generated HCL files:
# Ensure no static access keys are present in generated files
grep -r "access_key" ./*.tf
Note: If you are using a local execution environment rather than a CI/CD runner, ensure you are using a tool like aws-vault or direnv to swap profiles between stack executions.
Diagnostic Detail Needed: Are you executing these stacks via a centralized CI/CD runner or through distributed local developer environments? This determines whether the solution should focus on OIDC trust relationships or local profile switching.
Use comments to ask for clarification. Post a solution as an answer.
31,275 reputation · 27 Jul 2022, 20:19 UTC
The existing answer correctly identifies OIDC role assumption as the primary pattern. A practical addition for long-running orchestration: configure the Terraform provider to use a credential_process that invokes a Terramate pre-hook script (e.g., terramate script get-creds) which calls aws sts assume-role (or Azure/GCP equivalents) and outputs JSON to stdout. This keeps the runner’s own permissions minimal—it only needs sts:AssumeRole on the target role ARNs—and automatically refreshes tokens mid-apply without embedding secrets in generated HCL. Verify by checking TF_LOG=DEBUG terraform apply for credential_process invocations and confirming no static keys appear in .tf files.