liveBook · Manning

Authorization

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

Authorization is the process of determining which operations an authenticated identity is permitted to perform.

A deployment pipeline may prove that it is running a particular workflow and still lack permission to change cloud resources. Authentication maps a request to an identity; authorization grants that identity permission to act. Registering an OpenID Connect (OIDC) identity provider establishes trust in identities it supplies, but does not by itself authorize them. section 8.5.1 section 8.5.1

To authorize a CI/CD identity for cloud deployment:

  • Register the pipeline’s OIDC provider with the cloud vendor. For GitHub Actions, the provider URL is https://token.actions.githubusercontent.com. section 8.5.1
  • Map the supplied identity to a cloud identity. In AWS, create a role it can assume; in Azure, map it to a service principal. section 8.5.1
  • Restrict that relationship. For an AWS role, specify the OIDC provider as a principal and add conditions limiting assumption to the intended repository and workflows. Without those conditions, other users of the provider could assume the role. section 8.5.1
Listing 8.14 Allowing a GitHub Actions workflow to assume a role
jobs:
  terraform:
    name: Run Terraform against AWS
    runs-on: ubuntu-latest
 
    permissions:                                              #1
      id-token: write                                         #1
      contents: read                                          #1
 
    steps:
      - name: Checkout                                        #2
        uses: actions/checkout@v4
 
      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v4        #3
        with:
          role-to-assume: arn:aws:iam::999999999999:role/github-actions-${{ 
github.repository }}                                        #4
          region: us-west-2                                   #5
#1 The AWS action needs the OIDC token to be accessible.
#2 Checkout our repository.
#3 This action is published by AWS and converts the OIDC token into AWS credentials.
#4 When using OIDC you have to tell AWS what role you want to assume.
#5 AWS requires a region when logging in.

The GitHub Actions workflow requests access to an OIDC token, then configures AWS credentials by naming the role to assume. The workflow configuration works alongside the cloud-side role and its restrictions. section 8.5.1

Authorization also governs access to Terraform state. Give backend access only to people and systems that need it: when CI/CD runs production jobs, developers may not need direct state access. Pair that restriction with access logging so problems can be traced. section 6.4.2

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains the authentication–authorization distinction and AWS role restrictions, while leaving vendor-specific configuration details to each platform.
Examples
Uses a GitHub Actions workflow assuming an AWS role, an Azure service-principal mapping, and restricted production-state access.
What it assumes
Assumes CI/CD and Terraform-backend context but defines authentication and authorization before applying them to cloud identities.
What you can do after
Operate/configure it by restricting cloud-role assumption to intended workflows and limiting state access to necessary users and systems.
How it connects
Connects authorization to authentication, OpenID Connect, identity and access management, CI/CD, and Terraform state backends.

Also explained in

Compare how 28 books explain authorization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.