Skip to content

Commit 3755640

Browse files
authored
Merge pull request #13 from MicrosoftCloudEssentials-LearningHub/managed-identity-RBAC
Switched from API key authentication to managed identity authenticati…
2 parents c020350 + e547c29 commit 3755640

6 files changed

Lines changed: 38 additions & 37 deletions

File tree

.github/workflows/validate_and_fix_markdown.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
fetch-depth: 0
2121

2222
- name: Set up Node.js
23-
uses: actions/setup-node@v3
23+
uses: actions/setup-node@v4
2424
with:
25-
node-version: '16'
25+
node-version: '20'
2626

2727
- name: Install Markdown Linter
2828
run: npm install -g markdownlint-cli

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Costa Rica
55
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
66
[brown9804](https://github.com/brown9804)
77

8-
Last updated: 2025-12-04
8+
Last updated: 2026-01-12
99

1010
----------
1111

@@ -202,7 +202,7 @@ graph TD
202202

203203
<!-- START BADGE -->
204204
<div align="center">
205-
<img src="https://img.shields.io/badge/Total%20views-1696-limegreen" alt="Total views">
206-
<p>Refresh Date: 2025-12-04</p>
205+
<img src="https://img.shields.io/badge/Total%20views-1324-limegreen" alt="Total views">
206+
<p>Refresh Date: 2026-01-12</p>
207207
</div>
208208
<!-- END BADGE -->

TROUBLESHOOTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Costa Rica
55
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
66
[brown9804](https://github.com/brown9804)
77

8-
Last updated: 2025-11-24
8+
Last updated: 2026-01-12
99

1010
----------
1111

@@ -347,7 +347,7 @@ terraform apply
347347

348348
<!-- START BADGE -->
349349
<div align="center">
350-
<img src="https://img.shields.io/badge/Total%20views-1696-limegreen" alt="Total views">
351-
<p>Refresh Date: 2025-12-04</p>
350+
<img src="https://img.shields.io/badge/Total%20views-1324-limegreen" alt="Total views">
351+
<p>Refresh Date: 2026-01-12</p>
352352
</div>
353353
<!-- END BADGE -->

src/a2a/status_automation.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if () {
1111

1212
# Check automation endpoint
1313
try {
14-
= Invoke-RestMethod -Uri "https://zava-faf734f3-app.azurewebsites.net/a2a/automation/status" -TimeoutSec 5
14+
= Invoke-RestMethod -Uri "https://zava-4f64ebdc-app.azurewebsites.net/a2a/automation/status" -TimeoutSec 5
1515
Write-Host "Automation Status: "
1616
} catch {
1717
Write-Host "Automation endpoint not accessible"

terraform-infrastructure/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Costa Rica
55
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
66
[brown9804](https://github.com/brown9804)
77

8-
Last updated: 2025-12-03
8+
Last updated: 2026-01-12
99

1010
----------
1111

@@ -119,7 +119,7 @@ graph TD;
119119

120120
<!-- START BADGE -->
121121
<div align="center">
122-
<img src="https://img.shields.io/badge/Total%20views-1696-limegreen" alt="Total views">
123-
<p>Refresh Date: 2025-12-04</p>
122+
<img src="https://img.shields.io/badge/Total%20views-1324-limegreen" alt="Total views">
123+
<p>Refresh Date: 2026-01-12</p>
124124
</div>
125125
<!-- END BADGE -->

terraform-infrastructure/main.tf

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ resource "azapi_resource" "storage" {
105105
}
106106

107107
# AI Foundry account (preview) using AzAPI provider.
108+
# Using managed identity authentication (disableLocalAuth = true for better security)
108109
resource "azapi_resource" "ai_foundry" {
109-
type = "Microsoft.CognitiveServices/accounts@2025-06-01"
110+
type = "Microsoft.CognitiveServices/accounts@2024-10-01"
110111
name = local.ai_foundry_name
111112
location = var.location
112113
parent_id = azurerm_resource_group.rg.id
@@ -118,7 +119,7 @@ resource "azapi_resource" "ai_foundry" {
118119
properties = {
119120
allowProjectManagement = true
120121
customSubDomainName = local.ai_foundry_name
121-
disableLocalAuth = false
122+
disableLocalAuth = true
122123
}
123124
})
124125
}
@@ -446,24 +447,21 @@ resource "azurerm_linux_web_app" "app" {
446447
DOCKER_ENABLE_CI = "true"
447448
WEBSITES_PORT = "8000"
448449

449-
# GPT Configuration (Key Vault referenced secrets)
450+
# GPT Configuration (using managed identity)
450451
gpt_endpoint = "https://${local.ai_foundry_name}.cognitiveservices.azure.com/"
451452
gpt_deployment = "gpt-4o-mini"
452-
gpt_api_key = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault.kv.vault_uri}secrets/ai-foundry-key)"
453453
gpt_api_version = "2024-12-01-preview"
454454

455-
# MSFT Foundry Configuration
455+
# MSFT Foundry Configuration (using managed identity)
456456
AZURE_AI_FOUNDRY_ENDPOINT = "https://${local.ai_foundry_name}.cognitiveservices.azure.com/"
457457
AZURE_AI_PROJECT_NAME = local.ai_project_name
458458
AZURE_AI_PROJECT_ENDPOINT = "https://${local.ai_foundry_name}.cognitiveservices.azure.com/"
459459
AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME = "gpt-4o-mini"
460-
AZURE_AI_FOUNDRY_API_KEY = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault.kv.vault_uri}secrets/ai-foundry-key)"
461460

462-
# MSFT Foundry OpenAI Configuration
461+
# MSFT Foundry OpenAI Configuration (using managed identity)
463462
AZURE_OPENAI_CHAT_DEPLOYMENT = "gpt-4o-mini"
464463
AZURE_OPENAI_EMBEDDING_DEPLOYMENT = "text-embedding-3-small"
465464
AZURE_OPENAI_IMAGE_DEPLOYMENT = "dall-e-3"
466-
AZURE_OPENAI_API_KEY = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault.kv.vault_uri}secrets/ai-foundry-key)"
467465
AZURE_OPENAI_ENDPOINT = "https://${local.ai_foundry_name}.cognitiveservices.azure.com/"
468466
AZURE_OPENAI_API_VERSION = "2024-02-01"
469467

