This repository was archived by the owner on Jul 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Redis authentication managed identity #213
Draft
nickdala
wants to merge
11
commits into
Azure:main
Choose a base branch
from
nickdala:redis-managed-identity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5eda8a0
User assigned managed identity
nickdala 2a03fd3
Redis access policies
nickdala 680453c
Enable Entra ID for Azure Cache for Redis authentication
nickdala 3eaf048
Remove Redis password from secrets and add a secret for the managed i…
nickdala 90d666b
Assign the managed identity to the App Service.
nickdala 7d16943
Update Azure Terraform provider version
nickdala 1a18fb2
CAMS application changes to support managed identity authentication f…
nickdala 7ce8103
remove locale from URL
nickdala 4a3316c
remove URL reference to the wrong Redis Configuration
nickdala a57b05c
Set the access policy for the current user to Data Contributor
nickdala ca30432
update azure provider version
nickdala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
Contributor
Author
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 | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.