Skip to content

Commit d4bb1a7

Browse files
committed
feat: add developer Redis access via infra pipeline
- Add developer_principal_id input to infra.yml workflow - Add conditional Redis access policy for local debugging - Load appsettings.Development.local.json for local dev config - Include full stack trace in error logging for debugging - Add app-logs to gitignore
1 parent 17b2dcd commit d4bb1a7

7 files changed

Lines changed: 74 additions & 1 deletion

File tree

.github/workflows/infra.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ on:
1919
- plan
2020
- apply
2121
- destroy
22+
developer_principal_id:
23+
description: 'Azure AD Object ID for developer Redis access (optional, for local debugging)'
24+
required: false
25+
default: ''
26+
type: string
2227

2328
permissions:
2429
id-token: write
@@ -27,6 +32,7 @@ permissions:
2732
env:
2833
TF_VAR_github_repository: ${{ github.repository }}
2934
TF_VAR_github_environment: ${{ inputs.environment }}
35+
TF_VAR_developer_principal_id: ${{ inputs.developer_principal_id }}
3036
ARM_USE_OIDC: true
3137
ARM_USE_AZUREAD: true
3238
# State storage settings

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,5 @@ yarn-error.log*
9595
# Publish output
9696
publish/
9797
wwwroot/_framework/
98+
app-logs/
99+
app-logs.zip

infra/terraform/appservice.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,35 @@ resource "azapi_update_resource" "app_service_auth" {
119119
}
120120
}
121121

122+
# Configure App Service logging
123+
resource "azapi_update_resource" "app_service_logs" {
124+
type = "Microsoft.Web/sites/config@2024-04-01"
125+
resource_id = "${azapi_resource.app_service.id}/config/logs"
126+
127+
body = {
128+
properties = {
129+
applicationLogs = {
130+
fileSystem = {
131+
level = "Information"
132+
}
133+
}
134+
detailedErrorMessages = {
135+
enabled = true
136+
}
137+
failedRequestsTracing = {
138+
enabled = true
139+
}
140+
httpLogs = {
141+
fileSystem = {
142+
enabled = true
143+
retentionInDays = 7
144+
retentionInMb = 35
145+
}
146+
}
147+
}
148+
}
149+
}
150+
122151
# Role assignments for App Service managed identity
123152

124153
# Search Index Data Reader

infra/terraform/redis.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,25 @@ resource "azapi_resource" "redis_app_access" {
6464

6565
depends_on = [azapi_resource.app_service]
6666
}
67+
68+
# Redis access assignment for developer identity (local debugging)
69+
# Only created if developer_principal_id is specified
70+
resource "azapi_resource" "redis_developer_access" {
71+
count = var.developer_principal_id != "" ? 1 : 0
72+
type = "Microsoft.Cache/redisEnterprise/databases/accessPolicyAssignments@2025-04-01"
73+
name = "developeraccess"
74+
parent_id = azapi_resource.redis_database.id
75+
76+
schema_validation_enabled = false
77+
78+
body = {
79+
properties = {
80+
accessPolicyName = "default"
81+
user = {
82+
objectId = var.developer_principal_id
83+
}
84+
}
85+
}
86+
87+
depends_on = [azapi_resource.redis_database]
88+
}

infra/terraform/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ variable "github_environment" {
2929
default = "demo"
3030
}
3131

32+
variable "developer_principal_id" {
33+
description = "Azure AD Object ID of developer for local debugging access (optional)"
34+
type = string
35+
default = ""
36+
}
37+
3238
# Local values for consistent naming
3339
locals {
3440
resource_prefix = "${var.project_name}-${var.environment}"

src/backend/HealthPlanChat.WebApi/Middleware/SafeErrorHandlingMiddleware.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ public async Task InvokeAsync(HttpContext context)
5555
}
5656
catch (Exception ex)
5757
{
58-
// Log exception type and correlation info, but NOT the message (may contain user data)
58+
// Log exception type and correlation info
59+
// NOTE: In development, log full exception for debugging
5960
_logger.LogError(
61+
ex, // Include full exception for stack trace
6062
"Unhandled exception. Type: {ExceptionType}, Path: {Path}, TraceId: {TraceId}",
6163
ex.GetType().Name,
6264
context.Request.Path,

src/backend/HealthPlanChat.WebApi/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
var builder = WebApplication.CreateBuilder(args);
1010

11+
// Add optional local configuration override (gitignored, for local dev with real Azure resources)
12+
builder.Configuration.AddJsonFile(
13+
$"appsettings.{builder.Environment.EnvironmentName}.local.json",
14+
optional: true,
15+
reloadOnChange: true);
16+
1117
// Bind configuration sections
1218
builder.Services.Configure<AppOptions>(builder.Configuration.GetSection(AppOptions.SectionKey));
1319
builder.Services.Configure<RetrievalOptions>(builder.Configuration.GetSection(RetrievalOptions.SectionKey));

0 commit comments

Comments
 (0)