Skip to content

About

This Terraform module integrates GitHub Actions with Workload Identity Federation for Microsoft Azure.

Topics

Resources

Contributing

Stars

0 stars

Watchers

4 watching

Forks

Repository files navigation

Terraform Azure GitHub Actions Workload Identity Federation (WIF) Module

This Terraform module integrates GitHub Actions with Workload Identity Federation for Microsoft Azure. It simplifies the process of setting up and managing Azure Role-based Access Control (RBAC) for GitHub Actions environments by creating the necessary resources and configuring the required secrets.

Background

Workload Identity Federation for Microsoft Azure allows you to use Azure AD to authenticate and authorize users and applications to access Azure resources. This module simplifies the process of setting up and managing Azure RBAC for GitHub Actions environments by creating the necessary resources and configuring the required secrets.

See references below for more information about Workload Identity Federation for Microsoft Azure and GitHub Actions.

Prerequisites

  • Existing Azure Active Directory (AD) tenant.
  • Permissions to create and manage Azure AD applications and service principals (optional if using Managed Identity).
  • Existing GitHub repository with GitHub Actions enabled, and GitHub Actions environments configured.
  • Logged in to Azure CLI using az login.
  • Credentials fo GitHub, either using a personal access token or GitHub App.

Features

  • Creates and manage existing Azure Active Directory (AD) applications and service principals (optional if using Managed Identity) for GitHub repositories' environments (development, staging, production, etc.).
  • Assign custom and built-in Azure RBAC roles to the service principal associated with each environment.
  • Configures trust against GitHub through GitHub Actions environments with Azure AD application or User Assigned Managed Identity federated credentials.
  • Configure existing GitHub repository with per environment secrets, that provides required configurations.

Usage

Create new Azure AD application and service principal

The following example creates a new Azure AD application and service principal for each environment in the repository my-repo. The service principal is assigned the built-in Azure RBAC role Contributor for the subscription your-subscription-id in the environment development. The service principal is assigned the built-in Azure RBAC role Contributor for the subscription your-subscription-id in the environment production. The service principal for the environment production is configured to use an existing Azure AD application with the ID your-existing-application-id.

module "azureAdApplication" {
  source        = "../../"
  name_prefix   = "demo"
  environment   = "development"
  identity_type = "azureAdApplication"

  repositories = {
    "myorg/my-repo" = {
      environments = {
        development = {
          name_prefix     = "app1-dev"
          subscription_id = "<your-subscription-id>"
                    tags = {
            Environment = "development"
            Application = "App1"
          }

          roles = {
            Contributor = {
              scopes = [
               "/subscriptions/your-subscription-id>"
              ]
            }
          }
        },
        production = {
          name_prefix     = "app1-prod"
          client_id       = "<your-existing-application-id>"
          subscription_id = "<your-subscription-id>"
                    tags = {
            Environment = "development"
            Application = "App1"
          }

          roles = {
            Contributor = {
              scopes = [
                "/subscriptions/your-subscription-id>"
              ]
            }
          }
        }
      }
    }
  }
}

Examples

Please see the examples directory for examples of how to use this module.

Requirements

Name Version
terraform ~>1.0
azuread 2.36.0
azurerm ~>3.51
github ~> 5.0

Providers

Name Version
azuread 2.36.0
azurerm 3.30.0
github 5.18.3

Modules

No modules.

Resources

Name Type
azuread_application.github_oidc resource
azuread_application_federated_identity_credential.github_oidc resource
azuread_service_principal.github_oidc resource
azurerm_role_assignment.inline_role_assignment resource
azurerm_role_assignment.standard_role_assignment resource
azurerm_role_definition.inline_role_definition resource
github_actions_environment_secret.azure_client_id resource
github_actions_environment_secret.azure_subscription_id resource
github_actions_environment_secret.azure_tenant_id resource
github_repository_environment.repo_environment resource
azuread_application.existing data source
azuread_service_principal.lookup data source
azurerm_client_config.current data source
azurerm_subscription.current data source
github_repository.repo data source

Inputs

Name Description Type Default Required
audience_name The value is the audience name for the GitHub OIDC provider. string "api://AzureADTokenExchange" no
default_tags The value is a map of default tags to assign to the resource. map(string)
{
"CreatedBy": "Terraform"
}
no
environment value is the environment for the resources created. string n/a yes
github_issuer_url value is the issuer URL for the GitHub OIDC provider. string "https://token.actions.githubusercontent.com" no
name_prefix The value is a prefix for the name of the resources created. string n/a yes
override_subject_template_path set this to override the default subject template for the workload identity subject. string null no
owners List of object IDs of the application owners. list(string) null no
repositories List of repositories and their respective environments for which to create secrets and configure permissions. See the usage examples above for the structure and types of data this field accepts.
list(object({
repository_name = string
environments = list(object({
environment = string
name_prefix = string
application_id = optional(string)
subscription_id = optional(string)
tags = optional(map(string))
roles = optional(map(object({
scopes = set(string)
})))
inline_roles = optional(map(object({
name = string
assignable = bool
scope = string
assignable_scopes = optional(set(string))
permissions = object({
actions = list(string)
not_actions = list(string)
})
})))
}))
}))
n/a yes

Outputs

Name Description
azure_client_id_secrets Information about the AZURE_CLIENT_ID secrets for GitHub repository environments.
azure_subscription_id_secrets Information about the AZURE_SUBSCRIPTION_ID secrets for GitHub repository environments.
azure_tenant_id_secrets Information about the AZURE_TENANT_ID secrets for GitHub repository environments.
github_oidc_applications Information about the created GitHub OIDC applications.
github_oidc_service_principals Information about the created GitHub OIDC service principals.
github_repository_environments Information about the created GitHub repository environments.
inline_role_assignments Information about the inline role assignments.
inline_role_definitions Information about the inline role definitions.
inline_roles n/a
standard_role_assignments Information about the standard role assignments.

References

Contributing

Please see CONTRIBUTING.md for details on submitting patches and the contribution workflow.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

This Terraform module integrates GitHub Actions with Workload Identity Federation for Microsoft Azure.

Topics

Resources

Contributing

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages