|
| 1 | +locals { |
| 2 | + create_role_assignment = var.create_role_assignment ? 1 : 0 |
| 3 | + |
| 4 | + redpanda_operator_namespace = "redpanda" |
| 5 | + |
| 6 | + # aks_oidc_issuer_url = "https://TODO" |
| 7 | +} |
| 8 | + |
| 9 | +// Allow storing Redpanda TF state to storage |
| 10 | +resource "azurerm_role_assignment" "assign_identity_storage_blob_data_contributor" { |
| 11 | + count = local.create_role_assignment |
| 12 | + |
| 13 | + scope = azurerm_storage_account.management.id |
| 14 | + principal_id = azurerm_user_assigned_identity.redpanda_agent.principal_id |
| 15 | + role_definition_name = "Storage Blob Data Contributor" |
| 16 | +} |
| 17 | + |
| 18 | +// Allow access to key vault |
| 19 | +resource "azurerm_role_assignment" "vault_secrets_officer" { |
| 20 | + count = local.create_role_assignment |
| 21 | + |
| 22 | + scope = azurerm_resource_group.redpanda.id |
| 23 | + principal_id = data.azurerm_client_config.current.object_id |
| 24 | + role_definition_name = "Key Vault Secrets Officer" |
| 25 | +} |
| 26 | + |
| 27 | +resource "azurerm_role_assignment" "redpanda_agent_redpanda" { |
| 28 | + count = local.create_role_assignment |
| 29 | + |
| 30 | + principal_id = azurerm_user_assigned_identity.redpanda_agent.principal_id |
| 31 | + scope = azurerm_resource_group.redpanda.id |
| 32 | + role_definition_id = azurerm_role_definition.redpanda_agent.role_definition_resource_id |
| 33 | +} |
| 34 | + |
| 35 | +resource "azurerm_role_assignment" "redpanda_agent_network" { |
| 36 | + count = local.create_role_assignment |
| 37 | + |
| 38 | + principal_id = azurerm_user_assigned_identity.redpanda_agent.principal_id |
| 39 | + scope = azurerm_resource_group.network.id |
| 40 | + role_definition_id = azurerm_role_definition.redpanda_agent.role_definition_resource_id |
| 41 | +} |
| 42 | + |
| 43 | +resource "azurerm_role_assignment" "redpanda_agent_tiered_storage" { |
| 44 | + count = local.create_role_assignment |
| 45 | + |
| 46 | + principal_id = azurerm_user_assigned_identity.redpanda_agent.principal_id |
| 47 | + scope = azurerm_resource_group.storage.id |
| 48 | + role_definition_id = azurerm_role_definition.redpanda_agent.role_definition_resource_id |
| 49 | +} |
| 50 | + |
| 51 | +resource "azurerm_role_assignment" "redpanda_agent_iam" { |
| 52 | + count = local.create_role_assignment |
| 53 | + |
| 54 | + principal_id = azurerm_user_assigned_identity.redpanda_agent.principal_id |
| 55 | + scope = azurerm_resource_group.iam.id |
| 56 | + role_definition_id = azurerm_role_definition.redpanda_agent.role_definition_resource_id |
| 57 | +} |
| 58 | + |
| 59 | +resource "azurerm_role_assignment" "redpanda_cluster_network_contributor" { |
| 60 | + count = local.create_role_assignment |
| 61 | + |
| 62 | + scope = azurerm_resource_group.network.id |
| 63 | + principal_id = azurerm_user_assigned_identity.redpanda_cluster.principal_id |
| 64 | + role_definition_name = "Network Contributor" |
| 65 | +} |
| 66 | + |
| 67 | +resource "azurerm_role_assignment" "redpanda_private_link" { |
| 68 | + count = local.create_role_assignment |
| 69 | + |
| 70 | + principal_id = azurerm_user_assigned_identity.redpanda_cluster.principal_id |
| 71 | + scope = azurerm_resource_group.redpanda.id |
| 72 | + role_definition_id = azurerm_role_definition.redpanda_private_link.role_definition_resource_id |
| 73 | +} |
| 74 | + |
| 75 | +resource "azurerm_role_assignment" "redpanda_cluster" { |
| 76 | + count = local.create_role_assignment |
| 77 | + |
| 78 | + principal_id = azurerm_user_assigned_identity.redpanda_cluster.principal_id |
| 79 | + # See https://learn.microsoft.com/en-us/azure/role-based-access-control/troubleshooting?tabs=bicep#symptom---assigning-a-role-to-a-new-principal-sometimes-fails |
| 80 | + principal_type = "ServicePrincipal" |
| 81 | + scope = azurerm_storage_account.tiered_storage.id |
| 82 | + role_definition_name = "Storage Blob Data Contributor" |
| 83 | +} |
| 84 | + |
| 85 | +resource "azurerm_role_assignment" "redpanda_console" { |
| 86 | + count = local.create_role_assignment |
| 87 | + |
| 88 | + principal_id = azurerm_user_assigned_identity.redpanda_console.principal_id |
| 89 | + scope = azurerm_key_vault.console[0].id |
| 90 | + role_definition_id = azurerm_role_definition.redpanda_console.role_definition_resource_id |
| 91 | +} |
| 92 | + |
| 93 | +# federated identity is done in TF provisioner. |
| 94 | +# resource "azurerm_federated_identity_credential" "redpanda_cluster" { |
| 95 | +# count = local.create_role_assignment |
| 96 | +# name = var.redpanda_cluster_workload_identity_name |
| 97 | +# resource_group_name = azurerm_resource_group.redpanda.name |
| 98 | +# audience = ["api://AzureADTokenExchange"] |
| 99 | +# ## We know the oidc issuer url only after AKS cluster is created. |
| 100 | +# ## Check whether RP can come up if this resource is created during cluster creation. |
| 101 | +# ## If yes, we will have to ask customer to apply when we have the oidc issuer url. |
| 102 | +# ## In TF, issuer is required. But in AZ cli, it is optional in https://learn.microsoft.com/en-us/cli/azure/identity/federated-credential?view=azure-cli-latest |
| 103 | +# issuer = local.aks_oidc_issuer_url |
| 104 | +# parent_id = azurerm_user_assigned_identity.redpanda_cluster.id |
| 105 | +# subject = "system:serviceaccount:${local.redpanda_operator_namespace}:${azurerm_user_assigned_identity.redpanda_cluster.name}" |
| 106 | +# } |
| 107 | + |
| 108 | +resource "azurerm_role_assignment" "cert_manager" { |
| 109 | + count = local.create_role_assignment |
| 110 | + # In TF provisioner, the scope is a DNS zone specific resource. We change it to RG here since DNS zone is not avaiable until cluster is being deployed. |
| 111 | + # scope = "/subscriptions/60fc0bed-3072-4c53-906a-d130a934d520/resourceGroups/rg-rpcloud-cqclghd44f471cmf8ojg/providers/Microsoft.Network/dnsZones/cqclghd44f471cmf8ojg.byoc.ign.cloud.redpanda.com" |
| 112 | + scope = azurerm_resource_group.redpanda.id |
| 113 | + role_definition_name = "DNS Zone Contributor" |
| 114 | + principal_id = azurerm_user_assigned_identity.cert_manager.principal_id |
| 115 | + # See https://learn.microsoft.com/en-us/azure/role-based-access-control/troubleshooting?tabs=bicep#symptom---assigning-a-role-to-a-new-principal-sometimes-fails |
| 116 | + principal_type = "ServicePrincipal" |
| 117 | +} |
| 118 | + |
| 119 | +resource "azurerm_role_assignment" "external_dns_zone_contributor" { |
| 120 | + count = local.create_role_assignment |
| 121 | + # In TF provisioner, the scope is a DNS zone specific resource. We change it to RG here since DNS zone is not avaiable until cluster is being deployed. |
| 122 | + #scope = "/subscriptions/60fc0bed-3072-4c53-906a-d130a934d520/resourceGroups/rg-rpcloud-cqclghd44f471cmf8ojg/providers/Microsoft.Network/dnsZones/cqclghd44f471cmf8ojg.byoc.ign.cloud.redpanda.com" |
| 123 | + scope = azurerm_resource_group.redpanda.id |
| 124 | + role_definition_name = "DNS Zone Contributor" |
| 125 | + principal_id = azurerm_user_assigned_identity.external_dns.principal_id |
| 126 | + # See https://learn.microsoft.com/en-us/azure/role-based-access-control/troubleshooting?tabs=bicep#symptom---assigning-a-role-to-a-new-principal-sometimes-fails |
| 127 | + principal_type = "ServicePrincipal" |
| 128 | +} |
| 129 | + |
| 130 | +resource "azurerm_role_assignment" "external_dns_rgreader" { |
| 131 | + count = local.create_role_assignment |
| 132 | + scope = azurerm_resource_group.redpanda.id |
| 133 | + role_definition_name = "Reader" |
| 134 | + principal_id = azurerm_user_assigned_identity.external_dns.principal_id |
| 135 | + # See https://learn.microsoft.com/en-us/azure/role-based-access-control/troubleshooting?tabs=bicep#symptom---assigning-a-role-to-a-new-principal-sometimes-fails |
| 136 | + principal_type = "ServicePrincipal" |
| 137 | +} |
| 138 | + |
0 commit comments