@@ -537,14 +535,9 @@ resource "azurerm_key_vault_access_policy" "app_policy" {
537535
depends_on = [azurerm_linux_web_app.app]
538536
}
539537

540-
# Populate Key Vault secrets (AI Foundry key, Cosmos key, Search key, Storage connection)
538+
# Populate Key Vault secrets (Cosmos key, Search key, Storage connection)
541539
# Key Vault Secrets as Terraform resources (provides version for references)
542-
resource "azurerm_key_vault_secret" "ai_foundry_key" {
543-
name = "ai-foundry-key"
544-
value = jsondecode(data.azapi_resource_action.ai_foundry_keys[0].output).key1
545-
key_vault_id = azurerm_key_vault.kv.id
546-
depends_on = [azurerm_key_vault.kv]
547-
}
540+
# Note: AI Foundry now uses managed identity instead of keys
548541

549542
resource "azurerm_key_vault_secret" "search_admin_key" {
550543
name = "search-admin-key"
@@ -925,6 +918,23 @@ resource "azurerm_role_assignment" "search_project_contributor" {
925918
principal_type = "ServicePrincipal"
926919
}
927920

921+
# Role assignments for Web App managed identity to access AI Foundry
922+
resource "azurerm_role_assignment" "webapp_foundry_openai_user" {
923+
scope = azapi_resource.ai_foundry.id
924+
role_definition_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/providers/Microsoft.Authorization/roleDefinitions/${local.cognitive_openai_user_role_id}"
925+
principal_id = data.azurerm_linux_web_app.app_identity.identity[0].principal_id
926+
principal_type = "ServicePrincipal"
927+
depends_on = [azurerm_linux_web_app.app]
928+
}
929+
930+
resource "azurerm_role_assignment" "webapp_project_openai_user" {
931+
scope = azapi_resource.ai_project.id
932+
role_definition_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/providers/Microsoft.Authorization/roleDefinitions/${local.cognitive_openai_user_role_id}"
933+
principal_id = data.azurerm_linux_web_app.app_identity.identity[0].principal_id
934+
principal_type = "ServicePrincipal"
935+
depends_on = [azurerm_linux_web_app.app]
936+
}
937+
928938
# Storage account permissions for MSFT Foundry project
929939
resource "azurerm_role_assignment" "storage_blob_data_contributor_user" {
930940
scope = azapi_resource.storage.id
@@ -1099,16 +1109,7 @@ data "azapi_resource_action" "cosmos_keys" {
10991109
depends_on = [azurerm_cosmosdb_account.cosmos]
11001110
}
11011111

1102-
# Get AI Foundry keys for Web App configuration
1103-
data "azapi_resource_action" "ai_foundry_keys" {
1104-
count = var.enable_ai_automation ? 1 : 0
1105-
type = "Microsoft.CognitiveServices/accounts@2024-10-01"
1106-
resource_id = azapi_resource.ai_foundry.id
1107-
action = "listKeys"
1108-
response_export_values = ["key1"]
1109-
body = jsonencode({})
1110-
depends_on = [azapi_resource.ai_foundry]
1111-
}
1112+
# AI Foundry now uses managed identity authentication - no keys needed
11121113

11131114
# Connect resources to MSFT Foundry project using ARM templates
11141115
resource "azapi_resource" "storage_connection" {

0 commit comments

Comments
 (0)