diff --git a/.gitignore b/.gitignore index 52c79a0..aebcc01 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ __azurite_* *.bkp src/tmp/* -.vscode/*.dictionary.* +src/.vs/* +.vscode/*.dictionary.* \ No newline at end of file diff --git a/docs/workshop.md b/docs/workshop.md index 05a8ea3..8524a57 100644 --- a/docs/workshop.md +++ b/docs/workshop.md @@ -1475,20 +1475,19 @@ var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(_connection To use system-assigned identities, the code above needs to be replaced with: ```csharp -var configurationOptions = await ConfigurationOptions.Parse($"{_hostname}:{_port}").ConfigureForAzureWithSystemAssignedManagedIdentityAsync(_managedIdentityPrincipalId!); +var configurationOptions = await ConfigurationOptions.Parse($"{_hostname}:{_port}").ConfigureForAzureWithSystemAssignedManagedIdentityAsync(); var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configurationOptions); ```
> - Update the code of the `GetDatabaseAsync` method in `src/catalog-api/RedisService.cs` to use system-assigned identity of the App Service Web App -> - Set the value of the `AZURE_MANAGED_IDENTITY_PRINCIPAL_ID` app setting to the system-assigned identity of the App Service Web App (`Object (principal) ID`)
-> The variables `_hostname`, `_port`, and `_managedIdentityPrincipalId` were already defined in `src/catalog-api/RedisService.cs` +> The variables `_hostname` and `_port` were already defined in `src/catalog-api/RedisService.cs`
@@ -1506,8 +1505,6 @@ Afterwards, go to the **Identity** menu on your App Service resource, and copy t ![Managed identity of catalog-api](./assets/catalog-api-managed-identity.png) -Finally, go to the **Configuration** menu of your App Service resource and set the app setting `AZURE_MANAGED_IDENTITY_PRINCIPAL_ID` to the value of `Object (principal) ID`. - Validate the change by clicking **Ok**, then **Save** and you should be all set now. diff --git a/solutions/catalog-api/RedisService.cs b/solutions/catalog-api/RedisService.cs index 34f9cc9..4764e8a 100644 --- a/solutions/catalog-api/RedisService.cs +++ b/solutions/catalog-api/RedisService.cs @@ -1,4 +1,3 @@ -using Microsoft.Azure.StackExchangeRedis; using StackExchange.Redis; public interface IRedisService { @@ -11,7 +10,6 @@ public class RedisService : IRedisService { private IDatabase? _database = null; private readonly string? _connectionString; - private readonly string? _managedIdentityPrincipalId; private readonly string? _hostname; private readonly string? _port; @@ -22,7 +20,6 @@ public RedisService(IConfiguration configuration) { _ttl = TTL(configuration["AZURE_REDIS_TTL_IN_SECONDS"]); _connectionString = configuration["AZURE_REDIS_CONNECTION_STRING"]; - _managedIdentityPrincipalId = configuration["AZURE_MANAGED_IDENTITY_PRINCIPAL_ID"]; _port = configuration["AZURE_REDIS_PORT"]; _hostname = configuration["AZURE_REDIS_HOSTNAME"]; } @@ -35,7 +32,7 @@ private async Task GetDatabaseAsync() { Console.WriteLine("Initializing Redis database connection"); // var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(_connectionString!, AzureCacheForRedis.ConfigureForAzure); - var configurationOptions = await ConfigurationOptions.Parse($"{_hostname}:{_port}").ConfigureForAzureWithSystemAssignedManagedIdentityAsync(_managedIdentityPrincipalId!); + var configurationOptions = await ConfigurationOptions.Parse($"{_hostname}:{_port}").ConfigureForAzureWithSystemAssignedManagedIdentityAsync(); var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configurationOptions); _database = connectionMultiplexer.GetDatabase(); diff --git a/src/cache-refresh-func/CacheRefresh.Func.csproj b/src/cache-refresh-func/CacheRefresh.Func.csproj index dd6e59c..b943579 100644 --- a/src/cache-refresh-func/CacheRefresh.Func.csproj +++ b/src/cache-refresh-func/CacheRefresh.Func.csproj @@ -11,11 +11,10 @@ - + - diff --git a/src/catalog-api/Catalog.Api.csproj b/src/catalog-api/Catalog.Api.csproj index 0353ea6..e3fe4d6 100644 --- a/src/catalog-api/Catalog.Api.csproj +++ b/src/catalog-api/Catalog.Api.csproj @@ -8,8 +8,7 @@ - - + diff --git a/src/catalog-api/RedisService.cs b/src/catalog-api/RedisService.cs index 5affafb..ceaca36 100644 --- a/src/catalog-api/RedisService.cs +++ b/src/catalog-api/RedisService.cs @@ -1,4 +1,3 @@ -using Microsoft.Azure.StackExchangeRedis; using StackExchange.Redis; public interface IRedisService { @@ -11,7 +10,6 @@ public class RedisService : IRedisService { private IDatabase? _database = null; private readonly string? _connectionString; - private readonly string? _managedIdentityPrincipalId; private readonly string? _hostname; private readonly string? _port; @@ -22,7 +20,6 @@ public RedisService(IConfiguration configuration) { _ttl = TTL(configuration["AZURE_REDIS_TTL_IN_SECONDS"]); _connectionString = configuration["AZURE_REDIS_CONNECTION_STRING"]; - _managedIdentityPrincipalId = configuration["AZURE_MANAGED_IDENTITY_PRINCIPAL_ID"]; _port = configuration["AZURE_REDIS_PORT"]; _hostname = configuration["AZURE_REDIS_HOSTNAME"]; } diff --git a/src/catalog-api/appsettings.json.template b/src/catalog-api/appsettings.json.template index 2dc4d1a..df561fd 100644 --- a/src/catalog-api/appsettings.json.template +++ b/src/catalog-api/appsettings.json.template @@ -9,7 +9,6 @@ "AZURE_COSMOS_CONNECTION_STRING": "YOUR_COSMOS_CONNECTION_STRING", "AZURE_COSMOS_DATABASE": "catalogdb", "AZURE_REDIS_CONNECTION_STRING":"YOUR_REDIS_CONNECTION_STRING", - "AZURE_MANAGED_IDENTITY_PRINCIPAL_ID": "MANAGED_IDENTITY_PRINCIPAL_ID_FOR_AAD_INTEGRATION", "AZURE_REDIS_PORT": "OPTIONAL_REDIS_PORT_FOR_ADD_INTEGRATION", "AZURE_REDIS_HOSTNAME": "REDIS_HOSTNAME_FOR_ADD_INTEGRATION", "PRODUCT_LIST_CACHE_DISABLE":"0", diff --git a/src/history-func/History.Api.csproj b/src/history-func/History.Api.csproj index af472a3..ba0b752 100644 --- a/src/history-func/History.Api.csproj +++ b/src/history-func/History.Api.csproj @@ -12,9 +12,8 @@ - + - diff --git a/src/history-func/HistoryStoreService.cs b/src/history-func/HistoryStoreService.cs index dd843b4..4ef1352 100644 --- a/src/history-func/HistoryStoreService.cs +++ b/src/history-func/HistoryStoreService.cs @@ -1,7 +1,6 @@ using System; using System.Text.Json; using StackExchange.Redis; -using Microsoft.Azure.StackExchangeRedis; namespace History.Api { diff --git a/terraform/app.tf b/terraform/app.tf index a4f92c9..3289038 100644 --- a/terraform/app.tf +++ b/terraform/app.tf @@ -17,7 +17,6 @@ resource "azurerm_linux_web_app" "this" { AZURE_REDIS_CONNECTION_STRING = azurerm_redis_cache.this.primary_connection_string AZURE_REDIS_HOSTNAME = azurerm_redis_cache.this.hostname AZURE_REDIS_PORT = azurerm_redis_cache.this.ssl_port - AZURE_MANAGED_IDENTITY_PRINCIPAL_ID = "" PRODUCT_LIST_CACHE_DISABLE = "0" SIMULATED_DB_LATENCY_IN_SECONDS = "2" APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.this.instrumentation_key diff --git a/terraform/roles.tf b/terraform/roles.tf index da1fda3..1a379ff 100644 --- a/terraform/roles.tf +++ b/terraform/roles.tf @@ -20,7 +20,6 @@ resource "azurerm_cosmosdb_sql_role_assignment" "app_service" { resource_group_name = local.resource_group_name account_name = azurerm_cosmosdb_account.this.name role_definition_id = azurerm_cosmosdb_sql_role_definition.this.id - principal_id = azurerm_linux_web_app.this.identity[0].principal_id scope = azurerm_cosmosdb_account.this.id } @@ -30,7 +29,6 @@ resource "azurerm_cosmosdb_sql_role_assignment" "function_app_cache" { resource_group_name = local.resource_group_name account_name = azurerm_cosmosdb_account.this.name role_definition_id = azurerm_cosmosdb_sql_role_definition.this.id - principal_id = azurerm_linux_function_app.func_cache.identity[0].principal_id scope = azurerm_cosmosdb_account.this.id } @@ -38,6 +36,5 @@ resource "azurerm_cosmosdb_sql_role_assignment" "function_app_history" { resource_group_name = local.resource_group_name account_name = azurerm_cosmosdb_account.this.name role_definition_id = azurerm_cosmosdb_sql_role_definition.this.id - principal_id = azurerm_linux_function_app.func_history.identity[0].principal_id scope = azurerm_cosmosdb_account.this.id }