Skip to content

Commit 21f2e6c

Browse files
ritikaguptamsmarosset
authored andcommitted
add role assignments for gmsa creds
Signed-off-by: ritikaguptams <[email protected]>
1 parent d642504 commit 21f2e6c

File tree

5 files changed

+94
-21
lines changed

5 files changed

+94
-21
lines changed
File renamed without changes.

infra/azure/terraform/capz/identities/main.tf

Lines changed: 45 additions & 0 deletions
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
}

infra/azure/terraform/capz/main.tf

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ resource "azurerm_marketplace_agreement" "kinvolk-stable2-agreement" {
6363
# Data source to get the current client configuration
6464
data "azurerm_client_config" "current" {}
6565

66-
6766
# Resource group for CAPZ CI resources
6867
resource "azurerm_resource_group" "capz_ci" {
6968
location = var.location
@@ -81,45 +80,56 @@ resource "azurerm_storage_account" "k8sprowstorage" {
8180
min_tls_version = "TLS1_0"
8281
account_replication_type = "RAGRS"
8382
cross_tenant_replication_enabled = true
84-
depends_on = [azurerm_resource_group.capz_ci]
83+
depends_on = [
84+
azurerm_resource_group.capz_ci
85+
]
8586
}
8687

87-
# Import identities module
88-
module "identities" {
89-
source = "./identities"
88+
# Import container registry module
89+
module "container_registry" {
90+
source = "./container-registry"
9091
resource_group_name = var.resource_group_name
9192
location = var.location
92-
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+
]
93108
}
94109

95110
# Import key vault module
96111
module "key_vault" {
97-
source = "./key-vault"
98-
resource_group_name = var.resource_group_name
99-
location = var.location
100-
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
101116
identities = {
102-
cloud_provider_user_identity_id = module.identities.cloud_provider_user_identity_id
103117
domain_vm_identity_id = module.identities.domain_vm_identity_id
104118
gmsa_user_identity_id = module.identities.gmsa_user_identity_id
105119
}
106-
depends_on = [azurerm_resource_group.capz_ci]
107-
}
108-
109-
# Import container registry module
110-
module "container_registry" {
111-
source = "./container-registry"
112-
resource_group_name = var.resource_group_name
113-
location = var.location
114-
depends_on = [azurerm_resource_group.capz_ci]
120+
depends_on = [
121+
azurerm_resource_group.capz_ci
122+
]
115123
}
116124

117125
# Import role assignments module
118126
module "role_assignments" {
119127
source = "./role-assignments"
120128
resource_group_name = var.resource_group_name
121129
container_registry_scope = module.container_registry.container_registry_id
122-
subscription_id = data.azurerm_client_config.current.subscription_id
130+
#storage_account_scope = azurerm_storage_account.k8sprowstorage.id
131+
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,

infra/azure/terraform/capz/role-assignments/main.tf

Lines changed: 18 additions & 0 deletions
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
}
@@ -26,6 +28,10 @@ variable "subscription_id" {
2628
type = string
2729
}
2830

31+
variable "key_vault_id" {
32+
type = string
33+
}
34+
2935
data "azuread_service_principal" "az_service_principal" {
3036
display_name = "az-cli-prow"
3137
}
@@ -69,3 +75,15 @@ resource "azurerm_role_assignment" "sp_custom_role_assignment" {
6975
role_definition_name = azurerm_role_definition.custom_role.name
7076
scope = "/subscriptions/${var.subscription_id}"
7177
}
78+
79+
resource "azurerm_key_vault_access_policy" "access_policy_gmsa_sp" {
80+
key_vault_id = var.key_vault_id
81+
tenant_id = data.azuread_service_principal.az_service_principal.application_tenant_id
82+
object_id = data.azuread_service_principal.az_service_principal.id
83+
secret_permissions = [
84+
"Get",
85+
"Delete",
86+
"List",
87+
"Purge"
88+
]
89+
}
File renamed without changes.

0 commit comments

Comments
 (0)