Provider authentication and least privilege
Authenticate the workload, not the source file
A Terraform provider is software that calls an external API. Authentication proves the caller identity; authorization determines what that identity can do. Avoid putting a permanent access key in configuration or passing one in a command argument. Prefer a short-lived session issued to a verified workload. The API, not the Terraform variable name or workspace name, enforces permission. For this chapter, all identities are invented and no token is issued.
Follow the credential flow
An approved runner receives a signed identity assertion from its trusted issuer. A cloud identity service validates the issuer, audience, signature, expiration and applicable subject conditions before granting a scoped session. The provider uses that session to call the service. In HCP Terraform, dynamic provider credentials can automate this exchange for supported integrations. Each integration has its own token claims and configuration rules; the following is a teaching model, not real claim syntax.
# Fictional policy model, not an IAM or OIDC provider configuration.issuer: https://issuer.example.testsubject: org:bookshop:workspace:inventory-prod:phase:applyaudience: inventory-cloudrole: inventory-prod-applymaximum_session_minutes: 30A production apply session should reject a development subject even if the issuer and audience match. A short expiration limits the time available for misuse but cannot prevent actions during that time. The runner must not expose the token to unrelated jobs or logs. Review the provider-specific credential chain: an ambient profile or environment credential might be selected instead of the intended session. Confirm the effective identity in an authorized environment using the provider-specific identity check; never discover access against unknown credentials.
Separate the plan and apply authority
A plan is not a harmless text preview. Providers can read remote resources during planning, and a backend may require locking permissions. Some integrations need additional permissions; do not promise a universal read-only plan role. Design the smallest practical role for each phase and environment, with explicit exceptions and tests. Here is a fictional inventory application split.
Phase Identity Scopeplan inventory-prod-plan Required reads only, where feasibleapply inventory-prod-apply Approved inventory changesstate inventory-prod-backend Dedicated state and lock objectsThe apply role must be available only after the trusted approval gate, not to an arbitrary pull request. Protect the exact reviewed configuration and saved plan; if either changes, review again. Backend authentication is distinct from provider authentication. Use dedicated state access, enforce account and environment boundaries, and verify that the runner is not able to acquire the apply role during an unapproved plan. A provider alias is not a security boundary by itself.
Review the runner and trust policy
Review branch or environment protection, runner isolation, allowed repository or workspace claims, token audience, session duration, effective resource permissions, audit logs and revocation. Never grant untrusted contribution code access to production secrets. A runner that executes a malicious provider or script can expose any credentials available to that process. Keep dependency acquisition and review separate from the privileged apply environment. Treat a missing identity check as a release blocker, not a reason to grant administrator permissions.
Practice
Use the six fictional identity cases in the worksheet. Decide whether the requested session should be issued under the toy policy, and explain which trust condition or approval is missing. This exercise models selected checks only and does not implement a real federation service.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Provider authentication and least privilege — knowledge check
Review identity and dependency trust boundaries.
What is the purpose of workload federation?
Why can planning require permissions?
What should a production trust policy verify?
Which boundary should prevent unapproved production apply?
How should backend credentials be treated?