Skip to content

Commit 473b04e

Browse files
committed
add role assignments for gmsa creds
Signed-off-by: ritikaguptams <[email protected]>
1 parent b006d63 commit 473b04e

File tree

5 files changed

+92
-19
lines changed

5 files changed

+92
-19
lines changed
File renamed without changes.

Diff for: infra/azure/terraform/capz/identities/main.tf

+45
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ variable "location" {
2222
type = string
2323
}
2424

25+
variable "subscription_id" {
26+
type = string
27+
}
28+
29+
variable "container_registry_scope" {
30+
type = string
31+
}
32+
2533
resource "azurerm_user_assigned_identity" "cloud_provider_user_identity" {
2634
name = "cloud-provider-user-identity"
2735
location = var.location
@@ -40,6 +48,43 @@ resource "azurerm_user_assigned_identity" "gmsa_user_identity" {
4048
resource_group_name = var.resource_group_name
4149
}
4250

51+
resource "azurerm_role_definition" "gmsa_custom_role" {
52+
name = "gMSA"
53+
scope = "/subscriptions/${var.subscription_id}"
54+
description = "Required permissions for gmsa to read properties of subscriptions and managed identities"
55+
56+
permissions {
57+
actions = [
58+
"Microsoft.Resources/subscriptions/read",
59+
"Microsoft.ManagedIdentity/userAssignedIdentities/read"
60+
]
61+
not_actions = []
62+
}
63+
64+
assignable_scopes = [
65+
"/subscriptions/${var.subscription_id}"
66+
]
67+
}
68+
69+
resource "azurerm_role_assignment" "gmsa_role_assignment" {
70+
principal_id = azurerm_user_assigned_identity.domain_vm_identity.principal_id
71+
role_definition_name = azurerm_role_definition.gmsa_custom_role.name
72+
scope = "/subscriptions/${var.subscription_id}"
73+
depends_on = [azurerm_user_assigned_identity.domain_vm_identity]
74+
}
75+
76+
resource "azurerm_role_assignment" "cloud_provider_sub_contributor" {
77+
principal_id = azurerm_user_assigned_identity.cloud_provider_user_identity.principal_id
78+
role_definition_name = "Contributor"
79+
scope = "/subscriptions/${var.subscription_id}"
80+
}
81+
82+
resource "azurerm_role_assignment" "acr_pull" {
83+
principal_id = azurerm_user_assigned_identity.cloud_provider_user_identity.principal_id
84+
role_definition_name = "AcrPull"
85+
scope = var.container_registry_scope
86+
}
87+
4388
output "cloud_provider_user_identity_id" {
4489
value = azurerm_user_assigned_identity.cloud_provider_user_identity.principal_id
4590
}

Diff for: infra/azure/terraform/capz/main.tf

+29-19
Original file line numberDiff line numberDiff line change
@@ -80,37 +80,46 @@ resource "azurerm_storage_account" "k8sprowstorage" {
8080
min_tls_version = "TLS1_0"
8181
account_replication_type = "RAGRS"
8282
cross_tenant_replication_enabled = true
83-
depends_on = [azurerm_resource_group.capz_ci]
83+
depends_on = [
84+
azurerm_resource_group.capz_ci
85+
]
8486
}
8587

86-
# Import identities module
87-
module "identities" {
88-
source = "./identities"
88+
# Import container registry module
89+
module "container_registry" {
90+
source = "./container-registry"
8991
resource_group_name = var.resource_group_name
9092
location = var.location
91-
depends_on = [azurerm_resource_group.capz_ci]
93+
depends_on = [
94+
azurerm_resource_group.capz_ci
95+
]
96+
}
97+
98+
# Import identities module
99+
module "identities" {
100+
source = "./identities"
101+
resource_group_name = var.resource_group_name
102+
location = var.location
103+
subscription_id = data.azurerm_client_config.current.subscription_id
104+
container_registry_scope = module.container_registry.container_registry_id
105+
depends_on = [
106+
azurerm_resource_group.capz_ci
107+
]
92108
}
93109

94110
# Import key vault module
95111
module "key_vault" {
96-
source = "./key-vault"
97-
resource_group_name = var.resource_group_name
98-
location = var.location
99-
tenant_id = data.azurerm_client_config.current.tenant_id
112+
source = "./key-vault"
113+
resource_group_name = var.resource_group_name
114+
location = var.location
115+
tenant_id = data.azurerm_client_config.current.tenant_id
100116
identities = {
101-
cloud_provider_user_identity_id = module.identities.cloud_provider_user_identity_id
102117
domain_vm_identity_id = module.identities.domain_vm_identity_id
103118
gmsa_user_identity_id = module.identities.gmsa_user_identity_id
104119
}
105-
depends_on = [azurerm_resource_group.capz_ci]
106-
}
107-
108-
# Import container registry module
109-
module "container_registry" {
110-
source = "./container-registry"
111-
resource_group_name = var.resource_group_name
112-
location = var.location
113-
depends_on = [azurerm_resource_group.capz_ci]
120+
depends_on = [
121+
azurerm_resource_group.capz_ci
122+
]
114123
}
115124

116125
# Import role assignments module
@@ -120,6 +129,7 @@ module "role_assignments" {
120129
container_registry_scope = module.container_registry.container_registry_id
121130
storage_account_scope = azurerm_storage_account.k8sprowstorage.id
122131
subscription_id = data.azurerm_client_config.current.subscription_id
132+
key_vault_id = module.key_vault.key_vault_id
123133
depends_on = [
124134
azurerm_resource_group.capz_ci,
125135
azurerm_storage_account.k8sprowstorage,

Diff for: infra/azure/terraform/capz/role-assignments/main.tf

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
# This module maintains all role assignments for our service principal - az-cli-prow
18+
1719
variable "resource_group_name" {
1820
type = string
1921
}
@@ -30,6 +32,10 @@ variable "subscription_id" {
3032
type = string
3133
}
3234

35+
variable "key_vault_id" {
36+
type = string
37+
}
38+
3339
data "azuread_service_principal" "az_service_principal" {
3440
display_name = "az-cli-prow"
3541
}
@@ -73,3 +79,15 @@ resource "azurerm_role_assignment" "sp_custom_role_assignment" {
7379
role_definition_name = azurerm_role_definition.custom_role.name
7480
scope = "/subscriptions/${var.subscription_id}"
7581
}
82+
83+
resource "azurerm_key_vault_access_policy" "access_policy_gmsa_sp" {
84+
key_vault_id = var.key_vault_id
85+
tenant_id = data.azuread_service_principal.az_service_principal.application_tenant_id
86+
object_id = data.azuread_service_principal.az_service_principal.id
87+
secret_permissions = [
88+
"Get",
89+
"Delete",
90+
"List",
91+
"Purge"
92+
]
93+
}

0 commit comments

Comments
 (0)