-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redis authentication managed identity #213
base: main
Are you sure you want to change the base?
Changes from all commits
5eda8a0
2a03fd3
680453c
3eaf048
90d666b
7d16943
1a18fb2
7ce8103
4a3316c
a57b05c
ca30432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,30 @@ module "cache" { | |
log_analytics_workspace_id = module.hub_app_insights[0].log_analytics_workspace_id | ||
} | ||
|
||
|
||
resource "azurerm_redis_cache_access_policy_assignment" "primary_current_user" { | ||
count = var.environment == "prod" ? 1 : 0 | ||
name = "primarycurrentuser" | ||
redis_cache_id = module.cache[0].cache_id | ||
access_policy_name = "Data Contributor" | ||
object_id = data.azuread_client_config.current.object_id | ||
object_id_alias = "currentuser" | ||
} | ||
|
||
resource "azurerm_redis_cache_access_policy_assignment" "app_user" { | ||
count = var.environment == "prod" ? 1 : 0 | ||
name = "primaryappuser" | ||
redis_cache_id = module.cache[0].cache_id | ||
access_policy_name = "Data Contributor" | ||
object_id = azurerm_user_assigned_identity.primary_app_service_identity[0].principal_id | ||
object_id_alias = azurerm_user_assigned_identity.primary_app_service_identity[0].principal_id | ||
|
||
# Ensure that the current user has been created before creating the app user | ||
depends_on = [ | ||
azurerm_redis_cache_access_policy_assignment.primary_current_user | ||
] | ||
} | ||
|
||
# ---------------------------------------------------------------------------------------------- | ||
# Cache - Prod - Secondary Region | ||
# ---------------------------------------------------------------------------------------------- | ||
|
@@ -29,6 +53,29 @@ module "secondary_cache" { | |
log_analytics_workspace_id = module.hub_app_insights[0].log_analytics_workspace_id | ||
} | ||
|
||
resource "azurerm_redis_cache_access_policy_assignment" "secondary_current_user" { | ||
count = var.environment == "prod" ? 1 : 0 | ||
name = "secondarycurrentuser" | ||
redis_cache_id = module.secondary_cache[0].cache_id | ||
access_policy_name = "Data Contributor" | ||
object_id = data.azuread_client_config.current.object_id | ||
object_id_alias = "currentuser" | ||
} | ||
|
||
resource "azurerm_redis_cache_access_policy_assignment" "secondary_app_user" { | ||
count = var.environment == "prod" ? 1 : 0 | ||
name = "secondaryappuser" | ||
redis_cache_id = module.secondary_cache[0].cache_id | ||
access_policy_name = "Data Contributor" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found |
||
object_id = azurerm_user_assigned_identity.secondary_app_service_identity[0].principal_id | ||
object_id_alias = azurerm_user_assigned_identity.secondary_app_service_identity[0].principal_id | ||
|
||
# Ensure that the current user has been created before creating the app user | ||
depends_on = [ | ||
azurerm_redis_cache_access_policy_assignment.secondary_current_user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe leave a comment as an fyi that access policy assignments must be done serially, hence why you're depending on it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this was fixed - hashicorp/terraform-provider-azurerm#26085. I'm going to get rid of this dependency. |
||
] | ||
} | ||
|
||
# ---------------------------------------------------------------------------------------------- | ||
# Cache - Dev | ||
# ---------------------------------------------------------------------------------------------- | ||
|
@@ -43,3 +90,26 @@ module "dev-cache" { | |
private_endpoint_subnet_id = null | ||
log_analytics_workspace_id = module.dev_app_insights[0].log_analytics_workspace_id | ||
} | ||
|
||
resource "azurerm_redis_cache_access_policy_assignment" "dev_current_user" { | ||
count = var.environment == "dev" ? 1 : 0 | ||
name = "devcurrentuser" | ||
redis_cache_id = module.dev-cache[0].cache_id | ||
access_policy_name = "Data Contributor" | ||
object_id = data.azuread_client_config.current.object_id | ||
object_id_alias = "currentuser" | ||
} | ||
|
||
resource "azurerm_redis_cache_access_policy_assignment" "dev_app_user" { | ||
count = var.environment == "dev" ? 1 : 0 | ||
name = "devappuser" | ||
redis_cache_id = module.dev-cache[0].cache_id | ||
access_policy_name = "Data Contributor" | ||
object_id = azurerm_user_assigned_identity.dev_app_service_identity[0].principal_id | ||
object_id_alias = azurerm_user_assigned_identity.dev_app_service_identity[0].principal_id | ||
|
||
# Ensure that the current user has been created before creating the app user | ||
depends_on = [ | ||
azurerm_redis_cache_access_policy_assignment.dev_current_user | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# ------------------------------------------------ | ||
# Identity for the Production Primary App Service | ||
# ------------------------------------------------ | ||
|
||
resource "azurecaf_name" "primary_app_service_identity_name" { | ||
count = var.environment == "prod" ? 1 : 0 | ||
name = var.application_name | ||
resource_type = "azurerm_user_assigned_identity" | ||
suffixes = [var.location, var.environment] | ||
} | ||
|
||
resource "azurerm_user_assigned_identity" "primary_app_service_identity" { | ||
count = var.environment == "prod" ? 1 : 0 | ||
location = azurerm_resource_group.spoke[0].location | ||
name = azurecaf_name.primary_app_service_identity_name[0].result | ||
resource_group_name = azurerm_resource_group.spoke[0].name | ||
} | ||
|
||
# ------------------------------------------------ | ||
# Identity for the Production Secondary App Service | ||
# ------------------------------------------------ | ||
|
||
resource "azurecaf_name" "secondary_app_service_identity_name" { | ||
count = var.environment == "prod" ? 1 : 0 | ||
name = var.application_name | ||
resource_type = "azurerm_user_assigned_identity" | ||
suffixes = [var.secondary_location, var.environment] | ||
} | ||
|
||
resource "azurerm_user_assigned_identity" "secondary_app_service_identity" { | ||
count = var.environment == "prod" ? 1 : 0 | ||
location = azurerm_resource_group.secondary_spoke[0].location | ||
name = azurecaf_name.secondary_app_service_identity_name[0].result | ||
resource_group_name = azurerm_resource_group.secondary_spoke[0].name | ||
} | ||
|
||
|
||
# ------------------------------------------------ | ||
# Identity for the Production Dev App Service | ||
# ------------------------------------------------ | ||
|
||
resource "azurecaf_name" "dev_app_service_identity_name" { | ||
count = var.environment == "dev" ? 1 : 0 | ||
name = var.application_name | ||
resource_type = "azurerm_user_assigned_identity" | ||
suffixes = [var.location, var.environment] | ||
} | ||
|
||
resource "azurerm_user_assigned_identity" "dev_app_service_identity" { | ||
count = var.environment == "dev" ? 1 : 0 | ||
location = azurerm_resource_group.dev[0].location | ||
name = azurecaf_name.dev_app_service_identity_name[0].result | ||
resource_group_name = azurerm_resource_group.dev[0].name | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this create both a systemassigned and userassigned? do you need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this will create both. We need both as Redis is the first use case that uses user assigned managed identity. Key Vault still uses the System Assigned managed identity. We have an item in the backlog to transition to user assigned managed identity.